Ignore:
Timestamp:
09/13/12 03:56:14 (7 years ago)
Author:
mistic100
Message:
  • now archive comment is well added
  • add PclZip library for servers without ZipArchive
File:
1 edited

Legend:

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

    r17656 r17880  
    2020     
    2121    $this->conf = $conf['batch_download']; 
    22     $this->conf['archive_acomment'] = $conf['batch_download_comment']; 
    2322    $this->data = array( 
    2423      'id' => 0, 
     
    270269    } 
    271270     
     271    global $conf; 
     272     
    272273    // first zip 
    273274    if ($this->data['last_zip'] == 0) 
     
    314315      $zip_path = $this->getArchivePath(); 
    315316       
    316       $zip = new ZipArchive; 
    317       if ($zip->open($zip_path, ZipArchive::CREATE) !== true) 
    318       { 
    319         trigger_error('BatchDownloader::createNextArchive, unable to open ZIP archive', E_USER_ERROR); 
    320       } 
     317      $zip = new myZip($zip_path, isset($conf['batch_download_force_pclzip'])); 
    321318       
    322319      // add images until size limit is reach, or all images are added 
     
    337334       
    338335      // archive comment 
    339       global $conf; 
    340       $comment = 'Generated on '.date('r').' with PHP ZipArchive '.PHP_VERSION.' by Piwigo Batch Downloader.'; 
     336      $comment = 'Generated on '.date('r').' with PHP '.PHP_VERSION.' by Piwigo Batch Downloader.'; 
    341337      $comment.= "\n".$conf['gallery_title'].' - '.get_absolute_root_url(); 
    342       if (!empty($this->conf['archive_comment'])) 
    343       { 
    344         $comment.= "\n\n".wordwrap(remove_accents($this->conf['archive_comment']), 60); 
     338      if (!empty($conf['batch_download_comment'])) 
     339      { 
     340        $comment.= "\n\n".wordwrap(remove_accents($conf['batch_download_comment']), 60); 
    345341      } 
    346342      $zip->setArchiveComment($comment); 
     
    629625    } 
    630626     
    631     if (!isset($set['sNAME'])) $set['sNAME'] = strip_tags($set['NAME']); 
     627    if (!isset($set['sNAME']))   $set['sNAME'] = strip_tags($set['NAME']); 
    632628    if (!isset($set['COMMENT'])) $set['COMMENT'] = null; 
    633629     
    634630    return $set; 
     631  } 
     632} 
     633 
     634 
     635/** 
     636 * small class implementing basic ZIP creation 
     637 * with ZipArchive or PclZip 
     638 */ 
     639class myZip 
     640{ 
     641  private $lib; 
     642  private $zip; 
     643   
     644  function __construct($zip_path, $pclzip=false) 
     645  { 
     646    if ( class_exists('ZipArchive') and !$pclzip ) 
     647    { 
     648      $this->lib = 'zipa'; 
     649       
     650      $this->zip = new ZipArchive; 
     651      if ($this->zip->open($zip_path, ZipArchive::CREATE) !== true) 
     652      { 
     653        trigger_error('BatchDownloader::createNextArchive, unable to open ZIP archive (ZipArchive)', E_USER_ERROR); 
     654      } 
     655    } 
     656    else 
     657    { 
     658      $this->lib = 'pcl'; 
     659       
     660      require_once(BATCH_DOWNLOAD_PATH.'include/pclzip.lib.php'); 
     661      $this->zip = new PclZip($zip_path); 
     662       
     663      // create a temporary file for archive creation 
     664      touch(BATCH_DOWNLOAD_LOCAL.'temp.txt'); 
     665       
     666      if ($this->zip->create(BATCH_DOWNLOAD_LOCAL.'temp.txt', PCLZIP_OPT_REMOVE_ALL_PATH) == 0) 
     667      { 
     668        trigger_error('BatchDownloader::createNextArchive, unable to open ZIP archive (PclZip)', E_USER_ERROR); 
     669      } 
     670       
     671      unlink(BATCH_DOWNLOAD_LOCAL.'temp.txt'); 
     672      $this->zip->delete(PCLZIP_OPT_BY_NAME, 'temp.txt'); 
     673    } 
     674  } 
     675   
     676  function addFile($path, $filename) 
     677  { 
     678    if ($this->lib == 'zipa') 
     679    { 
     680      $this->zip->addFile($path, $filename); 
     681    } 
     682    else 
     683    { 
     684      $this->zip->add($path, PCLZIP_OPT_REMOVE_ALL_PATH); 
     685    } 
     686  } 
     687   
     688  function setArchiveComment($comment) 
     689  { 
     690    if ($this->lib == 'zipa') 
     691    { 
     692      $this->zip->setArchiveComment($comment); 
     693    } 
     694  } 
     695   
     696  function close() 
     697  { 
     698    if ($this->lib == 'zipa') 
     699    { 
     700      $this->zip->close(); 
     701    } 
    635702  } 
    636703} 
Note: See TracChangeset for help on using the changeset viewer.