1 | <?php |
---|
2 | defined('BATCH_DOWNLOAD_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | # this file is called on public page # |
---|
5 | |
---|
6 | global $page, $template, $conf, $user; |
---|
7 | |
---|
8 | switch ($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->clear(); |
---|
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'].'&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&set_id='.$_GET['set_id'].'&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 | $self_url = BATCH_DOWNLOAD_PUBLIC . 'view&set_id='.$_GET['set_id']; |
---|
66 | |
---|
67 | $template->set_filename('index', dirname(__FILE__).'/../template/view.tpl'); |
---|
68 | $template->assign(array( |
---|
69 | 'BATCH_DOWNLOAD_PATH' => BATCH_DOWNLOAD_PATH, |
---|
70 | 'U_VIEW' => $self_url, |
---|
71 | 'U_INIT_ZIP' => BATCH_DOWNLOAD_PUBLIC . 'init_zip&set_id='.$_GET['set_id'], |
---|
72 | )); |
---|
73 | |
---|
74 | $BatchDownloader = new BatchDownloader($_GET['set_id']); |
---|
75 | |
---|
76 | if ($BatchDownloader->getParam('status') != 'new') |
---|
77 | { |
---|
78 | array_push($page['errors'], l10n('You can not edit this set')); |
---|
79 | break; |
---|
80 | } |
---|
81 | |
---|
82 | if ( isset($_GET['remove']) and preg_match('#^[0-9]+$#', $_GET['remove']) ) |
---|
83 | { |
---|
84 | $BatchDownloader->removeImages(array($_GET['remove'])); |
---|
85 | } |
---|
86 | |
---|
87 | $template->assign('set', $BatchDownloader->getSetInfo()); |
---|
88 | |
---|
89 | $template->set_prefilter('index_thumbnails', 'batch_download_thumbnails_list_prefilter'); |
---|
90 | |
---|
91 | $page['start'] = isset($_GET['start']) ? $_GET['start'] : 0; |
---|
92 | $page['items'] = array_keys($BatchDownloader->getImages()); |
---|
93 | |
---|
94 | if (count($page['items']) > $page['nb_image_page']) |
---|
95 | { |
---|
96 | $page['navigation_bar'] = create_navigation_bar( |
---|
97 | $self_url, |
---|
98 | count($page['items']), |
---|
99 | $page['start'], |
---|
100 | $page['nb_image_page'], |
---|
101 | false |
---|
102 | ); |
---|
103 | $template->assign('navbar', $page['navigation_bar']); |
---|
104 | } |
---|
105 | |
---|
106 | include(PHPWG_ROOT_PATH . 'include/category_default.inc.php'); |
---|
107 | |
---|
108 | break; |
---|
109 | } |
---|
110 | |
---|
111 | $template->assign('BATCH_DOWNLOAD_PATH', BATCH_DOWNLOAD_PATH); |
---|
112 | |
---|
113 | |
---|
114 | function batch_download_thumbnails_list_prefilter($content, &$smarty) |
---|
115 | { |
---|
116 | $search = '<span class="thumbName">'; |
---|
117 | |
---|
118 | $add = '<a href="{$U_VIEW}&remove={$thumbnail.id}"> |
---|
119 | <img src="{$BATCH_DOWNLOAD_PATH}template/image_delete.png" title="{\'Remove from download set\'|@translate}"> |
---|
120 | </a> '; |
---|
121 | |
---|
122 | return str_replace($search, $search.$add, $content); |
---|
123 | } |
---|
124 | |
---|
125 | ?> |
---|