source: extensions/BatchDownloader/include/functions.inc.php @ 23290

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

WORK IN PROGRESS: allow to download derivatives
TODO: only working with images files, finish download page

File size: 2.6 KB
Line 
1<?php
2defined('BATCH_DOWNLOAD_PATH') or die('Hacking attempt!');
3
4/**
5 * get BatchDownloader type and type_id from page info
6 * @return: array or false
7 */
8function get_set_info_from_page()
9{
10  global $page;
11 
12  switch ($page['section'])
13  {
14    case 'categories':
15      if (isset($page['chronology_field']))
16      {
17        $batch_type = 'calendar';
18        $batch_id = add_well_known_params_in_url('', 
19          array_intersect_key($page, 
20            array(
21              'chronology_field'=>0,
22              'chronology_style'=>0,
23              'chronology_view'=>0,
24              'chronology_date'=>0,
25          )));
26        $batch_id = ltrim($batch_id, '/');
27      }
28      else if (isset($page['category']))
29      {
30        $batch_type = 'category';
31        $batch_id = $page['category']['id'];
32      }
33      else if (isset($page['flat'])) // this is for the whole gallery only, flat mode for category is above
34      {
35        $batch_type = 'flat';
36        $batch_id = 0;
37      }
38      break;
39    case 'tags':
40      $batch_type = 'tags';
41      $batch_id = implode(',', array_map(create_function('$t', 'return $t["id"];'), $page['tags']));
42      break;
43    case 'search':
44      $batch_type = 'search';
45      $batch_id = $page['search'];
46      break;
47    case 'collections':
48      if (in_array(@$page['sub_section'], array('view','edit')))
49      {
50        $batch_type = 'collection';
51        $batch_id = $page['col_id'];
52      }
53      break;
54    case 'favorites':
55    case 'most_visited':
56    case 'best_rated':
57    case 'list':
58    case 'recent_pics':
59      $batch_type = $page['section'];
60      $batch_id = 0;
61      break;
62    default:
63      return false;
64  }
65 
66  return array(
67    'type' => $batch_type,
68    'id' => $batch_id,
69    'size' => isset($_GET['down_size']) ? $_GET['down_size'] : 'original',
70    );
71}
72
73/**
74 * check is current user can use BatchDownloader
75 * @return: boolean
76 */
77function check_download_access()
78{
79  global $user, $conf;
80 
81  if (is_a_guest()) return false;
82  if (is_admin()) return true;
83 
84  if ($user['level'] < $conf['batch_download']['level']) return false;
85 
86  if (!empty($conf['batch_download']['groups']))
87  {
88    $query = '
89SELECT 1 FROM '.USER_GROUP_TABLE.'
90  WHERE
91    user_id = '.$user['id'].'
92    AND group_id IN('.implode(',', $conf['batch_download']['groups']).')
93;';
94    $result = pwg_query($query);
95   
96    if (!pwg_db_num_rows($result)) return false;
97  }
98 
99  return true;
100}
101
102// https://bugs.php.net/bug.php?id=61636
103function readlargefile($fullfile)
104{
105  $fp = fopen($fullfile, 'rb');
106
107  if ($fp)
108  {
109    while (!feof($fp))
110    {
111      print(fread($fp, 2097152));
112    }
113
114    fclose($fp);
115  }
116}
117
118?>
Note: See TracBrowser for help on using the repository browser.