Ignore:
Timestamp:
Jun 17, 2013, 8:03:39 PM (11 years ago)
Author:
mistic100
Message:

fininalize download page
handle no-image files
correct link error when zips number changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/BatchDownloader/include/BatchDownloader.class.php

    r23290 r23291  
    298298   
    299299    $query = '
    300 SELECT id, path, representative_ext, width, height, rotation
     300SELECT id, path, width, height, rotation
    301301  FROM '.IMAGES_TABLE.'
    302302  WHERE id IN('.implode(',', $image_ids).')
     
    307307    while ($row = pwg_db_fetch_assoc($result))
    308308    {
    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           );
     309      $src_image = new SrcImage($row); // don't give representive_ext
     310     
     311      // no-image files
     312      if ($src_image->is_mimetype())
     313      {
     314        if ($update && in_array($row['id'], $to_update))
     315        {         
     316          $inserts[ $row['id'] ] = array(
     317            'image_id' => $row['id'],
     318            'type' => $this->data['size'],
     319            'width' => 0,
     320            'height' => 0,
     321            'filesize' => filesize(PHPWG_ROOT_PATH.$row['path'])/1024,
     322            'filemtime' => filemtime(PHPWG_ROOT_PATH.$row['path']),
     323            );
     324        }
     325      }
     326      // images files
     327      else
     328      {
     329        $derivative = new DerivativeImage($this->data['size'], $src_image);
     330        // if ($this->data['size'] != $derivative->get_type()) continue;
     331       
     332        $filemtime = @filemtime($derivative->get_path());
     333        $src_mtime = @filemtime(PHPWG_ROOT_PATH.$row['path']);
     334        if ($src_mtime===false) continue;
     335       
     336        if ($filemtime===false || $filemtime<$last_mod_time || $filemtime<$src_mtime)
     337        {
     338          $urls[] = $root_url.$derivative->get_url().$uid;
     339        }
     340        else if ($update && in_array($row['id'], $to_update))
     341        {
     342          $imagesize = getimagesize($derivative->get_path());
     343         
     344          $inserts[ $row['id'] ] = array(
     345            'image_id' => $row['id'],
     346            'type' => $this->data['size'],
     347            'width' => $imagesize[0],
     348            'height' => $imagesize[1],
     349            'filesize' => filesize($derivative->get_path())/1024,
     350            'filemtime' => $filemtime,
     351            );
     352        }
    333353      }
    334354    }
     
    344364      mass_inserts(
    345365        IMAGE_SIZES_TABLE,
    346         array('image_id','type','width','height','filesize'),
     366        array('image_id','type','width','height','filesize','filemtime'),
    347367        $inserts
    348368        );
     
    410430SELECT
    411431    id, name, file, path,
    412     representative_ext, rotation,
    413     filesize, width, height
     432    rotation, filesize, width, height
    414433  FROM '.IMAGES_TABLE.'
    415434  WHERE id IN ('.implode(',', $images_to_add).')
     
    438457      foreach ($images_to_add as $row)
    439458      {
     459        if (!file_exists(PHPWG_ROOT_PATH.$row['path']))
     460        {
     461          $this->removeImages(array($row['id']));
     462          continue;
     463        }
     464       
    440465        if ($this->data['size'] == 'original')
    441466        {
    442           $zip->addFile(PHPWG_ROOT_PATH . $row['path'], $row['id'].'_'.stripslashes(get_filename_wo_extension($row['file'])).'.'.get_extension($row['path']));
     467          $zip->addFile(PHPWG_ROOT_PATH.$row['path'], $row['id'].'_'.stripslashes(get_filename_wo_extension($row['file'])).'.'.get_extension($row['path']));
    443468          $total_size+= $row['filesize'];
    444469        }
    445470        else
    446471        {
    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'] ];
     472          $src_image = new SrcImage($row); // don't give representive_ext
     473         
     474          // no-image files
     475          if ($src_image->is_mimetype())
     476          {
     477            $zip->addFile(PHPWG_ROOT_PATH.$row['path'], $row['id'].'_'.stripslashes(get_filename_wo_extension($row['file'])).'.'.get_extension($row['path']));
     478            $total_size+= $row['filesize'];
     479          }
     480          // images files
     481          else
     482          {
     483            $derivative = new DerivativeImage($this->data['size'], $src_image);
     484            $path = $derivative->get_path();
     485       
     486            $zip->addFile($path, $row['id'].'_'.stripslashes(get_filename_wo_extension(basename($path))).'.'.get_extension($path));
     487            $total_size+= $filesizes[ $row['id'] ];
     488          }
    453489        }
    454490       
     
    572608      if ($this->data['status'] == 'done' or $i < $this->data['last_zip']+1)
    573609      {
    574         $out.= '<img src="'.$root_url.BATCH_DOWNLOAD_PATH.'template/drive.png"> Archive #'.$i.' (already downloaded)';
     610        $out.= '<img src="'.$root_url.BATCH_DOWNLOAD_PATH.'template/images/drive_error.png"> Archive #'.$i.' (already downloaded)';
    575611      }
    576612      else if ($i == $this->data['last_zip']+1)
     
    578614          $out.= '<a href="'.add_url_params($url, array('set_id'=>$this->data['id'],'zip'=>$i)).'" rel="nofollow" style="font-weight:bold;"'
    579615            .($i!=1 ? ' onClick="return confirm(\''.addslashes(sprintf(l10n('Starting download Archive #%d will destroy Archive #%d, be sure you finish the download. Continue ?'), $i, $i-1)).'\');"' : null).
    580             '><img src="'.$root_url.BATCH_DOWNLOAD_PATH.'template/drive_go.png"> Archive #'.$i.' (ready)</a>';
     616            '><img src="'.$root_url.BATCH_DOWNLOAD_PATH.'template/images/drive_go.png"> Archive #'.$i.' (ready)</a>';
    581617      }
    582618      else
    583619      {
    584         $out.= '<img src="'.$root_url.BATCH_DOWNLOAD_PATH.'template/drive.png"> Archive #'.$i.' (pending)';
     620        $out.= '<img src="'.$root_url.BATCH_DOWNLOAD_PATH.'template/images/drive.png"> Archive #'.$i.' (pending)';
    585621      }
    586622     
     
    613649    $path.= $set['BASENAME'] . '_';
    614650    $path.= $this->data['user_id'] . $this->data['id'];
    615     $path.= $this->getEstimatedArchiveNumber()!=1 ? '_part' . $i : null;
     651    $path.= '_part' . $i;
    616652    $path.= '.zip';
    617653   
     
    811847    $set = array(
    812848      'NB_IMAGES' =>     $this->data['nb_images'],
    813       'NB_ARCHIVES' =>   $this->data['status']=='new' ? l10n('unknown') : $this->getEstimatedArchiveNumber(),
     849      'NB_ARCHIVES' =>   $this->data['status']=='new' ? l10n('Unknown') : $this->getEstimatedArchiveNumber(),
    814850      'STATUS' =>        $this->data['status'],
    815851      'LAST_ZIP' =>      $this->data['last_zip'],
    816       'TOTAL_SIZE' =>    $this->data['status']=='new' ? l10n('unknown') : ceil($this->getEstimatedTotalSize()/1024),
    817       // 'LINKS' =>         $this->getDownloadList(BATCH_DOWNLOAD_PUBLIC . 'init_zip'),
     852      'TOTAL_SIZE' =>    $this->data['status']=='new' ? l10n('Unknown') : sprintf(l10n('%d MB'), ceil($this->getEstimatedTotalSize()/1024)),
    818853      'DATE_CREATION' => format_date($this->data['date_creation'], true),
    819854      'SIZE_ID' =>       $this->data['size'],
    820       'SIZE' =>          l10n($this->data['size']),
     855      'SIZE' =>          $this->data['size']=='original' ? l10n('Original') : l10n($this->data['size']),
    821856      );
    822857     
Note: See TracChangeset for help on using the changeset viewer.