Ignore:
Timestamp:
Jul 11, 2012, 12:58:19 PM (12 years ago)
Author:
mistic100
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.