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

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

first commit, not complete
TODO : use multisize, download history, localization, compatibility with User Selection (and create User Selection !!)

File size: 3.5 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 ($BatchDownloader->getParam('status') != 'done')
18    {
19      if (isset($_GET['zip']))
20      {
21        $BatchDownloader->deleteLastArchive();
22        $next_file = $BatchDownloader->createNextArchive();
23      }
24      else
25      {
26        $BatchDownloader->getEstimatedArchiveNumber();
27      }
28    }
29
30    $set = $BatchDownloader->getSetInfo();
31   
32    if (isset($next_file))
33    {
34      $set['U_DOWNLOAD'] = BATCH_DOWNLOAD_PATH . 'download.php?set_id='.$_GET['set_id'].'&amp;zip='.$_GET['zip'];
35      array_push($page['infos'], sprintf(l10n('Archive #%d is downloading, if the download doesn\'t start automatically please <a href="%s">click here</a>'), $_GET['zip'], $set['U_DOWNLOAD']));
36    }
37   
38    if ($BatchDownloader->getParam('nb_images') > $conf['batch_download']['max_elements'])
39    {
40      array_push($page['errors'], sprintf(
41        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.'),
42        $BatchDownloader->getParam('nb_images'),
43        $conf['batch_download']['max_elements'],
44        $BatchDownloader->getParam('nb_images') - $conf['batch_download']['max_elements']
45        ));
46    }
47   
48    $template->assign(array(
49      'set' => $set,
50      'archive_timeout' => $conf['batch_download']['archive_timeout'],
51      ));
52   
53    break;
54  }
55 
56  /* edition page */
57  case 'view':
58    $self_url = BATCH_DOWNLOAD_PUBLIC . 'view&amp;set_id='.$_GET['set_id'];
59   
60    $template->set_filename('index', dirname(__FILE__).'/../template/view.tpl');
61    $template->assign(array(
62      'BATCH_DOWNLOAD_PATH' => BATCH_DOWNLOAD_PATH,
63      'U_VIEW' => $self_url,
64      'U_INIT_ZIP' => BATCH_DOWNLOAD_PUBLIC . 'init_zip&amp;set_id='.$_GET['set_id'],
65      ));
66   
67    $BatchDownloader = new BatchDownloader($_GET['set_id']);
68   
69    if ($BatchDownloader->getParam('status') != 'new')
70    {
71      array_push($page['errors'], l10n('You can not edit this set'));
72      break;
73    }
74   
75    if ( isset($_GET['remove']) and preg_match('#^[0-9]+$#', $_GET['remove']) )
76    {
77      $BatchDownloader->removeImages(array($_GET['remove']));
78    }
79   
80    $template->assign('set', $BatchDownloader->getSetInfo());
81   
82    $template->set_prefilter('index_thumbnails', 'batch_download_thumbnails_list_prefilter');
83   
84    $page['start'] = isset($_GET['start']) ? $_GET['start'] : 0;
85    $page['items'] = array_keys($BatchDownloader->getImages());
86   
87    if (count($page['items']) > $page['nb_image_page'])
88    {
89      $page['navigation_bar'] = create_navigation_bar(
90        $self_url,
91        count($page['items']),
92        $page['start'],
93        $page['nb_image_page'],
94        false
95        );
96      $template->assign('navbar', $page['navigation_bar']);
97    }
98   
99    include(PHPWG_ROOT_PATH . 'include/category_default.inc.php');
100   
101    break;   
102}
103
104
105function batch_download_thumbnails_list_prefilter($content, &$smarty)
106{
107  $search = '<span class="thumbName">';
108 
109  $add = '<a href="{$U_VIEW}&amp;remove={$thumbnail.id}">
110<img src="{$BATCH_DOWNLOAD_PATH}template/image_delete.png" title="{\'Remove from download set\'|@translate}">
111</a>&nbsp;';
112
113  return str_replace($search, $search.$add, $content);
114}
115
116?>
Note: See TracBrowser for help on using the repository browser.