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

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

move remove_image.php code to a trigger on init

File size: 6.1 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->deleteLastArchive();
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' and $_GET['zip'] > $BatchDownloader->getParam('last_zip') )
31      {
32        $BatchDownloader->deleteLastArchive();
33        $next_file = $BatchDownloader->createNextArchive();
34      }
35     
36      // alert limit overflow
37      if ($BatchDownloader->getParam('nb_images') > $conf['batch_download']['max_elements'])
38      {
39        $template->assign('elements_error', sprintf(
40          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.'),
41          $BatchDownloader->getParam('nb_images'),
42          $conf['batch_download']['max_elements'],
43          $BatchDownloader->getParam('nb_images') - $conf['batch_download']['max_elements']
44          ));
45      }
46      else
47      {
48        if ($BatchDownloader->getParam('status') == 'new')
49        {
50          $missing_derivatives = $BatchDownloader->getMissingDerivatives(true);
51       
52          // generate missing files
53          if (count($missing_derivatives))
54          {
55            $template->assign('missing_derivatives', $missing_derivatives);
56          }
57          // set is ready
58          else
59          {
60            $BatchDownloader->updateParam('status', 'ready');
61          }
62        }
63       
64        // display download links
65        if ($BatchDownloader->getParam('status') != 'new')
66        {
67          $template->assign('zip_links', $BatchDownloader->getDownloadList(BATCH_DOWNLOAD_PUBLIC . 'init_zip'));
68        }
69      }
70     
71      $set = $BatchDownloader->getSetInfo();
72     
73      // link to the zip
74      if (isset($next_file))
75      {
76        $set['U_DOWNLOAD'] = get_root_url().BATCH_DOWNLOAD_PATH . 'download.php?set_id='.$_GET['set_id'].'&amp;zip='.$_GET['zip'];
77        $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']);
78      }
79     
80      // link to edit page
81      if ($BatchDownloader->getParam('status') != 'download' and $BatchDownloader->getParam('status') != 'done' and $BatchDownloader->getParam('nb_images') > 0)
82      {
83        $set['U_EDIT_SET'] = add_url_params(BATCH_DOWNLOAD_PUBLIC . 'view', array('set_id'=>$_GET['set_id']));
84      }
85     
86      // cancel link
87      if ($BatchDownloader->getParam('status') != 'done')
88      {
89        $set['U_CANCEL'] = add_url_params(BATCH_DOWNLOAD_PUBLIC . 'init_zip', array('set_id'=>$_GET['set_id'], 'cancel'=>'true'));
90      }
91     
92      $template->assign(array(
93        'set' => $set,
94        'archive_timeout' => $conf['batch_download']['archive_timeout'],
95        ));
96    }
97    catch (Exception $e)
98    {
99      array_push($page['errors'], $e->getMessage());
100    }
101   
102    break;
103  }
104 
105  /* edition page */
106  case 'view':
107  {
108    $self_url = add_url_params(BATCH_DOWNLOAD_PUBLIC . 'view', array('set_id'=>$_GET['set_id']));
109   
110    $template->set_filename('index', realpath(BATCH_DOWNLOAD_PATH . 'template/view.tpl'));
111    $template->assign(array(
112      'BATCH_DOWNLOAD_PATH' => BATCH_DOWNLOAD_PATH,
113      'U_VIEW' => $self_url,
114      'U_INIT_ZIP' => add_url_params(BATCH_DOWNLOAD_PUBLIC . 'init_zip', array('set_id'=>$_GET['set_id'])),
115      'SET_ID' => $_GET['set_id'],
116      ));
117   
118    try
119    {
120      $BatchDownloader = new BatchDownloader($_GET['set_id']);
121     
122      if ($BatchDownloader->getParam('status') != 'new' && $BatchDownloader->getParam('status') != 'ready')
123      {
124        array_push($page['errors'], l10n('You can not edit this set'));
125        break;
126      }
127     
128      if ( isset($_GET['remove']) and preg_match('#^[0-9]+$#', $_GET['remove']) )
129      {
130        $BatchDownloader->removeImages(array($_GET['remove']));
131      }
132     
133      $template->assign('set', $BatchDownloader->getSetInfo());
134     
135      $template->set_prefilter('index_thumbnails', 'batch_download_thumbnails_list_prefilter');
136     
137      $page['start'] = isset($_GET['start']) ? $_GET['start'] : 0;
138      $page['items'] = array_keys($BatchDownloader->getImages());
139     
140      if (count($page['items']) > $page['nb_image_page'])
141      {
142        $page['navigation_bar'] = create_navigation_bar(
143          $self_url,
144          count($page['items']),
145          $page['start'],
146          $page['nb_image_page'],
147          false
148          );
149        $template->assign('navbar', $page['navigation_bar']);
150      }
151     
152      include(PHPWG_ROOT_PATH . 'include/category_default.inc.php');
153    }
154    catch (Exception $e)
155    {
156      array_push($page['errors'], $e->getMessage());
157    }
158   
159    break;
160  }
161}
162
163$template->assign(array(
164  'BATCH_DOWNLOAD_PATH' => BATCH_DOWNLOAD_PATH,
165  'BATCH_DOWNLOAD_ABS_PATH' => realpath(BATCH_DOWNLOAD_PATH).'/',
166  ));
167
168
169function batch_download_thumbnails_list_prefilter($content, &$smarty)
170{
171  // add links
172  $search = '#(<li>|<li class="gthumb">)#';
173  $replace = '$1
174{strip}<a class="removeSet" href="{$U_VIEW}&amp;remove={$thumbnail.id}" data-id="{$thumbnail.id}" rel="nofollow">
175{\'Remove from download set\'|@translate}&nbsp;<img src="{$ROOT_URL}{$BATCH_DOWNLOAD_PATH}template/images/image_delete.png" title="{\'Remove from download set\'|@translate}">
176</a>{/strip}';
177
178  // custom CSS and AJAX request
179  $content.= file_get_contents(BATCH_DOWNLOAD_PATH.'template/thumbnails_css_js.tpl');
180
181  return preg_replace($search, $replace, $content);
182}
183
184?>
Note: See TracBrowser for help on using the repository browser.