Changeset 23291 for extensions


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

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

Location:
extensions/BatchDownloader
Files:
5 added
11 edited
1 copied
5 moved

Legend:

Unmodified
Added
Removed
  • extensions/BatchDownloader/admin/template/sets.tpl

    r21607 r23291  
    6262    <td>{$set.NAME}</td>
    6363    <td style="text-align:center;">{$set.DATE_CREATION}</td>
    64     <td>{$set.TOTAL_SIZE} MB</td>
     64    <td>{$set.TOTAL_SIZE}</td>
    6565    <td>{$set.NB_IMAGES}</td>
    6666    <td>{$set.NB_ARCHIVES}</td>
  • extensions/BatchDownloader/download.php

    r23167 r23291  
    88  $BatchDownloader = new BatchDownloader($_GET['set_id']);
    99  $file = $BatchDownloader->getArchivePath();
     10 
     11  if (!file_exists($file))
     12  {
     13    throw new Exception('Unable to locate file.');
     14  }
    1015 
    1116  if (isset($conf['batch_download_direct']) and $conf['batch_download_direct'])
  • extensions/BatchDownloader/include/BatchDownloader.class.php

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

    r23290 r23291  
    1111  case 'init_zip':
    1212  {
    13     $template->set_filename('index', dirname(__FILE__) . '/../template/init_zip.tpl');
     13    $template->set_filename('index', realpath(BATCH_DOWNLOAD_PATH . 'template/init_zip.tpl'));
    1414   
    1515    try
     
    5555            $template->assign('missing_derivatives', $missing_derivatives);
    5656          }
    57           // set ready
     57          // set is ready
    5858          else
    5959          {
     
    108108    $self_url = add_url_params(BATCH_DOWNLOAD_PUBLIC . 'view', array('set_id'=>$_GET['set_id']));
    109109   
    110     $template->set_filename('index', dirname(__FILE__).'/../template/view.tpl');
     110    $template->set_filename('index', realpath(BATCH_DOWNLOAD_PATH . 'template/view.tpl'));
    111111    $template->assign(array(
    112112      'BATCH_DOWNLOAD_PATH' => BATCH_DOWNLOAD_PATH,
     
    120120      $BatchDownloader = new BatchDownloader($_GET['set_id']);
    121121     
    122       if ($BatchDownloader->getParam('status') != 'new')
     122      if ($BatchDownloader->getParam('status') != 'new' && $BatchDownloader->getParam('status') != 'ready')
    123123      {
    124124        array_push($page['errors'], l10n('You can not edit this set'));
  • extensions/BatchDownloader/include/functions.inc.php

    r23290 r23291  
    6767    'type' => $batch_type,
    6868    'id' => $batch_id,
    69     'size' => isset($_GET['down_size']) ? $_GET['down_size'] : 'original',
     69    'size' => !empty($_GET['down_size']) ? $_GET['down_size'] : 'original',
    7070    );
    7171}
  • extensions/BatchDownloader/language/en_UK/plugin.lang.php

    r23280 r23291  
    5050$lang['No result'] = 'No result';
    5151$lang['Sorry, there is nothing to download. Some files may have been excluded because of <i title="Authorized types are : %s">filetype restrictions</i>.'] = 'Sorry, there is nothing to download. Some files may have been excluded because of <i title="Authorized types are : %s">filetype restrictions</i>.';
     52$lang['Unknown'] = 'Unknown';
     53$lang['Preparation'] = 'Preparation';
     54$lang['Please wait, your download is being prepared. This page will refresh automatically refresh when it is ready.'] = 'Please wait, your download is being prepared. This page will refresh automatically refresh when it is ready.';
     55$lang['%d MB'] = '%d MB';
    5256
    5357?>
  • extensions/BatchDownloader/language/fr_FR/plugin.lang.php

    r23280 r23291  
    5050$lang['No result'] = 'Aucun résultat';
    5151$lang['Sorry, there is nothing to download. Some files may have been excluded because of <i title="Authorized types are : %s">filetype restrictions</i>.'] = 'Désolé, il n\'y a rien à télécharger. Certains fichiers ont peut-être été exclu à cause de <i title="Les types autorisés sont : %s">leur type</i>.';
     52$lang['Unknown'] = 'Inconnu';
     53$lang['Preparation'] = 'Préparation';
     54$lang['Please wait, your download is being prepared. This page will refresh automatically refresh when it is ready.'] = 'Veuillez patienter, votre téléchargement est en cours de préparation. La page se refraîchira automatiquement une fois terminé.';
     55$lang['%d MB'] = '%d Mio';
    5256
    5357?>
  • extensions/BatchDownloader/template/download_button.tpl

    r23290 r23291  
    3030<script type="text/javascript"></script>
    3131<li><a href="{$BATCH_DWN_URL}" id="batchDownloadLink" title="{'Download all pictures of this selection'|@translate}" class="pwg-state-default pwg-button" rel="nofollow">
    32   <span class="pwg-icon batch-downloader-icon" style="background:url('{$ROOT_PATH}{$BATCH_DOWNLOAD_PATH}template/zip.png') center center no-repeat;">&nbsp;</span><span class="pwg-button-text">{'Download'|@translate}</span>
     32  <span class="pwg-icon batch-downloader-icon" style="background:url('{$ROOT_PATH}{$BATCH_DOWNLOAD_PATH}template/images/zip.png') center center no-repeat;">&nbsp;</span><span class="pwg-button-text">{'Download'|@translate}</span>
    3333</a></li>
    3434
  • extensions/BatchDownloader/template/init_zip.tpl

    r23290 r23291  
    1313{footer_script}
    1414var derivatives = {ldelim}
    15         elements: ["{'","'|@implode:$missing_derivatives}"],
    16         done: 0,
    17         total: {$missing_derivatives|@count},
    18        
    19         finished: function() {ldelim}
    20                 return derivatives.done == derivatives.total;
    21         }
     15  elements: ["{'","'|@implode:$missing_derivatives}"],
     16  done: 0,
     17  total: {$missing_derivatives|@count},
     18 
     19  finished: function() {ldelim}
     20    return derivatives.done == derivatives.total;
     21  }
    2222};
    2323
    24 function progress(success) {ldelim}
    25   jQuery('#progressBar').progressBar(derivatives.done, {ldelim}
    26     max: derivatives.total,
    27     textFormat: 'fraction',
    28     boxImage: '{$ROOT_PATH}themes/default/images/progressbar.gif',
    29     barImage: '{$ROOT_PATH}themes/default/images/progressbg_red.gif'
     24function progress() {ldelim}
     25  jQuery('#progressBar').progressBar(derivatives.done/derivatives.total*100, {ldelim}
     26    width: 300,
     27    height: 24,
     28    boxImage: '{$ROOT_PATH}{$BATCH_DOWNLOAD_PATH}template/images/progress_box.png',
     29    barImage: '{$ROOT_PATH}{$BATCH_DOWNLOAD_PATH}template/images/progress_bar.png'
    3030  });
    31   if (success !== undefined) {ldelim}
    32                 var type = success ? '.regenerateSuccess': '.regenerateError',
    33                         s = parseInt(jQuery(type).html());
    34                 jQuery(type).html(++s);
    35         }
    3631}
    3732
     
    4540function next_derivative() {
    4641  if (derivatives.finished()) {
    47                 alert("finish");
     42    setTimeout("location.reload(true)", 1000);
    4843    return;
    49         }
    50  
    51   $("#damn").append(derivatives.elements[ derivatives.done ]+"<br>");
     44  }
    5245 
    5346  jQuery.manageAjax.add("queued", {
     
    5750    success: function(data) {
    5851      derivatives.done++;
    59       progress(true);
     52      progress();
    6053      next_derivative();
    6154    },
    6255    error: function(data) {
    6356      derivatives.done++;
    64       progress(false);
     57      progress();
    6558      next_derivative();
    6659    }
     
    6861}
    6962
    70 $("#begin").click(function() {
    71   progress();
    72   next_derivative();
    73 });
     63progress();
     64setTimeout("next_derivative()", 1000);
    7465{/literal}{/footer_script}
    7566
     
    10394    <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>
    10495    <li><b>{'Size'|@translate}:</b> {$set.SIZE} {if $set.SIZE_INFO}<span class="downloadSizeDetails">({$set.SIZE_INFO})</span>{/if}</li>
    105     <li><b>{'Estimated size'|@translate}:</b> {$set.TOTAL_SIZE} MB</li>
     96    <li><b>{'Estimated size'|@translate}:</b> {$set.TOTAL_SIZE}</li>
    10697    <li><b>{'Estimated number of archives'|@translate}:</b> {$set.NB_ARCHIVES} <i>({'real number of archives can differ'|@translate})</i></li>
    10798    <li><b>{'Created on'|@translate}:</b> {$set.DATE_CREATION}</li>
     
    111102{if $missing_derivatives}
    112103<fieldset>
    113   <legend>Stuff happening</legend>
     104  <legend>{'Preparation'|@translate}</legend>
    114105 
    115   <a id="begin">GO</a>
     106  <p>{'Please wait, your download is being prepared. This page will refresh automatically refresh when it is ready.'|@translate}</p>
    116107 
    117   <div id="regenerationMsg" class="bulkAction">
    118     <span class="progressBar" id="progressBar"></span>
    119   </div>
     108  <div id="progressBar"></div>
    120109 
    121   <span class="regenerateSuccess">0</span> -
    122   <span class="regenerateError">0</span>
    123  
    124   <div id="damn">
    125   </div>
     110  <a href="{$set.U_CANCEL}" class="cancel-down" onClick="return confirm('{'Are you sure?'|@translate}');">{'Cancel this download'|@translate}</a>
    126111</fieldset>
    127 {/if}
    128112
    129 {if $zip_links}
     113{elseif $zip_links}
    130114<fieldset>
    131115  <legend>{'Download links'|@translate}</legend>
  • extensions/BatchDownloader/template/style.css

    r23290 r23291  
    44
    55ul.set-infos {
    6   margin-top:30px;
     6  margin-top:20px;
    77}
    88
     
    2828a.cancel-down {
    2929  display:inline-block;
    30   margin-top:20px;
     30  margin-top:10px;
    3131  padding:2px 5px;
    3232  font-weight:bold;
     
    3939  }
    4040 
    41 .downloadSizeDetails {font-style:italic; font-size:80%;}
     41.downloadSizeDetails {
     42  font-style:italic;
     43  font-size:80%;
     44}
     45
     46#progressBar {
     47  width:300px;
     48  position:relative;
     49}
     50#progressBar_pbImage {
     51  border-radius:12px;
     52}
     53#progressBar_pbText {
     54  color:white;
     55  font-weight:bold;
     56  font-size:16px;
     57  line-height:16px;
     58  position:absolute;
     59  right:5px;
     60  top:50%;
     61  margin-top:-9px;
     62  text-shadow:0 0 3px #000;
     63}
  • extensions/BatchDownloader/template/thumbnails_css_js.tpl

    r21206 r23291  
    1818      $trigger.parent("li").hide("fast", function() {ldelim} $trigger.remove() });
    1919      jQuery(".nbImagesSet").html(parseInt(jQuery(".nbImagesSet").html()) -1);
     20     
     21      if (typeof GThumb == "object") GThumb.build();
    2022    } else {ldelim}
    2123      $trigger.html('{'Un unknown error occured'|@translate}');
Note: See TracChangeset for help on using the changeset viewer.