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

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

add four functions in filename_pattern : escape, upper, lower, strpad

File size: 3.1 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        return false;
36      }
37      break;
38    case 'tags':
39      $batch_type = 'tags';
40      $batch_id = implode(',', array_map(create_function('$t', 'return $t["id"];'), $page['tags']));
41      break;
42    case 'search':
43      $batch_type = 'search';
44      $batch_id = $page['search'];
45      break;
46    case 'collections':
47      if (in_array(@$page['sub_section'], array('view','edit')))
48      {
49        $batch_type = 'collection';
50        $batch_id = $page['col_id'];
51      }
52      break;
53    case 'favorites':
54    case 'most_visited':
55    case 'best_rated':
56    case 'list':
57    case 'recent_pics':
58      $batch_type = $page['section'];
59      $batch_id = null;
60      break;
61    default:
62      return false;
63  }
64 
65  $set = array(
66    'type' => $batch_type,
67    'id' => $batch_id,
68    'size' => !empty($_GET['down_size']) ? $_GET['down_size'] : 'original',
69    'items' => $page['items'],
70    );
71   
72  return trigger_event('batchdownload_get_set_info', $set);
73}
74
75/**
76 * check is current user can use BatchDownloader
77 * @return: boolean
78 */
79function check_download_access()
80{
81  global $user, $conf;
82 
83  if (is_a_guest()) return false;
84  if (is_admin()) return true;
85 
86  if ($user['level'] < $conf['batch_download']['level']) return false;
87 
88  if (!empty($conf['batch_download']['groups']))
89  {
90    $query = '
91SELECT 1 FROM '.USER_GROUP_TABLE.'
92  WHERE
93    user_id = '.$user['id'].'
94    AND group_id IN('.implode(',', $conf['batch_download']['groups']).')
95;';
96    $result = pwg_query($query);
97   
98    if (!pwg_db_num_rows($result)) return false;
99  }
100 
101  return true;
102}
103
104// https://bugs.php.net/bug.php?id=61636
105function readlargefile($fullfile)
106{
107  $fp = fopen($fullfile, 'rb');
108
109  if ($fp)
110  {
111    while (!feof($fp))
112    {
113      print(fread($fp, 2097152));
114    }
115
116    fclose($fp);
117  }
118}
119
120if (!function_exists('str2lower'))
121{
122  if (function_exists('mb_strtolower') && defined('PWG_CHARSET'))
123  {
124    function str2lower($term)
125    {
126      return mb_strtolower($term, PWG_CHARSET);
127    }
128    function str2upper($term)
129    {
130      return mb_strtoupper($term, PWG_CHARSET);
131    }
132  }
133  else
134  {
135    function str2lower($term)
136    {
137      return strtolower($term);
138    }
139    function str2upper($term)
140    {
141      return strtoupper($term);
142    }
143  }
144}
145
146?>
Note: See TracBrowser for help on using the repository browser.