Changeset 17880


Ignore:
Timestamp:
Sep 13, 2012, 3:56:14 AM (8 years ago)
Author:
mistic100
Message:
  • now archive comment is well added
  • add PclZip library for servers without ZipArchive
Location:
extensions/BatchDownloader
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • extensions/BatchDownloader/admin.php

    r17517 r17880  
    1717if (!class_exists('ZipArchive'))
    1818{
    19   array_push($page['errors'], l10n('Unable to find ZipArchive PHP extension, Batch Downloader can\'t work without this extension.'));
     19  array_push($page['warnings'], l10n('Unable to find ZipArchive PHP extension, Batch Downloader will use PclZip instead, but with degraded performance.'));
    2020}
    2121
  • extensions/BatchDownloader/admin/config.php

    r16689 r17880  
    5252  'batch_download' => $conf['batch_download'],
    5353  'batch_download_comment' => stripslashes($conf['batch_download_comment']),
     54  'use_ziparchive' => class_exists('ZipArchive') && !isset($conf['batch_downloader_force_pclzip']),
     55  'PHP_VERSION' => PHP_VERSION,
    5456  ));
    5557
  • extensions/BatchDownloader/admin/template/config.tpl

    r16697 r17880  
    107107      </label>
    108108    </li>
     109  {if $use_ziparchive}
    109110    <li>
    110111      <label>
     
    115116      <i>{'Warning: ZipArchive doesn\'t accept special characters like accentuated ones, angle quotes (») and non-latin alphabets.'|@translate}</i>
    116117    </li>
     118  {else}
     119    <input type="hidden" name="archive_comment" value="">
     120  {/if}
    117121  </ul>
    118122</fieldset>
    119123
    120124<p class="formButtons"><input type="submit" name="save_config" value="{'Save Settings'|@translate}"></p> 
     125
     126<fieldset>
     127  <legend>{'Environment'|@translate}</legend>
     128 
     129  <b>PHP</b> {$PHP_VERSION}<br>
     130{if $use_ziparchive}
     131  <b>ZipArchive</b> {$PHP_VERSION}
     132{else}
     133  <b>PclZip</b> 2.8.2
     134{/if}
     135</fieldset>
     136 
    121137</form>
  • 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}
  • extensions/BatchDownloader/language/en_UK/plugin.lang.php

    r16697 r17880  
    4040$lang['Return to download page'] = 'Return to download page';
    4141$lang['Warning: ZipArchive doesn\'t accept special characters like accentuated ones, angle quotes (») and non-latin alphabets.'] = 'Warning: ZipArchive doesn\'t accept special characters like accentuated ones, angle quotes (») and non-latin alphabets.';
    42 $lang['Unable to find ZipArchive PHP extension, Batch Downloader can\'t work without this extension.'] = 'Unable to find ZipArchive PHP extension, Batch Downloader can\'t work without this extension.';
     42$lang['Unable to find ZipArchive PHP extension, Batch Downloader will use PclZip instead, but with degraded performance.'] = 'Unable to find ZipArchive PHP extension, Batch Downloader will use PclZip instead, but with degraded performance.';
    4343$lang['Remove from download set'] = 'Remove from download set';
    4444$lang['Confirm the download of %d pictures?'] = 'Confirm the download of %d pictures?';
  • extensions/BatchDownloader/language/fr_FR/plugin.lang.php

    r16697 r17880  
    4040$lang['Return to download page'] = 'Retourner à la page de téléchargement';
    4141$lang['Warning: ZipArchive doesn\'t accept special characters like accentuated ones, angle quotes (») and non-latin alphabets.'] = 'Attention: ZipArchive n\'accepte pas les caractères spéciaux comme les caractères accentués, les guillemets (») et les alphabets non-latin.';
    42 $lang['Unable to find ZipArchive PHP extension, Batch Downloader can\'t work without this extension.'] = 'Impossible de trouver l\'extension PHP ZipArchive, Batch Downloader ne peut fonctionner sans cette extension';
     42$lang['Unable to find ZipArchive PHP extension, Batch Downloader will use PclZip instead, but with degraded performance.'] = 'Impossible de trouver l\'extension PHP ZipArchive, Batch Downloader va utiliser PclZip à la place, mais avec des performances dégradées.';
    4343$lang['Remove from download set'] = 'Supprimer du lot';
    4444$lang['Confirm the download of %d pictures?'] = 'Confirmer le téléchargementde %d photos ?';
  • extensions/BatchDownloader/main.inc.php

    r17656 r17880  
    1919define('BATCH_DOWNLOAD_ADMIN',   get_root_url() . 'admin.php?page=plugin-BatchDownloader');
    2020define('BATCH_DOWNLOAD_PUBLIC',  get_absolute_root_url() . make_index_url(array('section' => 'download')) . '/');
    21 define('BATCH_DOWNLOAD_VERSION', '1.0.3');
     21define('BATCH_DOWNLOAD_VERSION', '1.0.4');
    2222
    2323
    2424add_event_handler('init', 'batch_download_init');
    2525
    26 if (class_exists('ZipArchive'))
    27 {
    28   add_event_handler('loc_end_section_init', 'batch_download_section_init');
    29   add_event_handler('loc_end_index', 'batch_download_page');
    30  
    31   add_event_handler('loc_end_index', 'batch_download_clean');
     26add_event_handler('loc_end_section_init', 'batch_download_section_init');
     27add_event_handler('loc_end_index', 'batch_download_page');
    3228
    33   add_event_handler('loc_end_index', 'batch_download_index_button', EVENT_HANDLER_PRIORITY_NEUTRAL+10);
     29add_event_handler('loc_end_index', 'batch_download_clean');
    3430
    35   add_event_handler('blockmanager_register_blocks', 'batch_download_add_menublock');
    36   add_event_handler('blockmanager_apply', 'batch_download_applymenu');
    37  
    38   include_once(BATCH_DOWNLOAD_PATH . 'include/BatchDownloader.class.php');
    39   include_once(BATCH_DOWNLOAD_PATH . 'include/functions.inc.php');
    40   include_once(BATCH_DOWNLOAD_PATH . 'include/events.inc.php');
    41 }
     31add_event_handler('loc_end_index', 'batch_download_index_button', EVENT_HANDLER_PRIORITY_NEUTRAL+10);
     32
     33add_event_handler('blockmanager_register_blocks', 'batch_download_add_menublock');
     34add_event_handler('blockmanager_apply', 'batch_download_applymenu');
     35
     36include_once(BATCH_DOWNLOAD_PATH . 'include/BatchDownloader.class.php');
     37include_once(BATCH_DOWNLOAD_PATH . 'include/functions.inc.php');
     38include_once(BATCH_DOWNLOAD_PATH . 'include/events.inc.php');
    4239
    4340if (defined('IN_ADMIN'))
     
    4946
    5047/**
    51  * unserialize conf and load language
     48 * update plugin & unserialize conf & load language
    5249 */
    5350function batch_download_init()
Note: See TracChangeset for help on using the changeset viewer.