| | 38 | |
| | 39 | add_event_handler('loc_end_section_init', 'community_section_init'); |
| | 40 | function community_section_init() |
| | 41 | { |
| | 42 | global $tokens, $page; |
| | 43 | |
| | 44 | if ($tokens[0] == 'add_photos') |
| | 45 | { |
| | 46 | $page['section'] = 'add_photos'; |
| | 47 | } |
| | 48 | } |
| | 49 | |
| | 50 | add_event_handler('loc_end_index', 'community_index'); |
| | 51 | function community_index() |
| | 52 | { |
| | 53 | global $page; |
| | 54 | |
| | 55 | if (isset($page['section']) and $page['section'] == 'add_photos') |
| | 56 | { |
| | 57 | include(COMMUNITY_PATH.'add_photos.php'); |
| | 58 | } |
| | 59 | } |
| | 60 | |
| | 61 | add_event_handler('blockmanager_apply' , 'community_gallery_menu'); |
| | 62 | function community_gallery_menu($menu_ref_arr) |
| | 63 | { |
| | 64 | global $conf, $user; |
| | 65 | |
| | 66 | // conditional : depending on community permissions, display the "Add |
| | 67 | // photos" link in the gallery menu |
| | 68 | |
| | 69 | // admins are not concerned about community permissions |
| | 70 | if (!is_admin()) |
| | 71 | { |
| | 72 | // what are the user groups? |
| | 73 | $query = ' |
| | 74 | SELECT |
| | 75 | group_id |
| | 76 | FROM '.USER_GROUP_TABLE.' |
| | 77 | WHERE user_id = '.$user['id'].' |
| | 78 | ;'; |
| | 79 | $user_group_ids = array_from_query($query, 'group_id'); |
| | 80 | |
| | 81 | $query = ' |
| | 82 | SELECT |
| | 83 | COUNT(*) |
| | 84 | FROM '.COMMUNITY_PERMISSIONS_TABLE.' |
| | 85 | WHERE (type = \'any_visitor\')'; |
| | 86 | |
| | 87 | if ($user['id'] != $conf['guest_id']) |
| | 88 | { |
| | 89 | $query.= ' |
| | 90 | OR (type = \'any_registered_user\') |
| | 91 | OR (type = \'user\' AND user_id = '.$user['id'].') |
| | 92 | OR (type = \'group\' AND group_id IN ('.implode(',', $user_group_ids).')) |
| | 93 | '; |
| | 94 | } |
| | 95 | |
| | 96 | $query.= ' |
| | 97 | ;'; |
| | 98 | |
| | 99 | list($counter) = pwg_db_fetch_row(pwg_query($query)); |
| | 100 | if (0 == $counter) |
| | 101 | { |
| | 102 | return; |
| | 103 | } |
| | 104 | } |
| | 105 | |
| | 106 | $menu = & $menu_ref_arr[0]; |
| | 107 | |
| | 108 | if (($block = $menu->get_block('mbMenu')) != null ) |
| | 109 | { |
| | 110 | load_language('plugin.lang', COMMUNITY_PATH); |
| | 111 | |
| | 112 | array_splice( |
| | 113 | $block->data, |
| | 114 | count($block->data), |
| | 115 | 0, |
| | 116 | array( |
| | 117 | '' => array( |
| | 118 | 'URL' => make_index_url(array('section' => 'add_photos')), |
| | 119 | 'TITLE' => l10n('Upload your own photos'), |
| | 120 | 'NAME' => l10n('Upload Photos') |
| | 121 | ) |
| | 122 | ) |
| | 123 | ); |
| | 124 | } |
| | 125 | } |
| | 126 | |