Changeset 25932


Ignore:
Timestamp:
12/12/13 14:41:53 (6 years ago)
Author:
mistic100
Message:

update for Piwigo 2.6 + code cleaning + fix unable to cancel set during generation

Location:
extensions/BatchDownloader
Files:
2 deleted
17 edited

Legend:

Unmodified
Added
Removed
  • extensions/BatchDownloader/admin.php

    r17880 r25932  
    88include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); 
    99$page['tab'] = (isset($_GET['tab'])) ? $_GET['tab'] : 'sets'; 
    10    
     10 
    1111$tabsheet = new tabsheet(); 
    1212$tabsheet->add('sets', l10n('Download history'), BATCH_DOWNLOAD_ADMIN . '-sets'); 
     
    1717if (!class_exists('ZipArchive')) 
    1818{ 
    19   array_push($page['warnings'], l10n('Unable to find ZipArchive PHP extension, Batch Downloader will use PclZip instead, but with degraded performance.')); 
     19  $page['warnings'][] = l10n('Unable to find ZipArchive PHP extension, Batch Downloader will use PclZip instead, but with degraded performance.'); 
    2020} 
    2121 
     
    2828  'BATCH_DOWNLOAD_ADMIN' => BATCH_DOWNLOAD_ADMIN, 
    2929  )); 
    30    
     30 
    3131$template->assign_var_from_handle('ADMIN_CONTENT', 'batch_download'); 
    32  
    33 ?> 
  • extensions/BatchDownloader/admin/config.php

    r25931 r25932  
    11<?php 
    2 if (!defined('BATCH_DOWNLOAD_PATH')) die('Hacking attempt!'); 
     2defined('BATCH_DOWNLOAD_PATH') or die('Hacking attempt!'); 
    33 
    44if (isset($_POST['save_config'])) 
    55{ 
    66  if (!defined('USER_COLLEC_ID')) $_POST['what']['collections'] = 'on'; 
    7    
     7 
    88  $conf['batch_download'] = array( 
    99    'groups'          => isset($_POST['groups']) ? $_POST['groups'] : array(), 
     
    2222    ); 
    2323  $conf['batch_download_comment'] = trim($_POST['archive_comment']); 
    24    
     24 
    2525  conf_update_param('batch_download', serialize($conf['batch_download'])); 
    2626  conf_update_param('batch_download_comment', $conf['batch_download_comment']); 
    27    
    28   array_push($page['infos'], l10n('Information data registered in database')); 
     27 
     28  $page['infos'][] = l10n('Information data registered in database'); 
    2929} 
    3030 
     
    6767 
    6868 
    69 $template->set_filename('batch_download', dirname(__FILE__) . '/template/config.tpl'); 
    70  
    71 ?> 
     69$template->set_filename('batch_download', realpath(BATCH_DOWNLOAD_PATH . 'admin/template/config.tpl')); 
  • extensions/BatchDownloader/admin/sets.php

    r23383 r25932  
    11<?php 
    2 if (!defined('BATCH_DOWNLOAD_PATH')) die('Hacking attempt!'); 
     2defined('BATCH_DOWNLOAD_PATH') or die('Hacking attempt!'); 
    33 
    44// actions 
     
    1111if (isset($_GET['cancel'])) 
    1212{ 
    13   $set = new BatchDownloader($_GET['cancel']);   
     13  $set = new BatchDownloader($_GET['cancel']); 
    1414  $set->updateParam('total_size', $set->getEstimatedTotalSize()); 
    1515  $set->updateParam('nb_zip', $set->getEstimatedArchiveNumber()); 
     
    2828    date_creation < DATE_SUB(NOW(), INTERVAL 1 HOUR) 
    2929;'; 
    30    
     30 
    3131  $sets = array_from_query($query, 'id'); 
    32    
     32 
    3333  foreach ($sets as $set_id) 
    3434  { 
     
    4848  if (!empty($_POST['username'])) 
    4949  { 
    50     array_push($where_clauses, 'username LIKE "%'.$_POST['username'].'%"'); 
     50    $where_clauses[] = 'username LIKE "%'.$_POST['username'].'%"'; 
    5151  } 
    52    
     52 
    5353  if ($_POST['type'] != -1) 
    5454  { 
    55     array_push($where_clauses, 'type = "'.$_POST['type'].'"'); 
     55    $where_clauses[] = 'type = "'.$_POST['type'].'"'; 
    5656  } 
    57    
     57 
    5858  if ($_POST['status'] != -1) 
    5959  { 
    6060    if ($_POST['status'] == 'new') 
    61       array_push($where_clauses, '(status = "new" OR status = "ready")'); 
     61      $where_clauses[] = '(status = "new" OR status = "ready")'; 
    6262    else 
    63       array_push($where_clauses, 'status = "'.$_POST['status'].'"'); 
     63      $where_clauses[] = 'status = "'.$_POST['status'].'"'; 
    6464  } 
    65    
     65 
    6666  if ($_POST['size'] != -1) 
    6767  { 
    68     array_push($where_clauses, 'size = "'.$_POST['size'].'"'); 
     68    $where_clauses[] = 'size = "'.$_POST['size'].'"'; 
    6969  } 
    70    
     70 
    7171  if ($_POST['order_by'] == 'size') 
    7272  { 
     
    8282// get sets 
    8383$query = ' 
    84 SELECT  
     84SELECT 
    8585    s.id, 
    8686    u.'.$conf['user_fields']['username'].' AS username 
     
    9797{ 
    9898  $set = new BatchDownloader($set_id); 
    99    
     99 
    100100  $template->append('sets', array_merge( 
    101101    $set->getSetInfo(), 
     
    106106    ) 
    107107    )); 
    108    
     108 
    109109  unset($set); 
    110110} 
     
    173173 
    174174 
    175 $template->set_filename('batch_download', dirname(__FILE__) . '/template/sets.tpl'); 
    176  
    177 ?> 
     175$template->set_filename('batch_download', realpath(BATCH_DOWNLOAD_PATH . 'admin/template/sets.tpl')); 
  • extensions/BatchDownloader/admin/template/config.tpl

    r25931 r25932  
    1 {combine_css path=$BATCH_DOWNLOAD_PATH|@cat:"admin/template/style.css"} 
     1{combine_css path=$BATCH_DOWNLOAD_PATH|cat:"admin/template/style.css"} 
    22 
    33{combine_script id='jquery.ui.slider' require='jquery.ui' load='footer' path='themes/default/js/ui/jquery.ui.slider.js'} 
     
    5151$('input[name="multisize"]').on('change', function() { 
    5252  if ($(this).val() == 'true') { 
    53     $('#multisize_title').text('{'Maximum photo size'|@translate|escape:javascript}'); 
     53    $('#multisize_title').text('{'Maximum photo size'|translate|escape:javascript}'); 
    5454  } 
    5555  else { 
    56     $('#multisize_title').text('{'Photo size'|@translate|escape:javascript}'); 
     56    $('#multisize_title').text('{'Photo size'|translate|escape:javascript}'); 
    5757  } 
    5858}) 
     
    6767<form method="post" action="" class="properties"> 
    6868<fieldset> 
    69   <legend>{'Download permissions'|@translate}</legend> 
    70    
     69  <legend>{'Download permissions'|translate}</legend> 
     70 
    7171  <ul> 
    7272    <li> 
    73       <i>{'Warning: Only registered users can use Batch Downloader.'|@translate}</i> 
     73      <i>{'Warning: Only registered users can use Batch Downloader.'|translate}</i> 
    7474    </li> 
    7575    <li> 
    7676      <label> 
    7777      {if $group_options} 
    78         <b>{'User groups'|@translate}</b> 
    79         <select name="groups[]" data-placeholder="{'Everybody'|@translate}" class="chzn-select" multiple="multiple" style="width:370px;"> 
     78        <b>{'User groups'|translate}</b> 
     79        <select name="groups[]" data-placeholder="{'Everybody'|translate}" class="chzn-select" multiple="multiple" style="width:370px;"> 
    8080          {html_options options=$group_options selected=$batch_download.groups} 
    8181        </select> 
    8282      {else} 
    83         {'There is no group in this gallery.'|@translate} <a href="admin.php?page=group_list">{'Group management'|@translate}</a> 
     83        {'There is no group in this gallery.'|translate} <a href="admin.php?page=group_list">{'Group management'|translate}</a> 
    8484      {/if} 
    8585      </label> 
     
    8787    <li> 
    8888      <label> 
    89         <b>{'Privacy level'|@translate}</b> 
     89        <b>{'Privacy level'|translate}</b> 
    9090        <select name="level"> 
    9191          {html_options options=$level_options selected=$batch_download.level} 
     
    9494    </li> 
    9595    <li> 
    96       <b>{'What can be downloaded?'|@translate}</b> 
    97       <label><input type="checkbox" name="what[categories]" {if in_array('categories',$batch_download.what)}checked="checked"{/if}/> {'Albums'|@translate}</label> 
    98       {if $USER_COLLEC_LOADED}<label><input type="checkbox" name="what[collections]" {if in_array('collections',$batch_download.what)}checked="checked"{/if}/> {'Collections'|@translate}</label>{/if} 
    99       <label><input type="checkbox" name="what[specials]" {if in_array('specials',$batch_download.what)}checked="checked"{/if}/> {'Specials'|@translate}</label> 
    100       <a class="icon-info-circled-1 showInfo" title="{'Most visited'|@translate}, {'Random photos'|@translate}, {'Best rated'|@translate}..."></a> 
     96      <b>{'What can be downloaded?'|translate}</b> 
     97      <label><input type="checkbox" name="what[categories]" {if in_array('categories',$batch_download.what)}checked="checked"{/if}/> {'Albums'|translate}</label> 
     98      {if $USER_COLLEC_LOADED}<label><input type="checkbox" name="what[collections]" {if in_array('collections',$batch_download.what)}checked="checked"{/if}/> {'Collections'|translate}</label>{/if} 
     99      <label><input type="checkbox" name="what[specials]" {if in_array('specials',$batch_download.what)}checked="checked"{/if}/> {'Specials'|translate}</label> 
     100      <a class="icon-info-circled-1 showInfo" title="{'Most visited'|translate}, {'Random photos'|translate}, {'Best rated'|translate}..."></a> 
    101101    </li> 
    102102    <li> 
     
    106106 
    107107      <label> 
    108         <b id="multisize_title">{'Maximum photo size'|@translate}</b> 
     108        <b id="multisize_title">{'Maximum photo size'|translate}</b> 
    109109        <select name="photo_size"> 
    110110          {html_options options=$sizes_options selected=$batch_download.photo_size} 
     
    116116 
    117117<fieldset> 
    118   <legend>{'Archives'|@translate}</legend> 
    119    
     118  <legend>{'Archives'|translate}</legend> 
     119 
    120120  <ul> 
    121121    <li> 
    122122      <label> 
    123         <b>{'Delete downloads after'|@translate}</b> 
    124         <input type="text" name="archive_timeout" value="{$batch_download.archive_timeout}" size="3"> {'hours'|@translate} 
    125       </label> 
    126     </li> 
    127     <li> 
    128       <label> 
    129         <b>{'Maximum number of photos per download set'|@translate}</b> 
     123        <b>{'Delete downloads after'|translate}</b> 
     124        <input type="text" name="archive_timeout" value="{$batch_download.archive_timeout}" size="3"> {'hours'|translate} 
     125      </label> 
     126    </li> 
     127    <li> 
     128      <label> 
     129        <b>{'Maximum number of photos per download set'|translate}</b> 
    130130        <div id="max_elements"></div> 
    131131        <input type="text" name="max_elements" value="{$batch_download.max_elements}" size="5"> 
     
    134134    <li> 
    135135      <label> 
    136         <b>{'Maximum size of each archive (in Megabytes)'|@translate}</b> 
     136        <b>{'Maximum size of each archive (in Megabytes)'|translate}</b> 
    137137        <div id="max_size"></div> 
    138138        <input type="text" name="max_size" value="{$batch_download.max_size}" size="5"> 
     
    141141    <li> 
    142142      <label> 
    143         <b>{'Archive prefix'|@translate}</b> 
     143        <b>{'Archive prefix'|translate}</b> 
    144144        <input type="text" name="archive_prefix" value="{$batch_download.archive_prefix}"> 
    145145      </label> 
     
    148148      <label> 
    149149        <input type="checkbox" name="one_archive" {if $batch_download.one_archive}checked{/if}> 
    150         <b>{'Delete previous archive when starting to download another one'|@translate}</b> 
    151       </label> 
    152       <a class="icon-info-circled-1 showInfo" title="{'It saves space on the server but doesn\'t allow to restart failed downloads.'|@translate}"></a> 
     150        <b>{'Delete previous archive when starting to download another one'|translate}</b> 
     151      </label> 
     152      <a class="icon-info-circled-1 showInfo" title="{'It saves space on the server but doesn\'t allow to restart failed downloads.'|translate}"></a> 
    153153    </li> 
    154154    <li> 
    155155      <label> 
    156156        <input type="checkbox" name="force_pclzip" {if $batch_download.force_pclzip}checked{/if}> 
    157         <b>{'Force the usage of PclZip instead of ZipArchive as ZIP library'|@translate}</b> 
    158       </label> 
    159       <a class="icon-info-circled-1 showInfo" title="{'Only check if you are experiencing corrupted archives with ZipArchive.'|@translate}"></a> 
     157        <b>{'Force the usage of PclZip instead of ZipArchive as ZIP library'|translate}</b> 
     158      </label> 
     159      <a class="icon-info-circled-1 showInfo" title="{'Only check if you are experiencing corrupted archives with ZipArchive.'|translate}"></a> 
    160160    </li> 
    161161    <li> 
    162162      <label> 
    163163        <input type="checkbox" name="direct" {if $batch_download.direct}checked{/if}> 
    164         <b>{'Don\'t download archives through PHP'|@translate}</b> 
    165       </label> 
    166       <a class="icon-info-circled-1 showInfo" title="{'Only check if your host complains about high PHP usage.'|@translate}"></a> 
     164        <b>{'Don\'t download archives through PHP'|translate}</b> 
     165      </label> 
     166      <a class="icon-info-circled-1 showInfo" title="{'Only check if your host complains about high PHP usage.'|translate}"></a> 
    167167    </li> 
    168168  {if $use_ziparchive} 
    169169    <li> 
    170170      <label> 
    171         <b>{'Archive comment'|@translate} :</b><br> 
     171        <b>{'Archive comment'|translate} :</b><br> 
    172172        <textarea name="archive_comment" rows="5" style="width:450px;">{$batch_download_comment}</textarea> 
    173173      </label> 
    174174      <br> 
    175       <i>{'Warning: ZipArchive doesn\'t accept special characters like accentuated ones, angle quotes (») and non-latin alphabets.'|@translate}</i> 
     175      <i>{'Warning: ZipArchive doesn\'t accept special characters like accentuated ones, angle quotes (») and non-latin alphabets.'|translate}</i> 
    176176    </li> 
    177177  {else} 
     
    181181</fieldset> 
    182182 
    183 <p class="formButtons"><input type="submit" name="save_config" value="{'Save Settings'|@translate}"></p>   
    184  
    185 <fieldset> 
    186   <legend>{'Environment'|@translate}</legend> 
    187    
     183<p class="formButtons"><input type="submit" name="save_config" value="{'Save Settings'|translate}"></p> 
     184 
     185<fieldset> 
     186  <legend>{'Environment'|translate}</legend> 
     187 
    188188  <b>PHP</b> {$PHP_VERSION}<br> 
    189189{if $use_ziparchive} 
     
    195195 
    196196<fieldset> 
    197   <legend>{'Advanced features'|@translate}</legend> 
    198    
     197  <legend>{'Advanced features'|translate}</legend> 
     198 
    199199  <dl class="advanced" style="display:none;"> 
    200200    {$ADVANCED_CONF} 
    201201  </dl> 
    202    
    203   <span class="show_advanced buttonLike">{'Display'|@translate}</span> 
     202 
     203  <span class="show_advanced buttonLike">{'Display'|translate}</span> 
    204204</fieldset> 
    205205 
  • extensions/BatchDownloader/admin/template/sets.tpl

    r23589 r25932  
    1 {combine_css path=$BATCH_DOWNLOAD_PATH|@cat:"admin/template/style.css"} 
     1{combine_css path=$BATCH_DOWNLOAD_PATH|cat:"admin/template/style.css"} 
    22 
    33<div class="titrePage"> 
     
    77<form class="filter" method="post" name="filter" action="{$F_FILTER_ACTION}"> 
    88<fieldset> 
    9   <legend>{'Filter'|@translate}</legend> 
     9  <legend>{'Filter'|translate}</legend> 
    1010 
    1111  <label> 
    12     {'Username'|@translate} 
     12    {'Username'|translate} 
    1313    <input type="text" name="username" value="{$F_USERNAME}"> 
    1414  </label> 
    1515 
    1616  <label> 
    17     {'Set type'|@translate} 
     17    {'Set type'|translate} 
    1818    {html_options name=type options=$type_options selected=$type_selected} 
    1919  </label> 
    20    
     20 
    2121  <label> 
    22     {'Photo sizes'|@translate} 
     22    {'Photo sizes'|translate} 
    2323    {html_options name=size options=$size_options selected=$size_selected} 
    2424  </label> 
    25    
     25 
    2626  <label> 
    27     {'Status'|@translate} 
     27    {'Status'|translate} 
    2828    {html_options name=status options=$status_options selected=$status_selected} 
    2929  </label> 
    3030 
    3131  <label> 
    32     {'Sort by'|@translate} 
     32    {'Sort by'|translate} 
    3333    {html_options name=order_by options=$order_options selected=$order_selected} 
    3434  </label> 
    3535 
    3636  <label> 
    37     {'Sort order'|@translate} 
     37    {'Sort order'|translate} 
    3838    {html_options name=direction options=$direction_options selected=$direction_selected} 
    3939  </label> 
     
    4141  <label> 
    4242    &nbsp; 
    43     <span><input class="submit" type="submit" name="filter" value="{'Submit'|@translate}"> <a href="{$F_FILTER_ACTION}">{'Reset'|@translate}</a></span> 
     43    <span><input class="submit" type="submit" name="filter" value="{'Submit'|translate}"> <a href="{$F_FILTER_ACTION}">{'Reset'|translate}</a></span> 
    4444  </label> 
    4545 
     
    5151  <thead> 
    5252    <tr class="throw"> 
    53       <td class="user">{'Username'|@translate}</td> 
    54       <td class="type">{'Set type'|@translate}</td> 
    55       <td class="date">{'Creation date'|@translate}</td> 
    56       <td class="img_size">{'Photo sizes'|@translate}</td> 
    57       <td class="images">{'Number of images'|@translate}</td> 
    58       <td class="archives">{'Number of archives'|@translate}</td> 
    59       <td class="size">{'Total size'|@translate}</td> 
    60       <td class="status">{'Status'|@translate}</td> 
    61       <td class="action">{'Actions'|@translate}</td> 
     53      <td class="user">{'Username'|translate}</td> 
     54      <td class="type">{'Set type'|translate}</td> 
     55      <td class="date">{'Creation date'|translate}</td> 
     56      <td class="img_size">{'Photo sizes'|translate}</td> 
     57      <td class="images">{'Number of images'|translate}</td> 
     58      <td class="archives">{'Number of archives'|translate}</td> 
     59      <td class="size">{'Total size'|translate}</td> 
     60      <td class="status">{'Status'|translate}</td> 
     61      <td class="action">{'Actions'|translate}</td> 
    6262    </tr> 
    6363  </thead> 
     
    6868    <td>{$set.NAME}</td> 
    6969    <td style="text-align:center;">{$set.DATE_CREATION}</td> 
    70     <td>{if $set.SIZE=='original'}{'Original'|@translate}{else}{$set.SIZE|@translate}{/if}</td> 
     70    <td>{if $set.SIZE=='original'}{'Original'|translate}{else}{$set.SIZE|translate}{/if}</td> 
    7171    <td>{$set.NB_IMAGES}</td> 
    7272    <td>{$set.NB_ARCHIVES}</td> 
    7373    <td>{$set.TOTAL_SIZE}</td> 
    7474    <td> 
    75       {$set.STATUS|@translate} 
     75      {$set.STATUS|translate} 
    7676      {if $set.STATUS == 'download'}<i style="font-size:0.8em;">({$set.LAST_ZIP}/{$set.NB_ARCHIVES})</i>{/if} 
    7777    </td> 
    7878    <td style="padding-left:25px;"> 
    79       <a href="{$set.U_DELETE}" title="{'Delete this set'|@translate}" onClick="return confirm('{'Are you sure?'|@translate}');"><img src="{$themeconf.admin_icon_dir}/delete.png"></a> 
    80       {if $set.STATUS != 'done'}<a href="{$set.U_CANCEL}" title="{'Cancel this set'|@translate}" onClick="return confirm('{'Are you sure?'|@translate}');"><img src="{$themeconf.admin_icon_dir}/permissions.png"></a>{/if} 
     79      <a href="{$set.U_DELETE}" title="{'Delete this set'|translate}" onClick="return confirm('{'Are you sure?'|translate}');"><img src="{$themeconf.admin_icon_dir}/delete.png"></a> 
     80      {if $set.STATUS != 'done'}<a href="{$set.U_CANCEL}" title="{'Cancel this set'|translate}" onClick="return confirm('{'Are you sure?'|translate}');"><img src="{$themeconf.admin_icon_dir}/permissions.png"></a>{/if} 
    8181    </td> 
    8282  </tr> 
    8383  {/foreach} 
    84    
     84 
    8585  {if not $sets} 
    8686  <tr class="row2"> 
    87     <td colspan="8" style="text-align:center;font-style:italic;">{'No result'|@translate}</td> 
     87    <td colspan="8" style="text-align:center;font-style:italic;">{'No result'|translate}</td> 
    8888  </tr> 
    8989  {/if} 
     
    9191 
    9292<form action="{$F_FILTER_ACTION}" method="post"> 
    93 <p><label><input type="checkbox" name="delete_done" value="1"> {'Remove all finished downloads'|@translate}</label> 
    94 <input type="submit" value="{'Submit'|@translate}"></p> 
     93  <p><label><input type="checkbox" name="delete_done" value="1"> {'Remove all finished downloads'|translate}</label> 
     94  <input type="submit" value="{'Submit'|translate}"></p> 
    9595</form> 
  • extensions/BatchDownloader/download.php

    r23383 r25932  
    77try { 
    88  $BatchDownloader = new BatchDownloader($_GET['set_id']); 
    9    
     9 
    1010  if ($conf['batch_download']['one_archive'] and $_GET['zip'] == $BatchDownloader->getParam('last_zip')) 
    1111  { 
     
    1616    $file = $BatchDownloader->getArchivePath($_GET['zip']); 
    1717  } 
    18    
     18 
    1919  if (empty($file) || !file_exists($file)) 
    2020  { 
    2121    throw new Exception('Unable to locate file.'); 
    2222  } 
    23    
     23 
    2424  if ($conf['batch_download']['direct']) 
    2525  { 
     
    4747 
    4848exit(0); 
    49  
    50 ?> 
  • extensions/BatchDownloader/include/BatchDownloader.class.php

    r23804 r25932  
    77  private $data; 
    88  private $images; 
    9    
     9 
    1010  /** 
    1111   * __construct 
     
    1919  { 
    2020    global $user, $conf; 
    21      
     21 
    2222    $this->conf = $conf['batch_download']; 
    2323    $this->data = array( 
     
    3636      ); 
    3737    $this->images = array(); 
    38      
     38 
    3939    // load specific set 
    4040    if (preg_match('#^[0-9]+$#', $set_id)) 
     
    4747;'; 
    4848      $result = pwg_query($query); 
    49        
     49 
    5050      if (pwg_db_num_rows($result)) 
    5151      { 
     
    5454          pwg_db_fetch_assoc($result) 
    5555          ); 
    56          
     56 
    5757        // make sure all pictures of the set exist 
    5858        $query = ' 
     
    6363;'; 
    6464        pwg_query($query); 
    65        
     65 
    6666        $query = ' 
    6767SELECT * 
     
    7070;'; 
    7171        $this->images = simple_hash_from_query($query, 'image_id', 'zip'); 
    72          
     72 
    7373        if ( $this->data['status'] != 'done' and count($this->images) != $this->data['nb_images'] ) 
    7474        { 
     
    7878      else 
    7979      { 
    80         throw new Exception(l10n('Invalid dowload set')); 
     80        throw new Exception(l10n('Invalid download set')); 
    8181      } 
    8282    } 
     
    8989        if (!in_array($size, $types)) 
    9090        { 
    91           throw new Exception(sprintf(l10n('Invalid size %s'), $size)); 
    92         } 
    93       } 
    94    
     91          throw new Exception(l10n('Invalid size %s', $size)); 
     92        } 
     93      } 
     94 
    9595      $this->data['type'] = $type; 
    9696      $this->data['type_id'] = $type_id; 
    9797      $this->data['size'] = $size; 
    98        
     98 
    9999      $query = ' 
    100100INSERT INTO '.BATCH_DOWNLOAD_TSETS.'( 
     
    109109    total_size, 
    110110    status 
    111   )  
     111  ) 
    112112  VALUES( 
    113113    '.$this->data['user_id'].', 
     
    125125      pwg_query($query); 
    126126      $this->data['id'] = pwg_db_insert_id(); 
    127        
     127 
    128128      $date = pwg_query('SELECT FROM_UNIXTIME(NOW());'); 
    129129      list($this->data['date_creation']) = pwg_db_fetch_row($date); 
    130        
     130 
    131131      if (!empty($images)) 
    132132      { 
     
    139139    } 
    140140  } 
    141    
     141 
    142142  /** 
    143143   * updateParam 
     
    150150    pwg_query('UPDATE '.BATCH_DOWNLOAD_TSETS.' SET '.$name.' = "'.$value.'" WHERE id = '.$this->data['id'].';'); 
    151151  } 
    152    
     152 
    153153  /** 
    154154   * getParam 
     
    160160    return $this->data[$name]; 
    161161  } 
    162    
     162 
    163163  /** 
    164164   * getImages 
     
    169169    return $this->images; 
    170170  } 
    171    
     171 
    172172  /** 
    173173   * isInSet 
     
    179179    return array_key_exists($image_id, $this->images); 
    180180  } 
    181    
     181 
    182182  /** 
    183183   * removeImages 
     
    187187  { 
    188188    if (empty($image_ids) or !is_array($image_ids)) return; 
    189      
     189 
    190190    foreach ($image_ids as $image_id) 
    191191    { 
    192192      unset($this->images[ $image_id ]); 
    193193    } 
    194      
     194 
    195195    $query = ' 
    196196DELETE FROM '.BATCH_DOWNLOAD_TIMAGES.' 
    197   WHERE  
     197  WHERE 
    198198    set_id = '.$this->data['id'].' 
    199199    AND image_id IN('.implode(',', $image_ids).') 
    200200;'; 
    201201    pwg_query($query); 
    202      
     202 
    203203    $this->updateParam('nb_images', count($this->images)); 
    204204  } 
    205    
     205 
    206206  /** 
    207207   * addImages 
     
    211211  { 
    212212    if (empty($image_ids) or !is_array($image_ids)) return; 
    213      
     213 
    214214    $query = ' 
    215215SELECT id, file 
     
    218218;'; 
    219219    $images = simple_hash_from_query($query, 'id', 'file'); 
    220      
     220 
    221221    $inserts = array(); 
    222      
     222 
    223223    foreach ($images as $image_id => $file) 
    224224    { 
    225225      if ($this->isInSet($image_id)) continue; 
    226226      if (!in_array(get_extension($file), $this->conf['allowed_ext'])) continue; 
    227        
     227 
    228228      $this->images[ $image_id ] = 0; 
    229229      $inserts[] = array( 
     
    233233        ); 
    234234    } 
    235      
     235 
    236236    if (count($inserts)) 
    237237    { 
     
    242242        ); 
    243243    } 
    244        
     244 
    245245    $this->updateParam('nb_images', count($this->images)); 
    246246  } 
    247    
     247 
    248248  /** 
    249249   * clearImages 
     
    252252  { 
    253253    $this->images = array(); 
    254      
     254 
    255255    $query = ' 
    256256DELETE FROM '.BATCH_DOWNLOAD_TIMAGES.' 
     
    259259    pwg_query($query); 
    260260  } 
    261    
     261 
    262262  /** 
    263263   * getMissingDerivatives 
     
    271271      return array(); 
    272272    } 
    273      
     273 
    274274    $uid = '&b='.time(); 
    275      
     275 
    276276    $params = ImageStdParams::get_by_type($this->data['size']); 
    277277    $last_mod_time = $params->last_mod_time; 
    278      
     278 
    279279    $image_ids = array_keys($this->images); 
    280280    $to_update = $urls = $inserts = array(); 
    281      
     281 
    282282    global $conf; 
    283283    $conf['old_question_mark_in_urls'] = $conf['question_mark_in_urls']; 
     
    286286    $conf['question_mark_in_urls'] = $conf['php_extension_in_urls'] = true; 
    287287    $conf['derivative_url_style'] = 2; 
    288      
     288 
    289289    // images which we need to update stats 
    290290    if ($update) 
     
    297297;'; 
    298298      $registered = array_from_query($query, 'image_id', 'filemtime'); 
    299        
     299 
    300300      $to_update = array_filter($registered, create_function('$t', 'return $t<'.$last_mod_time.';')); 
    301301      $to_update = array_merge($to_update, array_diff($image_ids, $registered)); 
    302302    } 
    303      
     303 
    304304    $query = ' 
    305305SELECT id, path, width, height, rotation 
     
    313313    { 
    314314      $src_image = new SrcImage($row); // don't give representive_ext 
    315        
     315 
    316316      // no-image files 
    317317      if ($src_image->is_mimetype()) 
    318318      { 
    319319        if ($update && in_array($row['id'], $to_update)) 
    320         {           
     320        { 
    321321          $inserts[ $row['id'] ] = array( 
    322322            'image_id' => $row['id'], 
     
    333333      { 
    334334        $derivative = new DerivativeImage($this->data['size'], $src_image); 
    335          
     335 
    336336        $filemtime = @filemtime($derivative->get_path()); 
    337337        $src_mtime = @filemtime(PHPWG_ROOT_PATH.$row['path']); 
    338338        if ($src_mtime===false) continue; 
    339          
     339 
    340340        if ($filemtime===false || $filemtime<$last_mod_time || $filemtime<$src_mtime) 
    341341        { 
     
    345345        { 
    346346          $imagesize = getimagesize($derivative->get_path()); 
    347            
     347 
    348348          $inserts[ $row['id'] ] = array( 
    349349            'image_id' => $row['id'], 
     
    357357      } 
    358358    } 
    359      
     359 
    360360    if (!empty($inserts)) 
    361361    { 
     
    365365;'; 
    366366      pwg_query($query); 
    367        
     367 
    368368      mass_inserts( 
    369369        IMAGE_SIZES_TABLE, 
     
    372372        ); 
    373373    } 
    374      
     374 
    375375    $conf['question_mark_in_urls'] = $conf['old_question_mark_in_urls']; 
    376376    $conf['php_extension_in_urls'] = $conf['old_php_extension_in_urls']; 
    377377    $conf['derivative_url_style'] = $conf['old_derivative_url_style']; 
    378      
     378 
    379379    return $urls; 
    380380  } 
    381    
     381 
    382382  /** 
    383383   * deleteArchives 
     
    386386  { 
    387387    $zip_path = glob($this->getArchivePath('*')); 
    388      
     388 
    389389    if (is_array($zip_path)) 
    390390    { 
     
    395395    } 
    396396  } 
    397    
     397 
    398398  /** 
    399399   * getFilename 
     
    402402  { 
    403403    $row['filename'] = stripslashes(get_filename_wo_extension($row['file'])); 
    404      
     404 
    405405    // datas 
    406406    $search = array('%id%', '%filename%', '%author%', '%dimensions%'); 
    407407    $replace = array($row['id'], $row['filename']); 
    408      
     408 
    409409    $replace[2] = empty($row['author']) ? null : $row['author']; 
    410410    $replace[3] = empty($filesize) ? null : $filesize['width'].'x'.$filesize['height']; 
    411      
     411 
    412412    $filename = str_replace($search, $replace, $this->conf['file_pattern']); 
    413      
     413 
    414414    // functions 
    415415    $filename = preg_replace_callback('#\$escape\((.*?)\)#', create_function('$m', 'return str2url($m[1]);'),   $filename); 
     
    417417    $filename = preg_replace_callback('#\$lower\((.*?)\)#',  create_function('$m', 'return str2lower($m[1]);'), $filename); 
    418418    $filename = preg_replace_callback('#\$strpad\((.*?),(.*?),(.*?)\)#', create_function('$m', 'return str_pad($m[1],$m[2],$m[3],STR_PAD_LEFT);'), $filename); 
    419      
     419 
    420420    // cleanup 
    421421    $filename = preg_replace( 
     
    424424      $filename 
    425425      ); 
    426      
     426 
    427427    if (empty($filename) || $filename == $this->conf['file_pattern']) 
    428428    { 
    429429      $filename = $row['id'].'_'.$row['filename']; 
    430430    } 
    431      
     431 
    432432    $filename.= '.'.get_extension($row['path']); 
    433      
     433 
    434434    return $filename; 
    435435  } 
    436    
     436 
    437437  /** 
    438438   * createNextArchive 
     
    447447      trigger_error('BatchDownloader::createNextArchive, the set is empty', E_USER_ERROR); 
    448448    } 
    449      
     449 
    450450    global $conf; 
    451      
     451 
    452452    // first zip 
    453453    if ($this->data['last_zip'] == 0) 
    454454    { 
    455455      $this->updateParam('status', 'download'); 
    456        
     456 
    457457      // limit number of elements 
    458458      if ($this->data['nb_images'] > $this->conf['max_elements']) 
     
    462462        $this->addImages($images_ids); 
    463463      } 
    464        
     464 
    465465      $this->getEstimatedArchiveNumber(true); 
    466        
     466 
    467467      $this->updateParam('date_creation', date('Y-m-d H:i:s')); 
    468        
     468 
    469469      trigger_action('batchdownload_init_zip', $this->data, array_keys($this->images)); // triggered once for all 
    470470    } 
    471      
     471 
    472472    // get next images of the set 
    473473    $images_to_add = array(); 
     
    475475    { 
    476476      if ($zip_id != 0) continue; // here are already added images 
    477       array_push($images_to_add, $image_id); 
    478     } 
    479      
     477      $images_to_add[] = $image_id; 
     478    } 
     479 
    480480    if (count($images_to_add)) 
    481481    { 
     
    489489;'; 
    490490      $images_to_add = hash_from_query($query, 'id'); 
    491        
     491 
    492492      if ($this->data['size'] != 'original') 
    493493      { 
     
    500500        $filesizes = hash_from_query($query, 'image_id'); 
    501501      } 
    502        
     502 
    503503      // open zip 
    504504      $this->updateParam('last_zip', $this->data['last_zip']+1); 
    505505      $zip_path = $this->getArchivePath(); 
    506506      $zip = new myZip($zip_path, $this->conf['force_pclzip']); 
    507        
     507 
    508508      // add images until size limit is reach, or all images are added 
    509509      $images_added = array(); 
     
    516516          continue; 
    517517        } 
    518          
     518 
    519519        if ($this->data['size'] == 'original') 
    520520        { 
     
    525525        { 
    526526          $src_image = new SrcImage($row); // don't give representive_ext 
    527            
     527 
    528528          // no-image files 
    529529          if ($src_image->is_mimetype()) 
     
    536536          { 
    537537            $derivative = new DerivativeImage($this->data['size'], $src_image); 
    538              
     538 
    539539            $zip->addFile($derivative->get_path(), $this->getFilename($row, $filesizes[ $row['id'] ])); 
    540540            $total_size+= $filesizes[ $row['id'] ]['filesize']; 
    541541          } 
    542542        } 
    543          
    544         array_push($images_added, $row['id']); 
     543 
     544        $images_added[] = $row['id']; 
    545545        $this->images[ $row['id'] ] = $this->data['last_zip']; 
    546          
     546 
    547547        if ($total_size >= $this->conf['max_size']*1024 and !$force_one_archive) break; 
    548548      } 
    549        
     549 
    550550      $this->updateParam('total_size', $this->data['total_size'] + $total_size); 
    551        
     551 
    552552      // archive comment 
    553553      $comment = 'Generated on '.date('r').' with PHP '.PHP_VERSION.' by Piwigo Batch Downloader.'; 
     
    558558      } 
    559559      $zip->setArchiveComment($comment); 
    560        
     560 
    561561      $zip->close(); 
    562        
     562 
    563563      // update database 
    564564      $query = ' 
     
    570570;'; 
    571571      pwg_query($query); 
    572        
     572 
    573573      trigger_action('batchdownload_end_zip', $this->data, $images_added); // triggered for each zip 
    574        
     574 
    575575      // all images added ? 
    576576      if (count($images_to_add) == count($images_added)) 
     
    578578        if ($this->conf['one_archive']) $this->updateParam('status', 'done'); 
    579579        $done = true; 
    580          
     580 
    581581        // over estimed 
    582582        $this->updateParam('nb_zip', $this->data['last_zip']); 
    583583      } 
    584        
     584 
    585585      // under estimed 
    586586      if (!isset($done) && $this->data['status'] != 'done' && $this->data['last_zip'] == $this->data['nb_zip']) 
     
    588588        $this->updateParam('nb_zip', $this->data['last_zip']+1); 
    589589      } 
    590        
     590 
    591591      return $zip_path; 
    592592    } 
     
    596596    } 
    597597  } 
    598    
     598 
    599599  /** 
    600600   * getEstimatedTotalSize 
     
    606606    if ($this->data['nb_images'] == 0) return 0; 
    607607    if ( !empty($this->data['estimated_total_size']) and !$force ) return $this->data['estimated_total_size']; 
    608      
     608 
    609609    $image_ids = array_slice(array_keys($this->images), 0, $this->conf['max_elements']); 
    610      
     610 
    611611    if ($this->data['size'] == 'original') 
    612612    { 
     
    625625;'; 
    626626    } 
    627      
     627 
    628628    list($this->data['estimated_total_size']) = pwg_db_fetch_row(pwg_query($query)); 
    629629    return $this->data['estimated_total_size']; 
    630630  } 
    631    
     631 
    632632  /** 
    633633   * getEstimatedArchiveNumber 
     
    638638    if ($this->data['status'] == 'done') return $this->data['nb_zip']; 
    639639    if ( !empty($this->data['nb_zip']) and !$force ) return $this->data['nb_zip']; 
    640      
     640 
    641641    $this->updateParam('nb_zip', ceil( $this->getEstimatedTotalSize($force) / ($this->conf['max_size']*1024) )); 
    642642    return $this->data['nb_zip']; 
    643643  } 
    644    
     644 
    645645  /** 
    646646   * getDownloadList 
     
    653653      return '<b>'.l10n('No archive').'</b>'; 
    654654    } 
    655      
     655 
    656656    $root_url = get_root_url(); 
    657      
     657 
    658658    $out = ''; 
    659659    for ($i=1; $i<=$this->getEstimatedArchiveNumber(); $i++) 
    660660    { 
    661661      $out.= '<li id="zip-'.$i.'">'; 
    662        
     662 
    663663      if ($this->data['status']=='done' or ($this->conf['one_archive'] and $i<$this->data['last_zip']+1)) 
    664664      { 
    665         $out.= '<img src="'.$root_url.BATCH_DOWNLOAD_PATH.'template/images/drive_error.png"> '.sprintf(l10n('Archive #%d (already downloaded)'), $i); 
     665        $out.= '<img src="'.$root_url.BATCH_DOWNLOAD_PATH.'template/images/drive_error.png"> '.l10n('Archive #%d (already downloaded)', $i); 
    666666      } 
    667667      else if ($i==$this->data['last_zip']+1 or (!$this->conf['one_archive'] and $i<$this->data['last_zip']+1)) 
    668668      { 
    669           $out.= '<a href="'.add_url_params($url, array('set_id'=>$this->data['id'],'zip'=>$i)).'" rel="nofollow" style="font-weight:bold;"'  
    670             .(($i!=1 and $this->conf['one_archive']) ? ' 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). 
    671             '><img src="'.$root_url.BATCH_DOWNLOAD_PATH.'template/images/drive_go.png"> '.sprintf(l10n('Archive #%d (ready)'), $i).'</a>'; 
     669          $out.= '<a href="'.add_url_params($url, array('set_id'=>$this->data['id'],'zip'=>$i)).'" rel="nofollow" style="font-weight:bold;"' 
     670            .(($i!=1 and $this->conf['one_archive']) ? ' onClick="return confirm(\''.addslashes(l10n('Starting download Archive #%d will destroy Archive #%d, be sure you finish the download. Continue ?', $i, $i-1)).'\');"' : null). 
     671            '><img src="'.$root_url.BATCH_DOWNLOAD_PATH.'template/images/drive_go.png"> '.l10n('Archive #%d (ready)', $i).'</a>'; 
    672672      } 
    673673      else 
    674674      { 
    675         $out.= '<img src="'.$root_url.BATCH_DOWNLOAD_PATH.'template/images/drive.png"> '.sprintf(l10n('Archive #%d (pending)'), $i); 
    676       } 
    677        
     675        $out.= '<img src="'.$root_url.BATCH_DOWNLOAD_PATH.'template/images/drive.png"> '.l10n('Archive #%d (pending)', $i); 
     676      } 
     677 
    678678      $out.= '</li>'; 
    679679    } 
    680      
     680 
    681681    return $out; 
    682682  } 
    683    
     683 
    684684  /** 
    685685   * getArchivePath 
     
    693693      mkgetdir(BATCH_DOWNLOAD_LOCAL . 'u-' .$this->data['user_id']. '/'); 
    694694    } 
    695      
     695 
    696696    if ($i === null) $i = $this->data['last_zip']; 
    697697    $set = $this->getNames(); 
    698      
     698 
    699699    $path = BATCH_DOWNLOAD_LOCAL . 'u-'. $this->data['user_id'] . '/'; 
    700700    $path.= !empty($this->conf['archive_prefix']) ? $this->conf['archive_prefix'] . '_' : null; 
     
    702702    $path.= $this->data['user_id'] . $this->data['id']; 
    703703    $path.= '_part' . $i . '.zip'; 
    704      
     704 
    705705    return $path; 
    706706  } 
    707    
     707 
    708708  /** 
    709709   * getNames 
    710    * @return: array  
     710   * @return: array 
    711711   *    NAME, set name with HTML 
    712712   *    sNAME, set name without HTML 
     
    715715   */ 
    716716  function getNames() 
    717   {     
     717  { 
    718718    switch ($this->data['type']) 
    719719    { 
     
    723723        global $conf, $page; 
    724724        $old_page = $page; 
    725          
     725 
    726726        $fields = array( 
    727727          'created' => l10n('Creation date'), 
    728728          'posted' => l10n('Post date'), 
    729729          ); 
    730          
     730 
    731731        $chronology = explode('-', $this->data['type_id']); 
    732732        $page['chronology_field'] = $chronology[0]; 
     
    734734        $page['chronology_view'] = $chronology[2]; 
    735735        $page['chronology_date'] = array_splice($chronology, 3); 
    736          
     736 
    737737        if (!class_exists('Calendar')) 
    738738        { 
     
    742742        $calendar->initialize(''); 
    743743        $display_name = strip_tags($calendar->get_display_name()); 
    744          
     744 
    745745        $set['NAME'] = l10n('Calendar').': '.$fields[$page['chronology_field']].$display_name; 
    746746        $set['sNAME'] = l10n('Calendar').': '.ltrim($display_name, $conf['level_separator']); 
    747747        $set['BASENAME'] = 'calendar-'.$page['chronology_field'].'-'.implode('-',$page['chronology_date']); 
    748          
     748 
    749749        $page = $old_page; 
    750750        break; 
    751751      } 
    752        
     752 
    753753      // category 
    754754      case 'category': 
     
    765765          $set['sNAME'] = l10n('Album').': '.trigger_event('render_category_name', $category['name']); 
    766766          $set['COMMENT'] = trigger_event('render_category_description', $category['comment']); 
    767            
     767 
    768768          if (!empty($category['permalink'])) 
    769769          { 
     
    781781        break; 
    782782      } 
    783        
     783 
    784784      // flat 
    785785      case 'flat': 
     
    789789        break; 
    790790      } 
    791        
     791 
    792792      // tags 
    793793      case 'tags': 
     
    796796        $set['NAME'] = l10n('Tags').': '; 
    797797        $set['BASENAME'] = 'tags'; 
    798          
     798 
    799799        $first = true; 
    800800        foreach ($tags as $tag) 
     
    810810        break; 
    811811      } 
    812        
     812 
    813813      // search 
    814814      case 'search': 
     
    818818        break; 
    819819      } 
    820        
     820 
    821821      // favorites 
    822822      case 'favorites': 
     
    826826        break; 
    827827      } 
    828        
     828 
    829829      // most_visited 
    830830      case 'most_visited': 
     
    834834        break; 
    835835      } 
    836        
     836 
    837837      // best_rated 
    838838      case 'best_rated': 
     
    842842        break; 
    843843      } 
    844        
     844 
    845845      // list 
    846846      case 'list': 
     
    850850        break; 
    851851      } 
    852        
     852 
    853853      // recent_pics 
    854854      case 'recent_pics': 
     
    858858        break; 
    859859      } 
    860        
     860 
    861861      // collection 
    862862      case 'collection': 
     
    868868          $infos = $UserCollection->getCollectionInfo(); 
    869869          $set['NAME'] = l10n('Collection').': <a href="'.$infos['U_PUBLIC'].'">'.$UserCollection->getParam('name').'</a>'; 
    870            
     870 
    871871          if ( ($name = str2url($UserCollection->getParam('name'))) != null) 
    872872          { 
     
    886886      } 
    887887    } 
    888      
     888 
    889889    if (!isset($set['sNAME']))    $set['sNAME'] = strip_tags($set['NAME']); 
    890890    if (!isset($set['COMMENT']))  $set['COMMENT'] = null; 
    891891    if (!isset($set['BASENAME'])) $set['BASENAME'] = $this->data['type'] . $this->data['type_id']; 
    892      
     892 
    893893    return $set; 
    894894  } 
    895    
     895 
    896896  /** 
    897897   * getSetInfo 
     
    899899   */ 
    900900  function getSetInfo() 
    901   {     
     901  { 
    902902    $set = array( 
    903903      'NB_IMAGES' =>     $this->data['nb_images'], 
     
    905905      'STATUS' =>        $this->data['status']=='ready' ? 'new' : $this->data['status'], 
    906906      'LAST_ZIP' =>      $this->data['last_zip'], 
    907       'TOTAL_SIZE' =>    $this->data['status']=='new' ? l10n('Unknown') : sprintf(l10n('%d MB'), ceil($this->getEstimatedTotalSize()/1024)), 
     907      'TOTAL_SIZE' =>    $this->data['status']=='new' ? l10n('Unknown') : l10n('%d MB', ceil($this->getEstimatedTotalSize()/1024)), 
    908908      'DATE_CREATION' => format_date($this->data['date_creation'], true), 
    909909      'SIZE' =>          $this->data['size'], 
    910910      ); 
    911        
     911 
    912912    if ($this->data['size'] != 'original') 
    913913    { 
     
    915915      $set['SIZE_INFO'] = $params->sizing->ideal_size[0].' x '.$params->sizing->ideal_size[1]; 
    916916    } 
    917      
     917 
    918918    return array_merge($set, $this->getNames()); 
    919919  } 
    920    
     920 
    921921  /** 
    922922   * delete 
     
    939939  private $lib; 
    940940  private $zip; 
    941    
     941 
    942942  function __construct($zip_path, $pclzip=false) 
    943943  { 
     
    945945    { 
    946946      $this->lib = 'zipa'; 
    947        
     947 
    948948      $this->zip = new ZipArchive; 
    949949      if ($this->zip->open($zip_path, ZipArchive::CREATE) !== true) 
     
    955955    { 
    956956      $this->lib = 'pcl'; 
    957        
     957 
    958958      require_once(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php'); 
    959959      $this->zip = new PclZip($zip_path); 
    960        
     960 
    961961      // create a temporary file for archive creation 
    962962      touch(BATCH_DOWNLOAD_LOCAL.'temp.txt'); 
    963        
     963 
    964964      if ($this->zip->create(BATCH_DOWNLOAD_LOCAL.'temp.txt', PCLZIP_OPT_REMOVE_ALL_PATH) == 0) 
    965965      { 
    966966        trigger_error('BatchDownloader::createNextArchive, unable to open ZIP archive (PclZip)', E_USER_ERROR); 
    967967      } 
    968        
     968 
    969969      unlink(BATCH_DOWNLOAD_LOCAL.'temp.txt'); 
    970970      $this->zip->delete(PCLZIP_OPT_BY_NAME, 'temp.txt'); 
    971971    } 
    972972  } 
    973    
     973 
    974974  function addFile($path, $filename) 
    975975  { 
     
    983983    } 
    984984  } 
    985    
     985 
    986986  function setArchiveComment($comment) 
    987987  { 
     
    991991    } 
    992992  } 
    993    
     993 
    994994  function close() 
    995995  { 
     
    10001000  } 
    10011001} 
    1002  
    1003 ?> 
  • extensions/BatchDownloader/include/download.inc.php

    r23383 r25932  
    11<?php 
    22defined('BATCH_DOWNLOAD_PATH') or die('Hacking attempt!'); 
    3  
    4 # this file is called on public page # 
    53 
    64global $page, $template, $conf, $user; 
     
    119  case 'init_zip': 
    1210  { 
    13     $template->set_filename('index', realpath(BATCH_DOWNLOAD_PATH . 'template/init_zip.tpl')); 
    14      
     11    $template->set_filename('batchdwn', realpath(BATCH_DOWNLOAD_PATH . 'template/init_zip.tpl')); 
     12 
    1513    try 
    1614    { 
    1715      $BatchDownloader = new BatchDownloader($_GET['set_id']); 
    18        
     16 
    1917      // delete set 
    2018      if ( isset($_GET['cancel']) ) 
     
    2624        redirect(get_absolute_root_url()); 
    2725      } 
    28        
     26 
    2927      // prepare next zip 
    3028      if ( isset($_GET['zip']) and $BatchDownloader->getParam('status') != 'new' and $BatchDownloader->getParam('status') != 'done' ) 
     
    3533          $BatchDownloader->createNextArchive(); 
    3634        } 
    37          
     35 
    3836        if ($conf['batch_download']['one_archive']) 
    3937        { 
     
    4543        } 
    4644      } 
    47        
     45 
    4846      // alert limit overflow 
    4947      if ($BatchDownloader->getParam('nb_images') > $conf['batch_download']['max_elements']) 
    5048      { 
    51         $template->assign('elements_error', sprintf( 
    52           l10n('You choose to download %d pictures, but the system is limited to %d. You can edit the set, or the last %d pictures will not be downloaded.'), 
     49        $template->assign('elements_error', l10n( 
     50          'You choose to download %d pictures, but the system is limited to %d. You can edit the set, or the last %d pictures will not be downloaded.', 
    5351          $BatchDownloader->getParam('nb_images'), 
    5452          $conf['batch_download']['max_elements'], 
     
    6159        { 
    6260          $missing_derivatives = $BatchDownloader->getMissingDerivatives(true); 
    63          
     61 
    6462          // generate missing files 
    6563          if (count($missing_derivatives)) 
     
    7371          } 
    7472        } 
    75          
     73 
    7674        // display download links 
    7775        if ($BatchDownloader->getParam('status') != 'new') 
     
    8078        } 
    8179      } 
    82        
     80 
    8381      $set = $BatchDownloader->getSetInfo(); 
    84        
     82 
    8583      // link to the zip 
    8684      if (isset($next_file)) 
    8785      { 
    8886        $set['U_DOWNLOAD'] = get_root_url().BATCH_DOWNLOAD_PATH . 'download.php?set_id='.$_GET['set_id'].'&zip='.$_GET['zip']; 
    89         $page['infos'][] = sprintf(l10n('The archive is downloading, if the download doesn\'t start automatically please <a href="%s">click here</a>'), $set['U_DOWNLOAD']); 
     87        $page['infos'][] = l10n('The archive is downloading, if the download doesn\'t start automatically please <a href="%s">click here</a>', $set['U_DOWNLOAD']); 
    9088      } 
    91        
     89 
    9290      // link to edit page 
    9391      if ($BatchDownloader->getParam('status') != 'download' and $BatchDownloader->getParam('status') != 'done' and $BatchDownloader->getParam('nb_images') > 0) 
     
    9593        $set['U_EDIT_SET'] = add_url_params(BATCH_DOWNLOAD_PUBLIC . 'view', array('set_id'=>$_GET['set_id'])); 
    9694      } 
    97        
     95 
    9896      // cancel link 
    99       if ($BatchDownloader->getParam('last_zip') != $BatchDownloader->getParam('nb_zip')) 
     97      if ($BatchDownloader->getParam('last_zip') != $BatchDownloader->getParam('nb_zip') 
     98        or (isset($missing_derivatives) and count($missing_derivatives)) 
     99        ) 
    100100      { 
    101101        $set['U_CANCEL'] = add_url_params(BATCH_DOWNLOAD_PUBLIC . 'init_zip', array('set_id'=>$_GET['set_id'], 'cancel'=>'true')); 
    102102      } 
    103        
     103 
    104104      $template->assign(array( 
    105105        'set' => $set, 
     
    109109    catch (Exception $e) 
    110110    { 
    111       array_push($page['errors'], $e->getMessage()); 
     111      $page['errors'][] = $e->getMessage(); 
    112112    } 
    113      
     113 
    114114    break; 
    115115  } 
    116    
     116 
    117117  /* edition page */ 
    118118  case 'view': 
    119119  { 
    120120    $self_url = add_url_params(BATCH_DOWNLOAD_PUBLIC . 'view', array('set_id'=>$_GET['set_id'])); 
    121      
    122     $template->set_filename('index', realpath(BATCH_DOWNLOAD_PATH . 'template/view.tpl')); 
     121 
     122    $template->set_filename('batchdwn', realpath(BATCH_DOWNLOAD_PATH . 'template/view.tpl')); 
    123123    $template->assign(array( 
    124124      'BATCH_DOWNLOAD_PATH' => BATCH_DOWNLOAD_PATH, 
     
    127127      'SET_ID' => $_GET['set_id'], 
    128128      )); 
    129      
     129 
    130130    try 
    131131    { 
    132132      $BatchDownloader = new BatchDownloader($_GET['set_id']); 
    133        
     133 
    134134      if ($BatchDownloader->getParam('status') != 'new' && $BatchDownloader->getParam('status') != 'ready') 
    135135      { 
    136         array_push($page['errors'], l10n('You can not edit this set')); 
     136        $page['errors'][] = l10n('You can not edit this set'); 
    137137        break; 
    138138      } 
    139        
     139 
    140140      if ( isset($_GET['remove']) and preg_match('#^[0-9]+$#', $_GET['remove']) ) 
    141141      { 
    142142        $BatchDownloader->removeImages(array($_GET['remove'])); 
    143143      } 
    144        
     144 
    145145      $template->assign('set', $BatchDownloader->getSetInfo()); 
    146        
     146 
    147147      $template->set_prefilter('index_thumbnails', 'batch_download_thumbnails_list_prefilter'); 
    148        
     148 
    149149      $page['start'] = isset($_GET['start']) ? $_GET['start'] : 0; 
    150150      $page['items'] = array_keys($BatchDownloader->getImages()); 
    151        
     151 
    152152      if (count($page['items']) > $page['nb_image_page']) 
    153153      { 
     
    161161        $template->assign('navbar', $page['navigation_bar']); 
    162162      } 
    163        
     163 
    164164      include(PHPWG_ROOT_PATH . 'include/category_default.inc.php'); 
    165165    } 
    166166    catch (Exception $e) 
    167167    { 
    168       array_push($page['errors'], $e->getMessage()); 
     168      $page['errors'][] = $e->getMessage(); 
    169169    } 
    170      
     170 
    171171    break; 
    172172  } 
     
    178178  )); 
    179179 
     180$template->assign_var_from_handle('CONTENT', 'batchdwn'); 
     181 
    180182 
    181183function batch_download_thumbnails_list_prefilter($content, &$smarty) 
     
    185187  $replace = '$1 
    186188{strip}<a class="removeSet" href="{$U_VIEW}&amp;remove={$thumbnail.id}" data-id="{$thumbnail.id}" rel="nofollow"> 
    187 {\'Remove from download set\'|@translate}&nbsp;<img src="{$ROOT_URL}{$BATCH_DOWNLOAD_PATH}template/images/image_delete.png" title="{\'Remove from download set\'|@translate}"> 
     189{\'Remove from download set\'|translate}&nbsp;<img src="{$ROOT_URL}{$BATCH_DOWNLOAD_PATH}template/images/image_delete.png" title="{\'Remove from download set\'|translate}"> 
    188190</a>{/strip}'; 
    189191 
     
    193195  return preg_replace($search, $replace, $content); 
    194196} 
    195  
    196 ?> 
  • extensions/BatchDownloader/include/events.inc.php

    r25931 r25932  
    22defined('BATCH_DOWNLOAD_PATH') or die('Hacking attempt!'); 
    33 
    4 # this file contains all functions directly called by the triggers # 
    5  
    64/* define page section from url */ 
    75function batch_download_section_init() 
    86{ 
    97  global $tokens, $page, $conf; 
    10    
     8 
    119  if ($tokens[0] == 'download') 
    1210  { 
    1311    if (check_download_access() === false) access_denied(); 
    14      
    15     add_event_handler('loc_begin_page_header', 'batch_download_page_header'); 
    16      
     12 
     13    $page['body_id'] = 'theBatchDownloader'; 
     14    $page['is_external'] = true; 
     15    $page['is_homepage'] = false; 
    1716    $page['section'] = 'download'; 
     17 
    1818    $page['section_title'] = '<a href="'.get_absolute_root_url().'">'.l10n('Home').'</a>'.$conf['level_separator'].l10n('Batch Downloader').$conf['level_separator']; 
    1919    $page['title'] = l10n('Batch Downloader'); 
    20      
     20 
    2121    switch (@$tokens[1]) 
    2222    { 
     
    3939} 
    4040 
    41 function batch_download_page_header() 
    42 { 
    43   global $page; 
    44   $page['body_id'] = 'theBatchDownloader'; 
    45 } 
    46  
    4741/* download section */ 
    48 function batch_download_page()  
     42function batch_download_page() 
    4943{ 
    5044  global $page; 
     
    6155{ 
    6256  global $page, $template, $user, $conf; 
    63    
     57 
    6458  // check accesses 
    6559  if ( !count($page['items']) or !isset($page['section']) ) return; 
    66    
     60 
    6761  if (check_download_access() === false) return; 
    68    
     62 
    6963  switch ($page['section']) 
    7064  { 
    7165  case 'categories': 
    7266    if (!isset($page['category']) && !isset($page['chronology_field'])) return; // don't download the full gallery in flat mode ! 
    73      
     67 
    7468    if (!in_array('categories', $conf['batch_download']['what'])) return; 
    7569    break; 
    76      
     70 
    7771  case 'collections': 
    7872    if (!in_array('collections', $conf['batch_download']['what'])) return; 
    7973    break; 
    80      
     74 
    8175  default: 
    8276    if (!in_array('specials', $conf['batch_download']['what'])) return; 
    8377  } 
    84    
    85    
     78 
     79 
    8680  // download the set 
    8781  if ( isset($_GET['action']) and $_GET['action']=='advdown_set' ) 
    8882  { 
    8983    $set = get_set_info_from_page(); 
    90      
     84 
    9185    if ($set !== false && count($set['items'])) 
    9286    { 
    9387      $BatchDownloader = new BatchDownloader('new', $set['items'], $set['type'], $set['id'], $set['size']); 
    94        
     88 
    9589      if ($BatchDownloader->getParam('nb_images') != 0) 
    9690      { 
     
    10397        { 
    10498          $BatchDownloader->createNextArchive(true); // make sure we have only one zip, even if 'max_size' is exceeded 
    105            
     99 
    106100          $u_download = get_root_url().BATCH_DOWNLOAD_PATH . 'download.php?set_id='.$BatchDownloader->getParam('id').'&zip=1'; 
    107            
     101 
    108102          $null = null; 
    109103          $template->block_footer_script(null, 'setTimeout("document.location.href = \''.$u_download.'\';", 1000);', $null, $null); 
    110            
    111           $page['infos'][] = sprintf(l10n('The archive is downloading, if the download doesn\'t start automatically please <a href="%s">click here</a>'), $u_download); 
     104 
     105          $page['infos'][] = l10n('The archive is downloading, if the download doesn\'t start automatically please <a href="%s">click here</a>', $u_download); 
    112106        } 
    113107        // otherwise we go to summary page 
     
    121115        $BatchDownloader->delete(); 
    122116        unset($BatchDownloader); 
    123          
    124         $page['errors'][] = sprintf(l10n('Sorry, there is nothing to download. Some files may have been excluded because of <i title="Authorized types are : %s">filetype restrictions</i>.'), implode(', ', $conf['batch_download']['allowed_ext'])); 
     117 
     118        $page['errors'][] = l10n('Sorry, there is nothing to download. Some files may have been excluded because of <i title="Authorized types are : %s">filetype restrictions</i>.', implode(', ', $conf['batch_download']['allowed_ext'])); 
    125119      } 
    126120    } 
    127121  } 
    128    
     122 
    129123  if ($page['section'] == 'collections') 
    130124  { 
     
    135129    $url = duplicate_index_url(array(), array('action')); 
    136130  } 
    137    
     131 
    138132  $url = add_url_params($url, array('action'=>'advdown_set', 'down_size'=>'')); 
    139    
     133 
    140134  // toolbar button 
    141135  $template->assign(array( 
     
    144138    'BATCH_DWN_URL' => $url, 
    145139    )); 
    146    
     140 
    147141  if ($conf['batch_download']['multisize']) 
    148142  { 
     
    175169    $template->assign('BATCH_DWN_SIZE', $conf['batch_download']['photo_size']); 
    176170  } 
    177      
     171 
    178172  $template->set_filename('batchdwn_button', realpath(BATCH_DOWNLOAD_PATH.'template/download_button.tpl')); 
    179173  $button = $template->parse('batchdwn_button', true); 
     
    187181{ 
    188182  global $user; 
    189    
     183 
    190184  $menu = &$menu_ref_arr[0]; 
    191185  if ($menu->get_id() != 'menubar') return; 
    192    
     186 
    193187  if (check_download_access() === false) return; 
    194    
     188 
    195189  $query = ' 
    196190SELECT id 
     
    203197  $result = pwg_query($query); 
    204198  if (!pwg_db_num_rows($result)) return; 
    205    
     199 
    206200  $menu->register_block(new RegisteredBlock('mbBatchDownloader', l10n('Batch Downloader'), 'BatchDownloader')); 
    207201} 
     
    210204{ 
    211205  global $template, $conf, $user; 
    212    
     206 
    213207  $menu = &$menu_ref_arr[0]; 
    214208  $block = $menu->get_block('mbBatchDownloader'); 
    215    
     209 
    216210  if ($block != null) 
    217211  { 
    218212    $query = ' 
    219 SELECT id  
     213SELECT id 
    220214  FROM '.BATCH_DOWNLOAD_TSETS.' 
    221215  WHERE 
     
    224218;'; 
    225219    $sets = array_from_query($query, 'id'); 
    226      
     220 
    227221    $data = array(); 
    228222    foreach ($sets as $set_id) 
     
    230224      $BatchDownloader = new BatchDownloader($set_id); 
    231225      $set = $BatchDownloader->getSetInfo(); 
    232        
    233       array_push($data, array( 
     226 
     227      $data[] = array( 
    234228        'URL' => add_url_params(BATCH_DOWNLOAD_PUBLIC . 'init_zip', array('set_id'=>$BatchDownloader->getParam('id'))), 
    235229        'TITLE' => str_replace('"', "'", strip_tags($set['COMMENT'])), 
    236230        'NAME' => $set['sNAME'], 
    237231        'COUNT' => $set['NB_IMAGES'], 
    238         )); 
    239     } 
    240      
     232        ); 
     233    } 
     234 
    241235    $template->set_template_dir(BATCH_DOWNLOAD_PATH . 'template/'); 
    242236    $block->set_title(l10n('Downloads')); 
     
    251245{ 
    252246  global $conf; 
    253    
     247 
    254248  $time = time(); 
    255    
     249 
    256250  // we only search for old downloads every hour, nevermind which user is connected 
    257251  if ($conf['batch_download']['last_clean'] > $time - 3600) return; 
    258    
     252 
    259253  $conf['batch_download']['last_clean'] = $time; 
    260254  conf_update_param('batch_download', serialize($conf['batch_download'])); 
    261    
     255 
    262256  // set old sets as done and clean images table 
    263257  $query = ' 
     
    271265;'; 
    272266  pwg_query($query); 
    273    
     267 
    274268  $query = ' 
    275269UPDATE '.BATCH_DOWNLOAD_TSETS.' 
    276270  SET status = "done" 
    277   WHERE  
     271  WHERE 
    278272    status != "done" AND 
    279273    date_creation < DATE_SUB(NOW(), INTERVAL '.$conf['batch_download']['archive_timeout'].' HOUR) 
    280274;'; 
    281275  pwg_query($query); 
    282    
     276 
    283277  // remove old archives 
    284278  $zips = glob(BATCH_DOWNLOAD_LOCAL . 'u-*/*.zip'); 
    285    
     279 
    286280  if (is_array($zips)) 
    287281  { 
     
    300294{ 
    301295  if (!isset($_POST['action']) || $_POST['action']!='bd_remove_image') return; 
    302    
     296 
    303297  check_status(ACCESS_CLASSIC); 
    304298 
     
    320314    echo 'error'; 
    321315  } 
    322    
     316 
    323317  exit(0); 
    324318} 
    325  
    326 ?> 
  • extensions/BatchDownloader/include/functions.inc.php

    r25931 r25932  
    99{ 
    1010  global $page, $conf; 
    11    
     11 
    1212  switch ($page['section']) 
    1313  { 
     
    1616      { 
    1717        $batch_type = 'calendar'; 
    18         $batch_id = add_well_known_params_in_url('',  
    19           array_intersect_key($page,  
     18        $batch_id = add_well_known_params_in_url('', 
     19          array_intersect_key($page, 
    2020            array( 
    2121              'chronology_field'=>0, 
     
    6262      return false; 
    6363  } 
    64    
     64 
    6565  $set = array( 
    6666    'type' => $batch_type, 
     
    6969    'items' => $page['items'], 
    7070    ); 
    71      
     71 
    7272  // check size 
    7373  if (!$conf['batch_download']['multisize']) 
     
    8787      $avail_sizes[] = 'original'; 
    8888    } 
    89      
     89 
    9090    if (!in_array($set['size'], $avail_sizes)) 
    9191    { 
     
    104104{ 
    105105  global $user, $conf; 
    106    
     106 
    107107  if (is_a_guest()) return false; 
    108108  if (is_admin()) return true; 
    109    
     109 
    110110  if ($user['level'] < $conf['batch_download']['level']) return false; 
    111    
     111 
    112112  if (!empty($conf['batch_download']['groups'])) 
    113113  { 
     
    119119;'; 
    120120    $result = pwg_query($query); 
    121      
     121 
    122122    if (!pwg_db_num_rows($result)) return false; 
    123123  } 
    124    
     124 
    125125  return true; 
    126126} 
     
    167167  } 
    168168} 
    169  
    170 ?> 
  • extensions/BatchDownloader/main.inc.php

    r23589 r25932  
    1 <?php  
     1<?php 
    22/* 
    33Plugin Name: Batch Downloader 
     
    3333{ 
    3434  add_event_handler('init', 'batch_downloader_remove_image'); 
    35    
     35 
    3636  add_event_handler('loc_end_section_init', 'batch_download_section_init'); 
    3737  add_event_handler('loc_end_index', 'batch_download_page'); 
     
    4040 
    4141  add_event_handler('loc_end_index', 'batch_download_index_button', EVENT_HANDLER_PRIORITY_NEUTRAL+10); 
     42} 
    4243 
    43   add_event_handler('blockmanager_register_blocks', 'batch_download_add_menublock'); 
    44   add_event_handler('blockmanager_apply', 'batch_download_applymenu'); 
    45 } 
     44add_event_handler('blockmanager_register_blocks', 'batch_download_add_menublock'); 
     45add_event_handler('blockmanager_apply', 'batch_download_applymenu'); 
    4646 
    4747 
     
    5757function batch_download_init() 
    5858{ 
    59   global $conf, $pwg_loaded_plugins; 
    60    
    61   if ( 
    62     BATCH_DOWNLOAD_VERSION == 'auto' or 
    63     $pwg_loaded_plugins[BATCH_DOWNLOAD_ID]['version'] == 'auto' or 
    64     version_compare($pwg_loaded_plugins[BATCH_DOWNLOAD_ID]['version'], BATCH_DOWNLOAD_VERSION, '<') 
    65   ) 
    66   { 
    67     include_once(BATCH_DOWNLOAD_PATH . 'include/install.inc.php'); 
    68     batch_download_install(); 
    69      
    70     if ( $pwg_loaded_plugins[BATCH_DOWNLOAD_ID]['version'] != 'auto' and BATCH_DOWNLOAD_VERSION != 'auto' ) 
    71     { 
    72       $query = ' 
    73 UPDATE '. PLUGINS_TABLE .' 
    74 SET version = "'. BATCH_DOWNLOAD_VERSION .'" 
    75 WHERE id = "'. BATCH_DOWNLOAD_ID .'"'; 
    76       pwg_query($query); 
    77        
    78       $pwg_loaded_plugins[BATCH_DOWNLOAD_ID]['version'] = BATCH_DOWNLOAD_VERSION; 
    79        
    80       if (defined('IN_ADMIN')) 
    81       { 
    82         $_SESSION['page_infos'][] = 'BatchDownloader updated to version '. BATCH_DOWNLOAD_VERSION; 
    83       } 
    84     } 
    85   } 
    86    
     59  global $conf; 
     60 
     61  include_once(BATCH_DOWNLOAD_PATH . 'maintain.inc.php'); 
     62  $maintain = new BatchDownloader_maintain(BATCH_DOWNLOAD_ID); 
     63  $maintain->autoUpdate(BATCH_DOWNLOAD_VERSION, 'install'); 
     64 
    8765  $conf['batch_download'] = unserialize($conf['batch_download']); 
    8866  $conf['batch_download']['file_pattern'] = isset($conf['batch_download_file_pattern']) ? $conf['batch_download_file_pattern'] : '%id%_%filename%_%dimensions%'; 
     
    9270    $conf['batch_download']['allowed_ext'] = array_merge($conf['batch_download']['allowed_ext'], $conf['batch_download_additional_ext']); 
    9371  } 
    94    
     72 
    9573  load_language('plugin.lang', BATCH_DOWNLOAD_PATH); 
    9674} 
     
    9977 * admin plugins menu 
    10078 */ 
    101 function batch_download_admin_menu($menu)  
     79function batch_download_admin_menu($menu) 
    10280{ 
    103   array_push($menu, array( 
     81  $menu[] = array( 
    10482    'NAME' => 'Batch Downloader', 
    10583    'URL' => BATCH_DOWNLOAD_ADMIN, 
    106   )); 
     84  ); 
    10785  return $menu; 
    10886} 
    109  
    110 ?> 
  • extensions/BatchDownloader/maintain.inc.php

    r19837 r25932  
    22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 
    33 
    4 defined('BATCH_DOWNLOAD_ID') or define('BATCH_DOWNLOAD_ID', basename(dirname(__FILE__))); 
    5 include_once(PHPWG_PLUGINS_PATH . BATCH_DOWNLOAD_ID . '/include/install.inc.php'); 
     4class BatchDownloader_maintain extends PluginMaintain 
     5{ 
     6  private $installed = false; 
    67 
    7 function plugin_install()  
    8 { 
    9   batch_download_install(); 
    10    
    11   define('batch_download_installed', true); 
    12 } 
     8  function install($plugin_version, &$errors=array()) 
     9  { 
     10    global $conf, $prefixeTable; 
    1311 
    14 function plugin_activate() 
    15 { 
    16   if (!defined('batch_download_installed')) 
     12    // configuration 
     13    if (empty($conf['batch_download'])) 
     14    { 
     15      $batch_download_default_config = array( 
     16        'groups'          => array(), 
     17        'level'           => 0, 
     18        'what'            => array('categories','specials','collections'), 
     19        'photo_size'      => 'original', 
     20        'multisize'       => true, 
     21        'archive_prefix'  => 'piwigo', 
     22        'archive_timeout' => 48, /* hours */ 
     23        'max_elements'    => 500, 
     24        'max_size'        => 100, /* MB */ 
     25        'last_clean'      => time(), 
     26        'one_archive'     => false, 
     27        'force_pclzip'    => false, 
     28        'direct'          => false, 
     29        ); 
     30 
     31      $conf['batch_download'] = serialize($batch_download_default_config); 
     32      $conf['batch_download_comment'] = null; 
     33 
     34      conf_update_param('batch_download', $conf['batch_download']); 
     35      conf_update_param('batch_download_comment', $conf['batch_download_comment']); 
     36    } 
     37    else 
     38    { 
     39      $new_conf = is_string($conf['batch_download']) ? unserialize($conf['batch_download']) : $conf['batch_download']; 
     40 
     41      if (!isset($new_conf['what'])) 
     42      { 
     43        $new_conf['what'] = array('categories','specials','collections'); 
     44      } 
     45      if (!isset($new_conf['one_archive'])) 
     46      { 
     47        $new_conf['one_archive'] = false; 
     48        $new_conf['force_pclzip'] = isset($conf['batch_download_force_pclzip']) && $conf['batch_download_force_pclzip']; 
     49        $new_conf['direct'] = isset($conf['batch_download_direct']) && $conf['batch_download_direct']; 
     50      } 
     51      if (!isset($new_conf['multisize'])) 
     52      { 
     53        $new_conf['multisize'] = true; 
     54      } 
     55 
     56      $conf['batch_download'] = serialize($new_conf); 
     57      conf_update_param('batch_download', $conf['batch_download']); 
     58    } 
     59 
     60    // archives directory 
     61    if (!file_exists(PHPWG_ROOT_PATH . $conf['data_location'] . 'download_archives/')) 
     62    { 
     63      mkgetdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'download_archives/', MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR); 
     64    } 
     65 
     66    // create tables 
     67    $query = ' 
     68CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'download_sets` ( 
     69  `id` mediumint(8) NOT NULL AUTO_INCREMENT, 
     70  `user_id` smallint(5) NOT NULL, 
     71  `date_creation` datetime NOT NULL, 
     72  `type` varchar(16) NOT NULL, 
     73  `type_id` varchar(64) NOT NULL, 
     74  `size` varchar(16) NOT NULL DEFAULT "original", 
     75  `nb_zip` smallint(3) NOT NULL DEFAULT 0, 
     76  `last_zip` smallint(3) NOT NULL DEFAULT 0, 
     77  `nb_images` mediumint(8) NOT NULL DEFAULT 0, 
     78  `total_size` int(10) NOT NULL DEFAULT 0, 
     79  `status` enum("new","ready","download","done") NOT NULL DEFAULT "new", 
     80  PRIMARY KEY (`id`) 
     81) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 
     82;'; 
     83    pwg_query($query); 
     84 
     85    $query = ' 
     86CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'download_sets_images` ( 
     87  `set_id` mediumint(8) NOT NULL, 
     88  `image_id` mediumint(8) NOT NULL, 
     89  `zip` smallint(5) NOT NULL DEFAULT 0, 
     90  UNIQUE KEY `UNIQUE` (`set_id`,`image_id`) 
     91) ENGINE=MyISAM DEFAULT CHARSET=utf8 
     92;'; 
     93    pwg_query($query); 
     94 
     95    $query = ' 
     96CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'image_sizes` ( 
     97  `image_id` mediumint(8) NOT NULL, 
     98  `type` varchar(16) NOT NULL, 
     99  `width` smallint(9) NOT NULL, 
     100  `height` smallint(9) NOT NULL, 
     101  `filesize` mediumint(9) NOT NULL, 
     102  `filemtime` int(16) NOT NULL, 
     103  PRIMARY KEY (`image_id`) 
     104) ENGINE=MyISAM DEFAULT CHARSET=utf8 
     105;'; 
     106    pwg_query($query); 
     107 
     108    // add a "size" column to download_sets 
     109    $result = pwg_query('SHOW COLUMNS FROM `' . $prefixeTable . 'download_sets` LIKE "size";'); 
     110    if (!pwg_db_num_rows($result)) 
     111    { 
     112      pwg_query('ALTER TABLE `' . $prefixeTable . 'download_sets` ADD `size` varchar(16) NOT NULL DEFAULT "original";'); 
     113    } 
     114 
     115    // add "ready" status 
     116    pwg_query('ALTER TABLE `' . $prefixeTable . 'download_sets` CHANGE `status` `status` enum("new","ready","download","done") NOT NULL DEFAULT "new";'); 
     117  } 
     118 
     119  function activate($plugin_version, &$errors=array()) 
    17120  { 
    18     batch_download_install(); 
     121    if (!$this->installed) 
     122    { 
     123      $this->install($plugin_version, $errors); 
     124    } 
    19125  } 
    20 } 
    21126 
    22 function plugin_uninstall()  
    23 { 
    24   global $prefixeTable, $conf; 
    25    
    26   pwg_query('DELETE FROM `' . CONFIG_TABLE . '` WHERE param = "batch_download" LIMIT 1;'); 
    27   pwg_query('DROP TABLE IF EXISTS `' . $prefixeTable . 'download_sets`;'); 
    28   pwg_query('DROP TABLE IF EXISTS `' . $prefixeTable . 'download_sets_images`;'); 
    29    
    30   rrmdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'download_archives/'); 
    31 } 
     127  function deactivate() 
     128  { 
     129  } 
    32130 
     131  function uninstall() 
     132  { 
     133    global $prefixeTable, $conf; 
    33134 
    34 if (!function_exists('rrmdir')) 
    35 { 
    36   function rrmdir($dir) 
     135    conf_delete_param('batch_download'); 
     136 
     137    pwg_query('DROP TABLE IF EXISTS `' . $prefixeTable . 'download_sets`;'); 
     138    pwg_query('DROP TABLE IF EXISTS `' . $prefixeTable . 'download_sets_images`;'); 
     139 
     140    self::rrmdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'download_archives/'); 
     141  } 
     142 
     143  static function rrmdir($dir) 
    37144  { 
    38145    if (!is_dir($dir)) 
     
    43150    $objects = scandir($dir); 
    44151    $return = true; 
    45      
     152 
    46153    foreach ($objects as $object) 
    47154    { 
     
    49156      { 
    50157        $path = $dir.'/'.$object; 
    51         if (filetype($path) == 'dir')  
     158        if (filetype($path) == 'dir') 
    52159        { 
    53           $return = $return && rrmdir($path);  
     160          $return = $return && self::rrmdir($path); 
    54161        } 
    55         else  
     162        else 
    56163        { 
    57164          $return = $return && @unlink($path); 
     
    59166      } 
    60167    } 
    61      
     168 
    62169    return $return && @rmdir($dir); 
    63170  } 
    64171} 
    65  
    66 ?> 
  • extensions/BatchDownloader/template/download_button.tpl

    r25931 r25932  
    1 <a href="{$BATCH_DWN_URL}{$BATCH_DWN_SIZE}" id="batchDownloadLink" title="{'Download all pictures of this selection'|@translate}" class="pwg-state-default pwg-button" rel="nofollow"> 
    2   <span class="pwg-icon batch-downloader-icon" style="background:url('{$ROOT_URL}{$BATCH_DOWNLOAD_PATH}template/images/zip.png') center center no-repeat;">&nbsp;</span><span class="pwg-button-text">{'Download'|@translate}</span> 
     1<a href="{$BATCH_DWN_URL}{$BATCH_DWN_SIZE}" id="batchDownloadLink" title="{'Download all pictures of this selection'|translate}" class="pwg-state-default pwg-button" rel="nofollow"> 
     2  <span class="pwg-icon batch-downloader-icon" style="background:url('{$ROOT_URL}{$BATCH_DOWNLOAD_PATH}template/images/zip.png') center center no-repeat;">&nbsp;</span><span class="pwg-button-text">{'Download'|translate}</span> 
    33</a> 
    44 
     
    77 
    88<div id="batchDownloadBox" class="switchBox" style="display:none"> 
    9   <div class="switchBoxTitle">{'Download'|@translate} - {'Photo sizes'|@translate}</div> 
     9  <div class="switchBoxTitle">{'Download'|translate} - {'Photo sizes'|translate}</div> 
    1010  {foreach from=$BATCH_DWN_SIZES item=size name=loop}{if !$smarty.foreach.loop.first}<br>{/if} 
    1111  <a href="{$BATCH_DWN_URL}{$size.TYPE}" rel="nofollow"> 
     
    1818{footer_script require='jquery'} 
    1919var batchdown_count = {$BATCH_DWN_COUNT}; 
    20 var batchdown_string = "{'Confirm the download of %d pictures?'|@translate}"; 
     20var batchdown_string = "{'Confirm the download of %d pictures?'|translate}"; 
    2121 
    2222{if isset($BATCH_DWN_SIZES)} 
    2323  (SwitchBox=window.SwitchBox||[]).push("#batchDownloadLink", "#batchDownloadBox"); 
    24    
     24 
    2525  jQuery("#batchDownloadBox a").click(function() { 
    2626    return confirm(batchdown_string.replace('%d', batchdown_count)); 
  • extensions/BatchDownloader/template/init_zip.tpl

    r23360 r25932  
    1 {combine_css path=$BATCH_DOWNLOAD_PATH|@cat:"template/style.css"} 
     1{combine_css path=$BATCH_DOWNLOAD_PATH|cat:"template/style.css"} 
    22 
    33{if $set.U_DOWNLOAD} 
    44{footer_script} 
    5 setTimeout("document.location.href = '{$set.U_DOWNLOAD}';", 1000); 
     5setTimeout(function() { 
     6  document.location.href = '{$set.U_DOWNLOAD}'; 
     7}, 1000); 
    68{/footer_script} 
    79{/if} 
     
    1214 
    1315{footer_script} 
    14 var derivatives = {ldelim} 
     16var derivatives = { 
    1517  elements: ["{'","'|@implode:$missing_derivatives}"], 
    1618  done: 0, 
    1719  total: {$missing_derivatives|@count}, 
    18    
    19   finished: function() {ldelim} 
     20 
     21  finished: function() { 
    2022    return derivatives.done == derivatives.total; 
    2123  } 
    2224}; 
    2325 
    24 function progress() {ldelim} 
    25   jQuery('#progressBar').progressBar(derivatives.done/derivatives.total*100, {ldelim} 
     26function progress() { 
     27  jQuery('#progressBar').progressBar(derivatives.done/derivatives.total*100, { 
    2628    width: 300, 
    2729    height: 24, 
     
    3133} 
    3234 
    33 {literal} 
    34 var queuedManager = jQuery.manageAjax.create('queued', {  
    35   queue: true,   
     35var queuedManager = jQuery.manageAjax.create('queued', { 
     36  queue: true, 
    3637  cacheResponse: false, 
    3738  maxRequests: 1 
     
    4041function next_derivative() { 
    4142  if (derivatives.finished()) { 
    42     setTimeout("location.reload(true)", 1000); 
     43    setTimeout(function() { 
     44      location.reload(true); 
     45    }, 1000); 
    4346    return; 
    4447  } 
    45    
     48 
    4649  queuedManager.add({ 
    47     type: 'GET',  
    48     url: derivatives.elements[ derivatives.done ],  
     50    type: 'GET', 
     51    url: derivatives.elements[ derivatives.done ], 
    4952    dataType: 'json', 
    50     data: { ajaxload: 'true' }, 
     53    data: { 
     54      ajaxload: 'true' 
     55    }, 
    5156    success: function() { 
    5257      derivatives.done++; 
     
    6368 
    6469progress(); 
    65 setTimeout("next_derivative()", 1000); 
    66 {/literal}{/footer_script} 
     70setTimeout(next_derivative, 1000); 
     71{/footer_script} 
    6772 
    68 {/if} 
    69  
    70  
    71 {* <!-- Menubar & titrePage --> *} 
    72 {if $themeconf.name == "stripped" or $themeconf.parent == "stripped"} 
    73   {include file=$BATCH_DOWNLOAD_ABS_PATH|@cat:'template/themes/stripped.tpl'} 
    74   {assign var="clear" value="true"} 
    75 {elseif $themeconf.name == "simple-grey" or $themeconf.parent == "simple"} 
    76   {include file=$BATCH_DOWNLOAD_ABS_PATH|@cat:'template/themes/simple.tpl'} 
    77   {assign var="clear" value="true"} 
    78 {else} 
    79   {include file=$BATCH_DOWNLOAD_ABS_PATH|@cat:'template/themes/default.tpl'} 
    80 {/if} 
    81  
    82 {if isset($errors) or not empty($infos)} 
    83 {include file='infos_errors.tpl'} 
    8473{/if} 
    8574 
     
    8776{if $set} 
    8877<fieldset> 
    89   <legend>{'Download info'|@translate}</legend> 
     78  <legend>{'Download info'|translate}</legend> 
    9079  <h2>{$set.NAME}</h2> 
    9180  {if $set.COMMENT}<blockquote class="comment">{$set.COMMENT}</blockquote>{/if} 
    92    
     81 
    9382  <ul class="set-infos"> 
    9483    <li class="error">{$elements_error}</li> 
    95     <li><b>{'%d photos'|@translate|@sprintf:$set.NB_IMAGES}</b>{if $set.U_EDIT_SET}, <a href="{$set.U_EDIT_SET}" rel="nofollow">{'Edit the set'|@translate}</a>{/if}</li> 
    96     <li><b>{'Photo sizes'|@translate}:</b> {if $set.SIZE=='original'}{'Original'|@translate}{else}{$set.SIZE|@translate}{/if} {if $set.SIZE_INFO}<span class="downloadSizeDetails">({$set.SIZE_INFO})</span>{/if}</li> 
    97     <li><b>{'Estimated size'|@translate}:</b> {$set.TOTAL_SIZE}</li> 
    98     <li><b>{'Estimated number of archives'|@translate}:</b> {$set.NB_ARCHIVES} <i>({'real number of archives can differ'|@translate})</i></li> 
    99     <li><b>{'Created on'|@translate}:</b> {$set.DATE_CREATION}</li> 
     84    <li><b>{'%d photos'|translate:$set.NB_IMAGES}</b>{if $set.U_EDIT_SET}, <a href="{$set.U_EDIT_SET}" rel="nofollow">{'Edit the set'|translate}</a>{/if}</li> 
     85    <li><b>{'Photo sizes'|translate}:</b> {if $set.SIZE=='original'}{'Original'|translate}{else}{$set.SIZE|translate}{/if} {if $set.SIZE_INFO}<span class="downloadSizeDetails">({$set.SIZE_INFO})</span>{/if}</li> 
     86    <li><b>{'Estimated size'|translate}:</b> {$set.TOTAL_SIZE}</li> 
     87    <li><b>{'Estimated number of archives'|translate}:</b> {$set.NB_ARCHIVES} <i>({'real number of archives can differ'|translate})</i></li> 
     88    <li><b>{'Created on'|translate}:</b> {$set.DATE_CREATION}</li> 
    10089  </ul> 
    10190</fieldset> 
     
    10392{if $missing_derivatives} 
    10493<fieldset> 
    105   <legend>{'Preparation'|@translate}</legend> 
    106    
    107   <p>{'Please wait, your download is being prepared. This page will automatically refresh when it is ready.'|@translate}</p> 
    108    
     94  <legend>{'Preparation'|translate}</legend> 
     95 
     96  <p>{'Please wait, your download is being prepared. This page will automatically refresh when it is ready.'|translate}</p> 
     97 
    10998  <div id="progressBar"></div> 
    110    
    111   <a href="{$set.U_CANCEL}" class="cancel-down" onClick="return confirm('{'Are you sure?'|@translate}');">{'Cancel this download'|@translate}</a> 
     99 
     100  <a href="{$set.U_CANCEL}" class="cancel-down" onClick="return confirm('{'Are you sure?'|translate}');">{'Cancel this download'|translate}</a> 
    112101</fieldset> 
    113102 
    114103{elseif $zip_links} 
    115104<fieldset> 
    116   <legend>{'Download links'|@translate}</legend> 
    117    
     105  <legend>{'Download links'|translate}</legend> 
     106 
    118107  <ul class="download-links"> 
    119108    {$zip_links} 
    120     <li class="warning">{'<b>Warning:</b> all files will be deleted within %d hours'|@translate|@sprintf:$archive_timeout}</li> 
     109    <li class="warning">{'<b>Warning:</b> all files will be deleted within %d hours'|translate:$archive_timeout}</li> 
    121110  </ul> 
    122    
    123   {if $set.U_CANCEL}<a href="{$set.U_CANCEL}" class="cancel-down" onClick="return confirm('{'Are you sure?'|@translate}');">{'Cancel this download'|@translate}</a>{/if} 
     111 
     112  {if $set.U_CANCEL}<a href="{$set.U_CANCEL}" class="cancel-down" onClick="return confirm('{'Are you sure?'|translate}');">{'Cancel this download'|translate}</a>{/if} 
    124113</fieldset> 
    125114{/if} 
    126115{/if} 
    127  
    128 {if $clear}<div style="clear: both;"></div> 
    129 </div>{/if} 
    130 </div>{* <!-- content --> *} 
  • extensions/BatchDownloader/template/style.css

    r23291 r25932  
    3838    border-color:#f00; 
    3939  } 
    40    
     40 
    4141.downloadSizeDetails { 
    4242  font-style:italic; 
  • extensions/BatchDownloader/template/thumbnails_css_js.tpl

    r23359 r25932  
    1 {html_style} 
    2 #thumbnails li {ldelim} position:relative !important;display:inline-block; } 
    3 li .removeSet {ldelim} width:100%;height:16px;display:none;position:absolute;top:0;background:rgba(0,0,0,0.8);padding:2px;border-radius:2px;font-size:10px;z-index:100 !important;color:#eee;white-space:nowrap; } 
    4 li:hover .removeSet {ldelim} display:block !important; } 
    5 {/html_style} 
     1{html_style}{literal} 
     2#thumbnails li { position:relative !important;display:inline-block; } 
     3li .removeSet { width:100%;height:16px;display:none;position:absolute;top:0;background:rgba(0,0,0,0.8);padding:2px;border-radius:2px;font-size:10px;z-index:100 !important;color:#eee;white-space:nowrap; } 
     4li:hover .removeSet { display:block !important; } 
     5{/literal}{/html_style} 
    66 
    77{footer_script require='jquery'} 
    8 jQuery(".removeSet").click(function() {ldelim} 
     8jQuery(".removeSet").click(function() { 
    99  var toggle_id = jQuery(this).data("id"); 
    1010  var $trigger = jQuery(this); 
    11    
    12   jQuery.ajax({ldelim} 
     11 
     12  jQuery.ajax({ 
    1313    type: "POST", 
    1414    url: "{$ROOT_URL}index.php", 
    15     data: {ldelim} 
     15    data: { 
    1616      action: "bd_remove_image", 
    1717      set_id: "{$SET_ID}", 
    1818      toggle_id: toggle_id 
    1919    }, 
    20     success: function(msg) {ldelim} 
    21       if (msg == "ok") {ldelim} 
    22         $trigger.parent("li").hide("fast", function() {ldelim} 
     20    success: function(msg) { 
     21      if (msg == "ok") { 
     22        $trigger.parent("li").hide("fast", function() { 
    2323          jQuery(this).remove(); 
    2424          if (typeof GThumb != "undefined") GThumb.build(); 
    2525        }); 
    26          
     26 
    2727        jQuery(".nbImagesSet").html(parseInt(jQuery(".nbImagesSet").html()) -1); 
    28       } else {ldelim} 
    29         $trigger.html('{'Un unknown error occured'|@translate}'); 
     28      } 
     29      else { 
     30        $trigger.html('{'Un unknown error occured'|translate}'); 
    3031      } 
    3132    }, 
    32     error: function() {ldelim} 
    33       $trigger.html('{'Un unknown error occured'|@translate}'); 
     33    error: function() { 
     34      $trigger.html('{'Un unknown error occured'|translate}'); 
    3435    } 
    3536  }); 
    36    
     37 
    3738  return false; 
    3839}); 
  • extensions/BatchDownloader/template/view.tpl

    r17517 r25932  
    1 {* <!-- Menubar & titrePage --> *} 
    2 {if $themeconf.name == "stripped" or $themeconf.parent == "stripped"} 
    3   {include file=$BATCH_DOWNLOAD_ABS_PATH|@cat:'template/themes/stripped.tpl'} 
    4   {assign var="clear" value="true"} 
    5 {elseif $themeconf.name == "simple-grey" or $themeconf.parent == "simple"} 
    6   {include file=$BATCH_DOWNLOAD_ABS_PATH|@cat:'template/themes/simple.tpl'} 
    7   {assign var="clear" value="true"} 
    8 {else} 
    9   {include file=$BATCH_DOWNLOAD_ABS_PATH|@cat:'template/themes/default.tpl'} 
    10 {/if} 
    11  
    12 {if isset($errors) or not empty($infos)} 
    13 {include file='infos_errors.tpl'} 
    14 {/if} 
    15  
    161{if $set} 
    172<fieldset> 
     
    194  {if $set.COMMENT}<blockquote>{$set.COMMENT}</blockquote>{/if} 
    205  {assign var="nb_images" value='<span class="nbImagesSet">'|@cat:$set.NB_IMAGES|@cat:'</span>'} 
    21   {'%d photos'|@translate|replace:'%d':'%s'|sprintf:$nb_images} 
     6  {'%d photos'|translate|replace:'%d':'%s'|sprintf:$nb_images} 
    227  <br> 
    23   <b><a href="{$U_INIT_ZIP}" rel="nofollow">{'Return to download page'|@translate} →</a></b> 
     8  <b><a href="{$U_INIT_ZIP}" rel="nofollow">{'Return to download page'|translate} →</a></b> 
    249</fieldset> 
    2510 
     
    3015</ul> 
    3116{else} 
    32 {'This download set is empty'|@translate} 
     17{'This download set is empty'|translate} 
    3318{/if} 
    3419 
    3520{if !empty($navbar)}{include file='navigation_bar.tpl'|@get_extent:'navbar'}{/if} 
    3621{/if} 
    37  
    38 {if $clear}<div style="clear: both;"></div> 
    39 </div>{/if} 
    40 </div>{* <!-- content --> *} 
Note: See TracChangeset for help on using the changeset viewer.