[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 | { |
---|
[23291] | 13 | $template->set_filename('index', realpath(BATCH_DOWNLOAD_PATH . 'template/init_zip.tpl')); |
---|
[16379] | 14 | |
---|
[16609] | 15 | try |
---|
[16379] | 16 | { |
---|
[16609] | 17 | $BatchDownloader = new BatchDownloader($_GET['set_id']); |
---|
| 18 | |
---|
[23290] | 19 | // delete set |
---|
[16609] | 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'); |
---|
[17915] | 26 | redirect(get_absolute_root_url()); |
---|
[16609] | 27 | } |
---|
| 28 | |
---|
[23290] | 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') ) |
---|
[16609] | 31 | { |
---|
| 32 | $BatchDownloader->deleteLastArchive(); |
---|
| 33 | $next_file = $BatchDownloader->createNextArchive(); |
---|
| 34 | } |
---|
[16626] | 35 | |
---|
[23290] | 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 | } |
---|
[23291] | 57 | // set is ready |
---|
[23290] | 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 | |
---|
[16609] | 71 | $set = $BatchDownloader->getSetInfo(); |
---|
| 72 | |
---|
[23290] | 73 | // link to the zip |
---|
[16609] | 74 | if (isset($next_file)) |
---|
| 75 | { |
---|
[17177] | 76 | $set['U_DOWNLOAD'] = get_root_url().BATCH_DOWNLOAD_PATH . 'download.php?set_id='.$_GET['set_id'].'&zip='.$_GET['zip']; |
---|
[23290] | 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']); |
---|
[16609] | 78 | } |
---|
| 79 | |
---|
[23290] | 80 | // link to edit page |
---|
| 81 | if ($BatchDownloader->getParam('status') != 'download' and $BatchDownloader->getParam('status') != 'done' and $BatchDownloader->getParam('nb_images') > 0) |
---|
[16626] | 82 | { |
---|
[17177] | 83 | $set['U_EDIT_SET'] = add_url_params(BATCH_DOWNLOAD_PUBLIC . 'view', array('set_id'=>$_GET['set_id'])); |
---|
[16626] | 84 | } |
---|
| 85 | |
---|
[23290] | 86 | // cancel link |
---|
| 87 | if ($BatchDownloader->getParam('status') != 'done') |
---|
[16609] | 88 | { |
---|
[23290] | 89 | $set['U_CANCEL'] = add_url_params(BATCH_DOWNLOAD_PUBLIC . 'init_zip', array('set_id'=>$_GET['set_id'], 'cancel'=>'true')); |
---|
[16609] | 90 | } |
---|
| 91 | |
---|
| 92 | $template->assign(array( |
---|
| 93 | 'set' => $set, |
---|
| 94 | 'archive_timeout' => $conf['batch_download']['archive_timeout'], |
---|
[16379] | 95 | )); |
---|
| 96 | } |
---|
[16609] | 97 | catch (Exception $e) |
---|
[16392] | 98 | { |
---|
[16609] | 99 | array_push($page['errors'], $e->getMessage()); |
---|
[16392] | 100 | } |
---|
| 101 | |
---|
[16379] | 102 | break; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | /* edition page */ |
---|
| 106 | case 'view': |
---|
[16592] | 107 | { |
---|
[17177] | 108 | $self_url = add_url_params(BATCH_DOWNLOAD_PUBLIC . 'view', array('set_id'=>$_GET['set_id'])); |
---|
[16379] | 109 | |
---|
[23291] | 110 | $template->set_filename('index', realpath(BATCH_DOWNLOAD_PATH . 'template/view.tpl')); |
---|
[16379] | 111 | $template->assign(array( |
---|
| 112 | 'BATCH_DOWNLOAD_PATH' => BATCH_DOWNLOAD_PATH, |
---|
| 113 | 'U_VIEW' => $self_url, |
---|
[17177] | 114 | 'U_INIT_ZIP' => add_url_params(BATCH_DOWNLOAD_PUBLIC . 'init_zip', array('set_id'=>$_GET['set_id'])), |
---|
[16609] | 115 | 'SET_ID' => $_GET['set_id'], |
---|
[16379] | 116 | )); |
---|
| 117 | |
---|
[16609] | 118 | try |
---|
[16379] | 119 | { |
---|
[16609] | 120 | $BatchDownloader = new BatchDownloader($_GET['set_id']); |
---|
| 121 | |
---|
[23291] | 122 | if ($BatchDownloader->getParam('status') != 'new' && $BatchDownloader->getParam('status') != 'ready') |
---|
[16609] | 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'); |
---|
[16379] | 153 | } |
---|
[16609] | 154 | catch (Exception $e) |
---|
[16379] | 155 | { |
---|
[16609] | 156 | array_push($page['errors'], $e->getMessage()); |
---|
[16379] | 157 | } |
---|
| 158 | |
---|
[16592] | 159 | break; |
---|
| 160 | } |
---|
[16379] | 161 | } |
---|
| 162 | |
---|
[17492] | 163 | $template->assign(array( |
---|
| 164 | 'BATCH_DOWNLOAD_PATH' => BATCH_DOWNLOAD_PATH, |
---|
| 165 | 'BATCH_DOWNLOAD_ABS_PATH' => realpath(BATCH_DOWNLOAD_PATH).'/', |
---|
| 166 | )); |
---|
[16379] | 167 | |
---|
[16392] | 168 | |
---|
[16379] | 169 | function batch_download_thumbnails_list_prefilter($content, &$smarty) |
---|
| 170 | { |
---|
[16626] | 171 | // add links |
---|
[21206] | 172 | $search = '#(<li>|<li class="gthumb">)#'; |
---|
| 173 | $replace = '$1 |
---|
[16609] | 174 | {strip}<a class="removeSet" href="{$U_VIEW}&remove={$thumbnail.id}" data-id="{$thumbnail.id}" rel="nofollow"> |
---|
[23323] | 175 | {\'Remove from download set\'|@translate} <img src="{$ROOT_URL}{$BATCH_DOWNLOAD_PATH}template/images/image_delete.png" title="{\'Remove from download set\'|@translate}"> |
---|
[16609] | 176 | </a>{/strip}'; |
---|
| 177 | |
---|
[16626] | 178 | // custom CSS and AJAX request |
---|
| 179 | $content.= file_get_contents(BATCH_DOWNLOAD_PATH.'template/thumbnails_css_js.tpl'); |
---|
[16379] | 180 | |
---|
[21206] | 181 | return preg_replace($search, $replace, $content); |
---|
[16379] | 182 | } |
---|
| 183 | |
---|
| 184 | ?> |
---|