[16379] | 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 | |
---|
[16609] | 15 | try |
---|
[16379] | 16 | { |
---|
[16609] | 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 | } |
---|
[16626] | 33 | |
---|
[16609] | 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'].'&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 | |
---|
[16626] | 42 | if ($BatchDownloader->getParam('status') == 'new' and $BatchDownloader->getParam('nb_images') > 0) |
---|
| 43 | { |
---|
| 44 | $set['U_EDIT_SET'] = BATCH_DOWNLOAD_PUBLIC . 'view&set_id='.$_GET['set_id']; |
---|
| 45 | } |
---|
| 46 | |
---|
[16609] | 47 | if ($BatchDownloader->getParam('nb_images') > $conf['batch_download']['max_elements']) |
---|
| 48 | { |
---|
| 49 | $template->assign('elements_error', sprintf( |
---|
| 50 | 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.'), |
---|
| 51 | $BatchDownloader->getParam('nb_images'), |
---|
| 52 | $conf['batch_download']['max_elements'], |
---|
| 53 | $BatchDownloader->getParam('nb_images') - $conf['batch_download']['max_elements'] |
---|
| 54 | )); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | $set['U_CANCEL'] = BATCH_DOWNLOAD_PUBLIC . 'init_zip&set_id='.$_GET['set_id'].'&cancel'; |
---|
| 58 | |
---|
| 59 | $template->assign(array( |
---|
| 60 | 'set' => $set, |
---|
| 61 | 'archive_timeout' => $conf['batch_download']['archive_timeout'], |
---|
[16379] | 62 | )); |
---|
| 63 | } |
---|
[16609] | 64 | catch (Exception $e) |
---|
[16392] | 65 | { |
---|
[16609] | 66 | array_push($page['errors'], $e->getMessage()); |
---|
[16392] | 67 | } |
---|
| 68 | |
---|
[16379] | 69 | break; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | /* edition page */ |
---|
| 73 | case 'view': |
---|
[16592] | 74 | { |
---|
[16379] | 75 | $self_url = BATCH_DOWNLOAD_PUBLIC . 'view&set_id='.$_GET['set_id']; |
---|
| 76 | |
---|
| 77 | $template->set_filename('index', dirname(__FILE__).'/../template/view.tpl'); |
---|
| 78 | $template->assign(array( |
---|
| 79 | 'BATCH_DOWNLOAD_PATH' => BATCH_DOWNLOAD_PATH, |
---|
| 80 | 'U_VIEW' => $self_url, |
---|
| 81 | 'U_INIT_ZIP' => BATCH_DOWNLOAD_PUBLIC . 'init_zip&set_id='.$_GET['set_id'], |
---|
[16609] | 82 | 'SET_ID' => $_GET['set_id'], |
---|
[16379] | 83 | )); |
---|
| 84 | |
---|
[16609] | 85 | try |
---|
[16379] | 86 | { |
---|
[16609] | 87 | $BatchDownloader = new BatchDownloader($_GET['set_id']); |
---|
| 88 | |
---|
| 89 | if ($BatchDownloader->getParam('status') != 'new') |
---|
| 90 | { |
---|
| 91 | array_push($page['errors'], l10n('You can not edit this set')); |
---|
| 92 | break; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | if ( isset($_GET['remove']) and preg_match('#^[0-9]+$#', $_GET['remove']) ) |
---|
| 96 | { |
---|
| 97 | $BatchDownloader->removeImages(array($_GET['remove'])); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | $template->assign('set', $BatchDownloader->getSetInfo()); |
---|
| 101 | |
---|
| 102 | $template->set_prefilter('index_thumbnails', 'batch_download_thumbnails_list_prefilter'); |
---|
| 103 | |
---|
| 104 | $page['start'] = isset($_GET['start']) ? $_GET['start'] : 0; |
---|
| 105 | $page['items'] = array_keys($BatchDownloader->getImages()); |
---|
| 106 | |
---|
| 107 | if (count($page['items']) > $page['nb_image_page']) |
---|
| 108 | { |
---|
| 109 | $page['navigation_bar'] = create_navigation_bar( |
---|
| 110 | $self_url, |
---|
| 111 | count($page['items']), |
---|
| 112 | $page['start'], |
---|
| 113 | $page['nb_image_page'], |
---|
| 114 | false |
---|
| 115 | ); |
---|
| 116 | $template->assign('navbar', $page['navigation_bar']); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | include(PHPWG_ROOT_PATH . 'include/category_default.inc.php'); |
---|
[16379] | 120 | } |
---|
[16609] | 121 | catch (Exception $e) |
---|
[16379] | 122 | { |
---|
[16609] | 123 | array_push($page['errors'], $e->getMessage()); |
---|
[16379] | 124 | } |
---|
| 125 | |
---|
[16592] | 126 | break; |
---|
| 127 | } |
---|
[16379] | 128 | } |
---|
| 129 | |
---|
[16392] | 130 | $template->assign('BATCH_DOWNLOAD_PATH', BATCH_DOWNLOAD_PATH); |
---|
[16379] | 131 | |
---|
[16392] | 132 | |
---|
[16379] | 133 | function batch_download_thumbnails_list_prefilter($content, &$smarty) |
---|
| 134 | { |
---|
[16626] | 135 | // add links |
---|
| 136 | $search = '<span class="wrap1">'; |
---|
| 137 | $replace = $search.' |
---|
[16609] | 138 | {strip}<a class="removeSet" href="{$U_VIEW}&remove={$thumbnail.id}" data-id="{$thumbnail.id}" rel="nofollow"> |
---|
| 139 | {\'Remove from download set\'|@translate} <img src="{$BATCH_DOWNLOAD_PATH}template/image_delete.png" title="{\'Remove from download set\'|@translate}"> |
---|
| 140 | </a>{/strip}'; |
---|
| 141 | |
---|
[16626] | 142 | // custom CSS and AJAX request |
---|
| 143 | $content.= file_get_contents(BATCH_DOWNLOAD_PATH.'template/thumbnails_css_js.tpl'); |
---|
[16379] | 144 | |
---|
[16609] | 145 | return str_replace($search, $replace, $content); |
---|
[16379] | 146 | } |
---|
| 147 | |
---|
| 148 | ?> |
---|