Changeset 16609


Ignore:
Timestamp:
07/11/12 12:58:19 (7 years ago)
Author:
mistic100
Message:

-add complete breadcrumb
-AJAX for remove photos (more faster)
-use try/catch for error handling

Location:
extensions/BatchDownloader
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • extensions/BatchDownloader/download.php

    r16379 r16609  
    33include(PHPWG_ROOT_PATH.'include/common.inc.php'); 
    44 
    5 // check_status(ACCESS_CLASSIC); 
     5check_status(ACCESS_CLASSIC); 
    66 
    7 $BatchDownloader = new BatchDownloader($_GET['set_id']); 
    8 $file = $BatchDownloader->getArchivePath(); 
     7try { 
     8  $BatchDownloader = new BatchDownloader($_GET['set_id']); 
     9  $file = $BatchDownloader->getArchivePath(); 
    910 
    10 header('Content-Type: application/force-download; name="'.basename($file).'"'); 
    11 header('Content-Disposition: attachment; filename="'.basename($file).'"'); 
    12 header('Content-Description: File Transfer'); 
    13 header('Content-Transfer-Encoding: binary'); 
    14 header('Content-Length: '.filesize($file).''); 
     11  header('Content-Type: application/force-download; name="'.basename($file).'"'); 
     12  header('Content-Disposition: attachment; filename="'.basename($file).'"'); 
     13  header('Content-Description: File Transfer'); 
     14  header('Content-Transfer-Encoding: binary'); 
     15  header('Content-Length: '.filesize($file).''); 
    1516 
    16 header('Cache-Control: no-cache, must-revalidate'); 
    17 header('Pragma: no-cache'); 
    18 header('Expires: 0'); 
     17  header('Cache-Control: no-cache, must-revalidate'); 
     18  header('Pragma: no-cache'); 
     19  header('Expires: 0'); 
    1920 
    20 readfile($file); 
     21  readfile($file); 
     22} 
     23catch (Exception $e) 
     24{ 
     25  echo $e->getMessage(); 
     26} 
     27     
    2128exit(0); 
    2229 
  • extensions/BatchDownloader/include/BatchDownloader.class.php

    r16598 r16609  
    9595      else 
    9696      { 
    97         trigger_error('BatchDownloader::__construct, invalid set id', E_USER_ERROR); 
     97        throw new Exception(l10n('Invalid dowload set')); 
    9898      } 
    9999    } 
     
    270270  function createNextArchive($force_one_archive=false) 
    271271  { 
    272     // set already downloaded 
     272    // set already downloaded (we should never be there !) 
    273273    if ( $this->data['status'] == 'done' or $this->data['nb_images'] == 0 ) 
    274274    { 
  • extensions/BatchDownloader/include/download.inc.php

    r16592 r16609  
    1313    $template->set_filename('index', dirname(__FILE__) . '/../template/init_zip.tpl'); 
    1414     
    15     $BatchDownloader = new BatchDownloader($_GET['set_id']); 
    16      
    17     if ( isset($_GET['cancel']) ) 
     15    try 
    1816    { 
    19       $BatchDownloader->deleteLastArchive(); 
    20       $BatchDownloader->clearImages(); 
    21       pwg_query('DELETE FROM '.BATCH_DOWNLOAD_TSETS.' WHERE id = '.$_GET['set_id'].';'); 
    22       $_SESSION['page_infos'][] = l10n('Download set deleted'); 
    23       redirect('index.php'); 
    24     } 
    25      
    26     if ( isset($_GET['zip']) and $BatchDownloader->getParam('status') != 'done' and $_GET['zip'] > $BatchDownloader->getParam('last_zip') ) 
    27     { 
    28       $BatchDownloader->deleteLastArchive(); 
    29       $next_file = $BatchDownloader->createNextArchive(); 
    30     } 
     17      $BatchDownloader = new BatchDownloader($_GET['set_id']); 
     18       
     19      if ( isset($_GET['cancel']) ) 
     20      { 
     21        $BatchDownloader->deleteLastArchive(); 
     22        $BatchDownloader->clearImages(); 
     23        pwg_query('DELETE FROM '.BATCH_DOWNLOAD_TSETS.' WHERE id = '.$_GET['set_id'].';'); 
     24        $_SESSION['page_infos'][] = l10n('Download set deleted'); 
     25        redirect('index.php'); 
     26      } 
     27       
     28      if ( isset($_GET['zip']) and $BatchDownloader->getParam('status') != 'done' and $_GET['zip'] > $BatchDownloader->getParam('last_zip') ) 
     29      { 
     30        $BatchDownloader->deleteLastArchive(); 
     31        $next_file = $BatchDownloader->createNextArchive(); 
     32      } 
    3133 
    32     $set = $BatchDownloader->getSetInfo(); 
    33      
    34     if (isset($next_file)) 
    35     { 
    36       $set['U_DOWNLOAD'] = BATCH_DOWNLOAD_PATH . 'download.php?set_id='.$_GET['set_id'].'&zip='.$_GET['zip']; 
    37       array_push($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'])); 
    38     } 
    39      
    40     if ($BatchDownloader->getParam('nb_images') > $conf['batch_download']['max_elements']) 
    41     { 
    42       $template->assign('elements_error', sprintf( 
    43         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.'), 
    44         $BatchDownloader->getParam('nb_images'), 
    45         $conf['batch_download']['max_elements'], 
    46         $BatchDownloader->getParam('nb_images') - $conf['batch_download']['max_elements'] 
     34      $set = $BatchDownloader->getSetInfo(); 
     35       
     36      if (isset($next_file)) 
     37      { 
     38        $set['U_DOWNLOAD'] = BATCH_DOWNLOAD_PATH . 'download.php?set_id='.$_GET['set_id'].'&amp;zip='.$_GET['zip']; 
     39        array_push($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'])); 
     40      } 
     41       
     42      if ($BatchDownloader->getParam('nb_images') > $conf['batch_download']['max_elements']) 
     43      { 
     44        $template->assign('elements_error', sprintf( 
     45          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.'), 
     46          $BatchDownloader->getParam('nb_images'), 
     47          $conf['batch_download']['max_elements'], 
     48          $BatchDownloader->getParam('nb_images') - $conf['batch_download']['max_elements'] 
     49          )); 
     50      } 
     51       
     52      $set['U_CANCEL'] = BATCH_DOWNLOAD_PUBLIC . 'init_zip&amp;set_id='.$_GET['set_id'].'&amp;cancel'; 
     53       
     54      $template->assign(array( 
     55        'set' => $set, 
     56        'archive_timeout' => $conf['batch_download']['archive_timeout'], 
    4757        )); 
    4858    } 
    49      
    50     if ($BatchDownloader->getParam('status') == 'new') 
     59    catch (Exception $e) 
    5160    { 
    52       $set['U_CANCEL'] = BATCH_DOWNLOAD_PUBLIC . 'init_zip&amp;set_id='.$_GET['set_id'].'&amp;cancel'; 
     61      array_push($page['errors'], $e->getMessage()); 
    5362    } 
    54      
    55     $template->assign(array( 
    56       'set' => $set, 
    57       'archive_timeout' => $conf['batch_download']['archive_timeout'], 
    58       )); 
    5963     
    6064    break; 
     
    7175      'U_VIEW' => $self_url, 
    7276      'U_INIT_ZIP' => BATCH_DOWNLOAD_PUBLIC . 'init_zip&amp;set_id='.$_GET['set_id'], 
     77      'SET_ID' => $_GET['set_id'], 
    7378      )); 
    7479     
    75     $BatchDownloader = new BatchDownloader($_GET['set_id']); 
    76      
    77     if ($BatchDownloader->getParam('status') != 'new') 
     80    try 
    7881    { 
    79       array_push($page['errors'], l10n('You can not edit this set')); 
    80       break; 
     82      $BatchDownloader = new BatchDownloader($_GET['set_id']); 
     83       
     84      if ($BatchDownloader->getParam('status') != 'new') 
     85      { 
     86        array_push($page['errors'], l10n('You can not edit this set')); 
     87        break; 
     88      } 
     89       
     90      if ( isset($_GET['remove']) and preg_match('#^[0-9]+$#', $_GET['remove']) ) 
     91      { 
     92        $BatchDownloader->removeImages(array($_GET['remove'])); 
     93      } 
     94       
     95      $template->assign('set', $BatchDownloader->getSetInfo()); 
     96       
     97      $template->set_prefilter('index_thumbnails', 'batch_download_thumbnails_list_prefilter'); 
     98       
     99      $page['start'] = isset($_GET['start']) ? $_GET['start'] : 0; 
     100      $page['items'] = array_keys($BatchDownloader->getImages()); 
     101       
     102      if (count($page['items']) > $page['nb_image_page']) 
     103      { 
     104        $page['navigation_bar'] = create_navigation_bar( 
     105          $self_url, 
     106          count($page['items']), 
     107          $page['start'], 
     108          $page['nb_image_page'], 
     109          false 
     110          ); 
     111        $template->assign('navbar', $page['navigation_bar']); 
     112      } 
     113       
     114      include(PHPWG_ROOT_PATH . 'include/category_default.inc.php'); 
    81115    } 
    82      
    83     if ( isset($_GET['remove']) and preg_match('#^[0-9]+$#', $_GET['remove']) ) 
     116    catch (Exception $e) 
    84117    { 
    85       $BatchDownloader->removeImages(array($_GET['remove'])); 
     118      array_push($page['errors'], $e->getMessage()); 
    86119    } 
    87      
    88     $template->assign('set', $BatchDownloader->getSetInfo()); 
    89      
    90     $template->set_prefilter('index_thumbnails', 'batch_download_thumbnails_list_prefilter'); 
    91      
    92     $page['start'] = isset($_GET['start']) ? $_GET['start'] : 0; 
    93     $page['items'] = array_keys($BatchDownloader->getImages()); 
    94      
    95     if (count($page['items']) > $page['nb_image_page']) 
    96     { 
    97       $page['navigation_bar'] = create_navigation_bar( 
    98         $self_url, 
    99         count($page['items']), 
    100         $page['start'], 
    101         $page['nb_image_page'], 
    102         false 
    103         ); 
    104       $template->assign('navbar', $page['navigation_bar']); 
    105     } 
    106      
    107     include(PHPWG_ROOT_PATH . 'include/category_default.inc.php'); 
    108120     
    109121    break; 
     
    116128function batch_download_thumbnails_list_prefilter($content, &$smarty) 
    117129{ 
    118   $search = '<span class="thumbName">'; 
     130  // custom style 
     131  $search[0] = '{/html_style}'; 
     132  $replace[0] = '.thumbnails  .wrap1 {ldelim} position:relative; } 
     133.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:0.8em; } 
     134.wrap1:hover .removeSet {ldelim} display:block; }' 
     135.$search[0]; 
     136 
     137  // links 
     138  $search[1] = '<span class="wrap1">'; 
     139  $replace[1] = $search[1].' 
     140{strip}<a class="removeSet" href="{$U_VIEW}&amp;remove={$thumbnail.id}" data-id="{$thumbnail.id}" rel="nofollow"> 
     141{\'Remove from download set\'|@translate}&nbsp;<img src="{$BATCH_DOWNLOAD_PATH}template/image_delete.png" title="{\'Remove from download set\'|@translate}"> 
     142</a>{/strip}'; 
     143 
     144  // AJAX request 
     145  $search[2] = '{/html_style}'; 
     146  $replace[2] = $search[2].' 
     147{footer_script require=\'jquery\'} 
     148jQuery(".removeSet").click(function() {ldelim} 
     149  var toggle_id = jQuery(this).data("id"); 
     150  var $trigger = jQuery(this); 
    119151   
    120   $add = '<a href="{$U_VIEW}&amp;remove={$thumbnail.id}" rel="nofollow"> 
    121 <img src="{$BATCH_DOWNLOAD_PATH}template/image_delete.png" title="{\'Remove from download set\'|@translate}"> 
    122 </a>&nbsp;'; 
     152  jQuery.ajax({ldelim} 
     153    type: "POST", 
     154    url: "{$BATCH_DOWNLOAD_PATH}remove_image.php", 
     155    data: {ldelim} "set_id": "{$SET_ID}", "toggle_id": toggle_id } 
     156  }).done(function(msg) {ldelim} 
     157    if (msg == "false") {ldelim} 
     158      $trigger.parent(".wrap1").hide("fast", function() {ldelim} $trigger.remove() }); 
     159      jQuery(".nbImages").html(jQuery(".nbImages").html() -1); 
     160    } else {ldelim} 
     161      $trigger.html(\'{\'Un unknown error occured\'|@translate}\'); 
     162    } 
     163  }); 
     164   
     165  return false; 
     166}); 
     167{/footer_script}'; 
    123168 
    124   return str_replace($search, $search.$add, $content); 
     169  return str_replace($search, $replace, $content); 
    125170} 
    126171 
  • extensions/BatchDownloader/include/events.inc.php

    r16598 r16609  
    2424     
    2525    $page['section'] = 'download'; 
    26     $page['title'] = l10n('Batch Downloader').$conf['level_separator'].' '; 
     26    $page['title'] = '<a href="'.get_absolute_root_url().'">'.l10n('Home').'</a>'.$conf['level_separator'].l10n('Batch Downloader').$conf['level_separator']; 
    2727     
    2828    switch (@$tokens[1]) 
     
    164164      array_push($data, array( 
    165165        'URL' => BATCH_DOWNLOAD_PUBLIC . 'init_zip&amp;set_id='.$BatchDownloader->getParam('set_id'), 
    166         'TITLE' => strip_tags($set['COMMENT']), 
     166        'TITLE' => str_replace('"', "'", strip_tags($set['COMMENT'])), 
    167167        'NAME' => $set['sNAME'], 
    168168        'COUNT' => $set['NB_IMAGES'], 
  • extensions/BatchDownloader/language/en_UK/plugin.lang.php

    r16598 r16609  
    66$lang['Random'] = 'Random'; 
    77$lang['User collection'] = 'User collection'; 
    8 $lang['Nb images'] = 'Nb images'; 
     8$lang['Nb images'] = 'Nb photos'; 
    99$lang['Nb archives'] = 'Nb archives'; 
    1010$lang['Total size'] = 'Total size'; 
     
    3232$lang['Cancel this set'] = 'Cancel this set'; 
    3333$lang['Download info'] = 'Download info'; 
     34$lang['Estimated size'] = 'Estimated size'; 
    3435$lang['Estimated number of archives'] = 'Estimated number of archives'; 
    3536$lang['real number of archives can differ'] = 'real number of archives can differ'; 
  • extensions/BatchDownloader/language/fr_FR/plugin.lang.php

    r16598 r16609  
    3232$lang['Cancel this set'] = 'Annuler ce lot'; 
    3333$lang['Download info'] = 'Informations sur le téléchargement'; 
     34$lang['Estimated size'] = 'Taille estimée'; 
    3435$lang['Estimated number of archives'] = 'Nombre estimé d\'archives'; 
    3536$lang['real number of archives can differ'] = 'le nombre réel d\'archives peut différer'; 
  • extensions/BatchDownloader/template/init_zip.tpl

    r16400 r16609  
    2020 
    2121 
     22{if $set} 
    2223<fieldset> 
    2324  <legend>{'Download info'|@translate}</legend> 
     
    2728  <ul class="set-infos"> 
    2829    <li class="error">{$elements_error}</li> 
    29     <li><b>{'%d images'|@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> 
     30    <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> 
    3031    <li><b>{'Estimated size'|@translate}:</b> {$set.TOTAL_SIZE} MB</li> 
    3132    <li><b>{'Estimated number of archives'|@translate}:</b> {$set.NB_ARCHIVES} <i>({'real number of archives can differ'|@translate})</i></li> 
    3233    <li><b>{'Created on'|@translate}:</b> {$set.DATE_CREATION}</li> 
    3334  </ul> 
    34    
    35    
    3635</fieldset> 
    37  
    3836 
    3937<fieldset> 
     
    4543  </ul> 
    4644   
    47   {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} 
     45  <a href="{$set.U_CANCEL}" class="cancel-down" onClick="return confirm('{'Are you sure?'|@translate}');">{'Cancel this download'|@translate}</a> 
    4846</fieldset> 
     47{/if} 
    4948 
    5049</div>{* <!-- content --> *} 
  • extensions/BatchDownloader/template/view.tpl

    r16379 r16609  
    1414  <h3>{$set.NAME}</h3> 
    1515  {if $set.COMMENT}<blockquote>{$set.COMMENT}</blockquote>{/if} 
    16   <span>{'%d images'|@translate|@sprintf:$set.NB_IMAGES}</span> 
     16  {'Nb images'|@translate}: <span class="nbImages">{$set.NB_IMAGES}</span> 
    1717</p> 
    1818 
Note: See TracChangeset for help on using the changeset viewer.