source: extensions/BatchDownloader/include/download.inc.php @ 23383

Last change on this file since 23383 was 23383, checked in by mistic100, 11 years ago

new parameters on config screen "photo_size", "one_archive", "force_pclzip", "direct"

File size: 6.4 KB
Line 
1<?php
2defined('BATCH_DOWNLOAD_PATH') or die('Hacking attempt!');
3
4# this file is called on public page #
5
6global $page, $template, $conf, $user;
7
8switch ($page['sub_section'])
9{
10  /* download page */
11  case 'init_zip':
12  {
13    $template->set_filename('index', realpath(BATCH_DOWNLOAD_PATH . 'template/init_zip.tpl'));
14   
15    try
16    {
17      $BatchDownloader = new BatchDownloader($_GET['set_id']);
18     
19      // delete set
20      if ( isset($_GET['cancel']) )
21      {
22        $BatchDownloader->deleteArchives();
23        $BatchDownloader->clearImages();
24        pwg_query('DELETE FROM '.BATCH_DOWNLOAD_TSETS.' WHERE id = '.$_GET['set_id'].';');
25        $_SESSION['page_infos'][] = l10n('Download set deleted');
26        redirect(get_absolute_root_url());
27      }
28     
29      // prepare next zip
30      if ( isset($_GET['zip']) and $BatchDownloader->getParam('status') != 'new' and $BatchDownloader->getParam('status') != 'done' )
31      {
32        if ($_GET['zip'] > $BatchDownloader->getParam('last_zip'))
33        {
34          if ($conf['batch_download']['one_archive']) $BatchDownloader->deleteArchives();
35          $BatchDownloader->createNextArchive();
36        }
37       
38        if ($conf['batch_download']['one_archive'])
39        {
40          $next_file = $BatchDownloader->getParam('last_zip')+1;
41        }
42        else
43        {
44          $next_file = $_GET['zip'];
45        }
46      }
47     
48      // alert limit overflow
49      if ($BatchDownloader->getParam('nb_images') > $conf['batch_download']['max_elements'])
50      {
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.'),
53          $BatchDownloader->getParam('nb_images'),
54          $conf['batch_download']['max_elements'],
55          $BatchDownloader->getParam('nb_images') - $conf['batch_download']['max_elements']
56          ));
57      }
58      else
59      {
60        if ($BatchDownloader->getParam('status') == 'new')
61        {
62          $missing_derivatives = $BatchDownloader->getMissingDerivatives(true);
63       
64          // generate missing files
65          if (count($missing_derivatives))
66          {
67            $template->assign('missing_derivatives', $missing_derivatives);
68          }
69          // set is ready
70          else
71          {
72            $BatchDownloader->updateParam('status', 'ready');
73          }
74        }
75       
76        // display download links
77        if ($BatchDownloader->getParam('status') != 'new')
78        {
79          $template->assign('zip_links', $BatchDownloader->getDownloadList(BATCH_DOWNLOAD_PUBLIC . 'init_zip'));
80        }
81      }
82     
83      $set = $BatchDownloader->getSetInfo();
84     
85      // link to the zip
86      if (isset($next_file))
87      {
88        $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']);
90      }
91     
92      // link to edit page
93      if ($BatchDownloader->getParam('status') != 'download' and $BatchDownloader->getParam('status') != 'done' and $BatchDownloader->getParam('nb_images') > 0)
94      {
95        $set['U_EDIT_SET'] = add_url_params(BATCH_DOWNLOAD_PUBLIC . 'view', array('set_id'=>$_GET['set_id']));
96      }
97     
98      // cancel link
99      if ($BatchDownloader->getParam('last_zip') != $BatchDownloader->getParam('nb_zip'))
100      {
101        $set['U_CANCEL'] = add_url_params(BATCH_DOWNLOAD_PUBLIC . 'init_zip', array('set_id'=>$_GET['set_id'], 'cancel'=>'true'));
102      }
103     
104      $template->assign(array(
105        'set' => $set,
106        'archive_timeout' => $conf['batch_download']['archive_timeout'],
107        ));
108    }
109    catch (Exception $e)
110    {
111      array_push($page['errors'], $e->getMessage());
112    }
113   
114    break;
115  }
116 
117  /* edition page */
118  case 'view':
119  {
120    $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'));
123    $template->assign(array(
124      'BATCH_DOWNLOAD_PATH' => BATCH_DOWNLOAD_PATH,
125      'U_VIEW' => $self_url,
126      'U_INIT_ZIP' => add_url_params(BATCH_DOWNLOAD_PUBLIC . 'init_zip', array('set_id'=>$_GET['set_id'])),
127      'SET_ID' => $_GET['set_id'],
128      ));
129   
130    try
131    {
132      $BatchDownloader = new BatchDownloader($_GET['set_id']);
133     
134      if ($BatchDownloader->getParam('status') != 'new' && $BatchDownloader->getParam('status') != 'ready')
135      {
136        array_push($page['errors'], l10n('You can not edit this set'));
137        break;
138      }
139     
140      if ( isset($_GET['remove']) and preg_match('#^[0-9]+$#', $_GET['remove']) )
141      {
142        $BatchDownloader->removeImages(array($_GET['remove']));
143      }
144     
145      $template->assign('set', $BatchDownloader->getSetInfo());
146     
147      $template->set_prefilter('index_thumbnails', 'batch_download_thumbnails_list_prefilter');
148     
149      $page['start'] = isset($_GET['start']) ? $_GET['start'] : 0;
150      $page['items'] = array_keys($BatchDownloader->getImages());
151     
152      if (count($page['items']) > $page['nb_image_page'])
153      {
154        $page['navigation_bar'] = create_navigation_bar(
155          $self_url,
156          count($page['items']),
157          $page['start'],
158          $page['nb_image_page'],
159          false
160          );
161        $template->assign('navbar', $page['navigation_bar']);
162      }
163     
164      include(PHPWG_ROOT_PATH . 'include/category_default.inc.php');
165    }
166    catch (Exception $e)
167    {
168      array_push($page['errors'], $e->getMessage());
169    }
170   
171    break;
172  }
173}
174
175$template->assign(array(
176  'BATCH_DOWNLOAD_PATH' => BATCH_DOWNLOAD_PATH,
177  'BATCH_DOWNLOAD_ABS_PATH' => realpath(BATCH_DOWNLOAD_PATH).'/',
178  ));
179
180
181function batch_download_thumbnails_list_prefilter($content, &$smarty)
182{
183  // add links
184  $search = '#(<li>|<li class="gthumb">)#';
185  $replace = '$1
186{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}">
188</a>{/strip}';
189
190  // custom CSS and AJAX request
191  $content.= file_get_contents(BATCH_DOWNLOAD_PATH.'template/thumbnails_css_js.tpl');
192
193  return preg_replace($search, $replace, $content);
194}
195
196?>
Note: See TracBrowser for help on using the repository browser.