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

Last change on this file since 16592 was 16592, checked in by mistic100, 12 years ago

-compatiblity with UserCollections
-don't crash for non-admin users (sic)

File size: 4.0 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', dirname(__FILE__) . '/../template/init_zip.tpl');
14   
15    $BatchDownloader = new BatchDownloader($_GET['set_id']);
16   
17    if ( isset($_GET['cancel']) )
18    {
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    }
31
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'].'&amp;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']
47        ));
48    }
49   
50    if ($BatchDownloader->getParam('status') == 'new')
51    {
52      $set['U_CANCEL'] = BATCH_DOWNLOAD_PUBLIC . 'init_zip&amp;set_id='.$_GET['set_id'].'&amp;cancel';
53    }
54   
55    $template->assign(array(
56      'set' => $set,
57      'archive_timeout' => $conf['batch_download']['archive_timeout'],
58      ));
59   
60    break;
61  }
62 
63  /* edition page */
64  case 'view':
65  {
66    $self_url = BATCH_DOWNLOAD_PUBLIC . 'view&amp;set_id='.$_GET['set_id'];
67   
68    $template->set_filename('index', dirname(__FILE__).'/../template/view.tpl');
69    $template->assign(array(
70      'BATCH_DOWNLOAD_PATH' => BATCH_DOWNLOAD_PATH,
71      'U_VIEW' => $self_url,
72      'U_INIT_ZIP' => BATCH_DOWNLOAD_PUBLIC . 'init_zip&amp;set_id='.$_GET['set_id'],
73      ));
74   
75    $BatchDownloader = new BatchDownloader($_GET['set_id']);
76   
77    if ($BatchDownloader->getParam('status') != 'new')
78    {
79      array_push($page['errors'], l10n('You can not edit this set'));
80      break;
81    }
82   
83    if ( isset($_GET['remove']) and preg_match('#^[0-9]+$#', $_GET['remove']) )
84    {
85      $BatchDownloader->removeImages(array($_GET['remove']));
86    }
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');
108   
109    break;
110  }
111}
112
113$template->assign('BATCH_DOWNLOAD_PATH', BATCH_DOWNLOAD_PATH);
114
115
116function batch_download_thumbnails_list_prefilter($content, &$smarty)
117{
118  $search = '<span class="thumbName">';
119 
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;';
123
124  return str_replace($search, $search.$add, $content);
125}
126
127?>
Note: See TracBrowser for help on using the repository browser.