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

Last change on this file since 21206 was 21206, checked in by mistic100, 11 years ago

-define body_id and fix breadcrumb
-fix edit page with simple and gthumb+

File size: 5.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    try
16    {
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(get_absolute_root_url());
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      }
33     
34      $set = $BatchDownloader->getSetInfo();
35     
36      if (isset($next_file))
37      {
38        $set['U_DOWNLOAD'] = get_root_url().BATCH_DOWNLOAD_PATH . 'download.php?set_id='.$_GET['set_id'].'&amp;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     
42      if ($BatchDownloader->getParam('status') == 'new' and $BatchDownloader->getParam('nb_images') > 0)
43      {
44        $set['U_EDIT_SET'] = add_url_params(BATCH_DOWNLOAD_PUBLIC . 'view', array('set_id'=>$_GET['set_id']));
45      }
46     
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'] = add_url_params(BATCH_DOWNLOAD_PUBLIC . 'init_zip', array('set_id'=>$_GET['set_id'], 'cancel'=>'true'));
58     
59      $template->assign(array(
60        'set' => $set,
61        'archive_timeout' => $conf['batch_download']['archive_timeout'],
62        ));
63    }
64    catch (Exception $e)
65    {
66      array_push($page['errors'], $e->getMessage());
67    }
68   
69    break;
70  }
71 
72  /* edition page */
73  case 'view':
74  {
75    $self_url = add_url_params(BATCH_DOWNLOAD_PUBLIC . 'view', array('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' => add_url_params(BATCH_DOWNLOAD_PUBLIC . 'init_zip', array('set_id'=>$_GET['set_id'])),
82      'SET_ID' => $_GET['set_id'],
83      ));
84   
85    try
86    {
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');
120    }
121    catch (Exception $e)
122    {
123      array_push($page['errors'], $e->getMessage());
124    }
125   
126    break;
127  }
128}
129
130$template->assign(array(
131  'BATCH_DOWNLOAD_PATH' => BATCH_DOWNLOAD_PATH,
132  'BATCH_DOWNLOAD_ABS_PATH' => realpath(BATCH_DOWNLOAD_PATH).'/',
133  ));
134
135
136function batch_download_thumbnails_list_prefilter($content, &$smarty)
137{
138  // add links
139  $search = '#(<li>|<li class="gthumb">)#';
140  $replace = '$1
141{strip}<a class="removeSet" href="{$U_VIEW}&amp;remove={$thumbnail.id}" data-id="{$thumbnail.id}" rel="nofollow">
142{\'Remove from download set\'|@translate}&nbsp;<img src="{$ROOT_URL}{$BATCH_DOWNLOAD_PATH}template/image_delete.png" title="{\'Remove from download set\'|@translate}">
143</a>{/strip}';
144
145  // custom CSS and AJAX request
146  $content.= file_get_contents(BATCH_DOWNLOAD_PATH.'template/thumbnails_css_js.tpl');
147
148  return preg_replace($search, $replace, $content);
149}
150
151?>
Note: See TracBrowser for help on using the repository browser.