[16379] | 1 | <?php |
---|
| 2 | defined('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 | */ |
---|
| 8 | function get_set_info_from_page() |
---|
| 9 | { |
---|
[25931] | 10 | global $page, $conf; |
---|
[25932] | 11 | |
---|
[16379] | 12 | switch ($page['section']) |
---|
| 13 | { |
---|
| 14 | case 'categories': |
---|
| 15 | if (isset($page['chronology_field'])) |
---|
| 16 | { |
---|
| 17 | $batch_type = 'calendar'; |
---|
[25932] | 18 | $batch_id = add_well_known_params_in_url('', |
---|
| 19 | array_intersect_key($page, |
---|
[16379] | 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 | { |
---|
[23321] | 35 | return false; |
---|
[16379] | 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; |
---|
[16592] | 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; |
---|
[16379] | 53 | case 'favorites': |
---|
| 54 | case 'most_visited': |
---|
| 55 | case 'best_rated': |
---|
| 56 | case 'list': |
---|
| 57 | case 'recent_pics': |
---|
| 58 | $batch_type = $page['section']; |
---|
[23318] | 59 | $batch_id = null; |
---|
[16379] | 60 | break; |
---|
[23290] | 61 | default: |
---|
| 62 | return false; |
---|
[16379] | 63 | } |
---|
[25932] | 64 | |
---|
[23771] | 65 | $set = array( |
---|
[23290] | 66 | 'type' => $batch_type, |
---|
| 67 | 'id' => $batch_id, |
---|
[23291] | 68 | 'size' => !empty($_GET['down_size']) ? $_GET['down_size'] : 'original', |
---|
[23771] | 69 | 'items' => $page['items'], |
---|
[23290] | 70 | ); |
---|
[25932] | 71 | |
---|
[25931] | 72 | // check size |
---|
| 73 | if (!$conf['batch_download']['multisize']) |
---|
| 74 | { |
---|
| 75 | $set['size'] = $conf['batch_download']['photo_size']; |
---|
| 76 | } |
---|
| 77 | else |
---|
| 78 | { |
---|
| 79 | $avail_sizes = array(); |
---|
| 80 | foreach (ImageStdParams::get_defined_type_map() as $params) |
---|
| 81 | { |
---|
| 82 | $avail_sizes[] = $params->type; |
---|
| 83 | if ($params->type == $conf['batch_download']['photo_size']) break; |
---|
| 84 | } |
---|
| 85 | if ($conf['batch_download']['photo_size'] == 'original') |
---|
| 86 | { |
---|
| 87 | $avail_sizes[] = 'original'; |
---|
| 88 | } |
---|
[25932] | 89 | |
---|
[25931] | 90 | if (!in_array($set['size'], $avail_sizes)) |
---|
| 91 | { |
---|
| 92 | $set['size'] = $conf['batch_download']['photo_size']; |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | |
---|
[26849] | 96 | return trigger_event('batchdownload_get_set_info', $set); |
---|
[16379] | 97 | } |
---|
| 98 | |
---|
| 99 | /** |
---|
| 100 | * check is current user can use BatchDownloader |
---|
| 101 | * @return: boolean |
---|
| 102 | */ |
---|
| 103 | function check_download_access() |
---|
| 104 | { |
---|
| 105 | global $user, $conf; |
---|
[25932] | 106 | |
---|
[16400] | 107 | if (is_a_guest()) return false; |
---|
[16379] | 108 | if (is_admin()) return true; |
---|
[25932] | 109 | |
---|
[16379] | 110 | if ($user['level'] < $conf['batch_download']['level']) return false; |
---|
[25932] | 111 | |
---|
[16379] | 112 | if (!empty($conf['batch_download']['groups'])) |
---|
| 113 | { |
---|
| 114 | $query = ' |
---|
| 115 | SELECT 1 FROM '.USER_GROUP_TABLE.' |
---|
| 116 | WHERE |
---|
| 117 | user_id = '.$user['id'].' |
---|
| 118 | AND group_id IN('.implode(',', $conf['batch_download']['groups']).') |
---|
| 119 | ;'; |
---|
| 120 | $result = pwg_query($query); |
---|
[25932] | 121 | |
---|
[16379] | 122 | if (!pwg_db_num_rows($result)) return false; |
---|
| 123 | } |
---|
[25932] | 124 | |
---|
[16379] | 125 | return true; |
---|
| 126 | } |
---|
| 127 | |
---|
[23167] | 128 | // https://bugs.php.net/bug.php?id=61636 |
---|
| 129 | function readlargefile($fullfile) |
---|
| 130 | { |
---|
| 131 | $fp = fopen($fullfile, 'rb'); |
---|
| 132 | |
---|
| 133 | if ($fp) |
---|
| 134 | { |
---|
| 135 | while (!feof($fp)) |
---|
| 136 | { |
---|
| 137 | print(fread($fp, 2097152)); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | fclose($fp); |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | |
---|
[23804] | 144 | if (!function_exists('str2lower')) |
---|
| 145 | { |
---|
| 146 | if (function_exists('mb_strtolower') && defined('PWG_CHARSET')) |
---|
| 147 | { |
---|
| 148 | function str2lower($term) |
---|
| 149 | { |
---|
| 150 | return mb_strtolower($term, PWG_CHARSET); |
---|
| 151 | } |
---|
| 152 | function str2upper($term) |
---|
| 153 | { |
---|
| 154 | return mb_strtoupper($term, PWG_CHARSET); |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | else |
---|
| 158 | { |
---|
| 159 | function str2lower($term) |
---|
| 160 | { |
---|
| 161 | return strtolower($term); |
---|
| 162 | } |
---|
| 163 | function str2upper($term) |
---|
| 164 | { |
---|
| 165 | return strtoupper($term); |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | } |
---|