[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 | { |
---|
| 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; |
---|
[16592] | 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; |
---|
[16379] | 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 | } |
---|
| 63 | |
---|
| 64 | if ( isset($batch_type) and isset($batch_id) ) |
---|
| 65 | { |
---|
| 66 | return array('type'=>$batch_type, 'id'=>$batch_id); |
---|
| 67 | } |
---|
| 68 | else |
---|
| 69 | { |
---|
| 70 | return false; |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | /** |
---|
| 75 | * check is current user can use BatchDownloader |
---|
| 76 | * @return: boolean |
---|
| 77 | */ |
---|
| 78 | function check_download_access() |
---|
| 79 | { |
---|
| 80 | global $user, $conf; |
---|
| 81 | |
---|
[16400] | 82 | if (is_a_guest()) return false; |
---|
[16379] | 83 | if (is_admin()) return true; |
---|
| 84 | |
---|
| 85 | if ($user['level'] < $conf['batch_download']['level']) return false; |
---|
| 86 | |
---|
| 87 | if (!empty($conf['batch_download']['groups'])) |
---|
| 88 | { |
---|
| 89 | $query = ' |
---|
| 90 | SELECT 1 FROM '.USER_GROUP_TABLE.' |
---|
| 91 | WHERE |
---|
| 92 | user_id = '.$user['id'].' |
---|
| 93 | AND group_id IN('.implode(',', $conf['batch_download']['groups']).') |
---|
| 94 | ;'; |
---|
| 95 | $result = pwg_query($query); |
---|
| 96 | |
---|
| 97 | if (!pwg_db_num_rows($result)) return false; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | return true; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | ?> |
---|