Changeset 3917 for trunk/bp-groups/bp-groups-loader.php
- Timestamp:
- 01/25/2011 08:58:56 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-groups/bp-groups-loader.php
r3858 r3917 21 21 */ 22 22 function BP_Groups_Component() { 23 parent::start( 'groups', __( 'User Groups', 'buddypress' ) ); 23 parent::start( 24 'groups', 25 __( 'User Groups', 'buddypress' ), 26 BP_PLUGIN_DIR 27 ); 28 } 29 30 /** 31 * Include files 32 */ 33 function _includes() { 34 $includes = array( 35 'cache', 36 'forums', 37 'actions', 38 'filters', 39 'screens', 40 'classes', 41 'widgets', 42 'activity', 43 'template', 44 'functions' 45 ); 46 parent::_includes( $includes ); 24 47 } 25 48 … … 40 63 define( 'BP_GROUPS_SLUG', $this->id ); 41 64 42 // Do some slug checks 43 $this->slug = BP_GROUPS_SLUG; 44 $this->root_slug = isset( $bp->pages->groups->slug ) ? $bp->pages->groups->slug : $this->slug; 45 46 // Tables 47 $this->table_name = $bp->table_prefix . 'bp_groups'; 48 $this->table_name_members = $bp->table_prefix . 'bp_groups_members'; 49 $this->table_name_groupmeta = $bp->table_prefix . 'bp_groups_groupmeta'; 50 51 // Notifications 52 $this->notification_callback = 'groups_format_notifications'; 65 // Global tables for messaging component 66 $global_tables = array( 67 'table_name' => $bp->table_prefix . 'bp_groups', 68 'table_name_members' => $bp->table_prefix . 'bp_groups_members', 69 'table_name_groupmeta' => $bp->table_prefix . 'bp_groups_groupmeta' 70 ); 71 72 // All globals for messaging component. 73 // Note that global_tables is included in this array. 74 $globals = array( 75 'slug' => BP_GROUPS_SLUG, 76 'root_slug' => isset( $bp->pages->groups->slug ) ? $bp->pages->groups->slug : BP_GROUPS_SLUG, 77 'notification_callback' => 'groups_format_notifications', 78 'search_string' => __( 'Search Groups...', 'buddypress' ), 79 'global_tables' => $global_tables, 80 ); 81 82 parent::_setup_globals( $globals ); 83 84 /** Single Group Globals **********************************************/ 85 86 // Are we viewing a single group? 87 if ( bp_is_groups_component() && $group_id = BP_Groups_Group::group_exists( bp_current_action() ) ) { 88 89 $bp->is_single_item = true; 90 $this->current_group = new BP_Groups_Group( $group_id ); 91 92 // When in a single group, the first action is bumped down one because of the 93 // group name, so we need to adjust this and set the group name to current_item. 94 $bp->current_item = isset( $bp->current_action ) ? $bp->current_action : false; 95 $bp->current_action = isset( $bp->action_variables[0] ) ? $bp->action_variables[0] : false; 96 array_shift( $bp->action_variables ); 97 98 // Using "item" not "group" for generic support in other components. 99 if ( is_super_admin() ) 100 $bp->is_item_admin = 1; 101 else 102 $bp->is_item_admin = groups_is_user_admin( $bp->loggedin_user->id, $this->current_group->id ); 103 104 // If the user is not an admin, check if they are a moderator 105 if ( empty( $bp->is_item_admin ) ) 106 $bp->is_item_mod = groups_is_user_mod( $bp->loggedin_user->id, $this->current_group->id ); 107 108 // Is the logged in user a member of the group? 109 if ( ( is_user_logged_in() && groups_is_user_member( $bp->loggedin_user->id, $this->current_group->id ) ) ) 110 $this->current_group->is_user_member = true; 111 else 112 $this->current_group->is_user_member = false; 113 114 // Should this group be visible to the logged in user? 115 if ( 'public' == $this->current_group->status || $this->current_group->is_user_member ) 116 $this->current_group->is_visible = true; 117 else 118 $this->current_group->is_visible = false; 119 120 // If this is a private or hidden group, does the user have access? 121 if ( 'private' == $this->current_group->status || 'hidden' == $this->current_group->status ) { 122 if ( $this->current_group->is_user_member && is_user_logged_in() || is_super_admin() ) 123 $this->current_group->user_has_access = true; 124 else 125 $this->current_group->user_has_access = false; 126 } else { 127 $this->current_group->user_has_access = true; 128 } 129 130 // Set current_group to 0 to prevent debug errors 131 } else { 132 $this->current_group = 0; 133 } 53 134 54 135 // Illegal group names/slugs 55 $this->forbidden_names 136 $this->forbidden_names = apply_filters( 'groups_forbidden_names', array( 56 137 'my-groups', 57 138 'create', … … 70 151 ) ); 71 152 72 // The default text for the blogs directory search box73 $bp->default_search_strings[$this->id] = __( 'Search Groups...', 'buddypress' );74 75 153 // Preconfigured group creation steps 76 154 $this->group_creation_steps = apply_filters( 'groups_create_group_steps', array( … … 104 182 105 183 // Auto join group when non group member performs group activity 106 $this->auto_join = defined( 'BP_DISABLE_AUTO_GROUP_JOIN' ) ? false : true; 107 108 // The default text for the groups directory search box 109 $this->default_search_string = __( 'Search Groups...', 'buddypress' ); 110 111 // Register this in the active components array 112 $bp->active_components[$this->id] = $this->id; 113 } 114 115 /** 116 * Include files 117 */ 118 function _includes() { 119 require_once( BP_PLUGIN_DIR . '/bp-groups/bp-groups-cache.php' ); 120 require_once( BP_PLUGIN_DIR . '/bp-groups/bp-groups-forums.php' ); 121 require_once( BP_PLUGIN_DIR . '/bp-groups/bp-groups-actions.php' ); 122 require_once( BP_PLUGIN_DIR . '/bp-groups/bp-groups-filters.php' ); 123 require_once( BP_PLUGIN_DIR . '/bp-groups/bp-groups-screens.php' ); 124 require_once( BP_PLUGIN_DIR . '/bp-groups/bp-groups-classes.php' ); 125 require_once( BP_PLUGIN_DIR . '/bp-groups/bp-groups-widgets.php' ); 126 require_once( BP_PLUGIN_DIR . '/bp-groups/bp-groups-activity.php' ); 127 require_once( BP_PLUGIN_DIR . '/bp-groups/bp-groups-template.php' ); 128 require_once( BP_PLUGIN_DIR . '/bp-groups/bp-groups-functions.php' ); 184 $this->auto_join = defined( 'BP_DISABLE_AUTO_GROUP_JOIN' ); 129 185 } 130 186 … … 137 193 global $bp; 138 194 139 // Are we viewing a single group?140 if ( bp_is_current_component( 'groups' ) && $group_id = BP_Groups_Group::group_exists( bp_current_action() ) ) {141 142 $bp->is_single_item = true;143 $this->current_group = new BP_Groups_Group( $group_id );144 145 // Using "item" not "group" for generic support in other components.146 if ( is_super_admin() )147 $bp->is_item_admin = 1;148 else149 $bp->is_item_admin = groups_is_user_admin( $bp->loggedin_user->id, $this->current_group->id );150 151 // If the user is not an admin, check if they are a moderator152 if ( empty( $bp->is_item_admin ) )153 $bp->is_item_mod = groups_is_user_mod( $bp->loggedin_user->id, $this->current_group->id );154 155 // Is the logged in user a member of the group?156 if ( ( is_user_logged_in() && groups_is_user_member( $bp->loggedin_user->id, $this->current_group->id ) ) )157 $this->current_group->is_user_member = true;158 else159 $this->current_group->is_user_member = false;160 161 // Should this group be visible to the logged in user?162 if ( 'public' == $this->current_group->status || $this->current_group->is_user_member )163 $this->current_group->is_visible = true;164 else165 $this->current_group->is_visible = false;166 167 // Set current_group to 0 to prevent debug errors168 } else {169 $this->current_group = 0;170 }171 172 195 // Add 'Groups' to the main navigation 173 bp_core_new_nav_item(array(196 $main_nav = array( 174 197 'name' => sprintf( __( 'Groups <span>(%d)</span>', 'buddypress' ), groups_total_groups_for_user() ), 175 198 'slug' => $this->slug, … … 178 201 'default_subnav_slug' => 'my-groups', 179 202 'item_css_id' => $this->id 180 ) );203 ); 181 204 182 205 $groups_link = trailingslashit( $bp->loggedin_user->domain . $this->slug ); 183 206 184 207 // Add the My Groups nav item 185 bp_core_new_subnav_item(array(208 $sub_nav[] = array( 186 209 'name' => __( 'My Groups', 'buddypress' ), 187 210 'slug' => 'my-groups', … … 191 214 'position' => 10, 192 215 'item_css_id' => 'groups-my-groups' 193 ) );216 ); 194 217 195 218 // Add the Group Invites nav item 196 bp_core_new_subnav_item(array(219 $sub_nav[] = array( 197 220 'name' => __( 'Invitations', 'buddypress' ), 198 221 'slug' => 'invites', … … 202 225 'position' => 30, 203 226 'user_has_access' => bp_is_my_profile() 204 ) ); 205 206 207 if ( bp_is_current_component( 'groups' ) ) { 227 ); 228 229 parent::_setup_nav( $main_nav, $sub_nav ); 230 231 if ( bp_is_groups_component() ) { 232 if ( bp_is_single_item() ) { 233 234 // Add 'Groups' to the main navigation 235 $main_nav = array( 236 'name' => __( 'Groups', 'buddypress' ), 237 'slug' => $this->root_slug, 238 'position' => -1, // Do not show in BuddyBar 239 'screen_function' => 'groups_screen_group_home', 240 'default_subnav_slug' => 'home', 241 'item_css_id' => $this->id 242 ); 243 244 $group_link = trailingslashit( $bp->root_domain . '/' . $this->root_slug . '/' . $this->current_group->slug ); 245 246 // Add the "Home" subnav item, as this will always be present 247 $sub_nav[] = array( 248 'name' => __( 'Home', 'buddypress' ), 249 'slug' => 'home', 250 'parent_url' => $group_link, 251 'parent_slug' => $this->root_slug, 252 'screen_function' => 'groups_screen_group_home', 253 'position' => 10, 254 'item_css_id' => 'home' 255 ); 256 257 // If the user is a group mod or more, then show the group admin nav item 258 if ( bp_is_item_admin() || bp_is_item_mod() ) { 259 $sub_nav[] = array( 260 'name' => __( 'Admin', 'buddypress' ), 261 'slug' => 'admin', 262 'parent_url' => $group_link, 263 'parent_slug' => $this->root_slug, 264 'screen_function' => 'groups_screen_group_admin', 265 'position' => 20, 266 'user_has_access' => ( $bp->is_item_admin + (int)$bp->is_item_mod ), 267 'item_css_id' => 'admin' 268 ); 269 } 270 271 // If this is a private group, and the user is not a member, show a "Request Membership" nav item. 272 if ( is_user_logged_in() && 273 !is_super_admin() && 274 !$this->current_group->is_user_member && 275 !groups_check_for_membership_request( $bp->loggedin_user->id, $this->current_group->id ) && 276 $this->current_group->status == 'private' 277 ) { 278 $sub_nav[] = array( 279 'name' => __( 'Request Membership', 'buddypress' ), 280 'slug' => 'request-membership', 281 'parent_url' => $group_link, 282 'parent_slug' => $this->root_slug, 283 'screen_function' => 'groups_screen_group_request_membership', 284 'position' => 30 285 ); 286 } 287 288 // Forums are enabled and turned on 289 if ( $this->current_group->enable_forum && bp_is_active( 'forums' ) ) { 290 $sub_nav[] = array( 291 'name' => __( 'Forum', 'buddypress' ), 292 'slug' => 'forum', 293 'parent_url' => $group_link, 294 'parent_slug' => $this->root_slug, 295 'screen_function' => 'groups_screen_group_forum', 296 'position' => 40, 297 'user_has_access' => $this->current_group->user_has_access, 298 'item_css_id' => 'forums' 299 ); 300 } 301 302 $sub_nav[] = array( 303 'name' => sprintf( __( 'Members (%s)', 'buddypress' ), number_format( $this->current_group->total_member_count ) ), 304 'slug' => 'members', 305 'parent_url' => $group_link, 306 'parent_slug' => $this->root_slug, 307 'screen_function' => 'groups_screen_group_members', 308 'position' => 60, 309 'user_has_access' => $this->current_group->user_has_access, 310 'item_css_id' => 'members' 311 ); 312 313 if ( is_user_logged_in() && groups_is_user_member( $bp->loggedin_user->id, $this->current_group->id ) ) { 314 if ( bp_is_active( 'friends' ) ) { 315 $sub_nav[] = array( 316 'name' => __( 'Send Invites', 'buddypress' ), 317 'slug' => 'send-invites', 318 'parent_url' => $group_link, 319 'parent_slug' => $this->root_slug, 320 'screen_function' => 'groups_screen_group_invite', 321 'item_css_id' => 'invite', 322 'position' => 70, 323 'user_has_access' => $this->current_group->user_has_access 324 ); 325 } 326 } 327 328 parent::_setup_nav( $main_nav, $sub_nav ); 329 } 330 } 331 332 if ( isset( $this->current_group->user_has_access ) ) 333 do_action( 'groups_setup_nav', $this->current_group->user_has_access ); 334 else 335 do_action( 'groups_setup_nav'); 336 } 337 338 /** 339 * Sets up the title for pages and <title> 340 * 341 * @global obj $bp 342 */ 343 function _setup_title() { 344 global $bp; 345 346 if ( bp_is_groups_component() ) { 208 347 209 348 if ( bp_is_my_profile() && !bp_is_single_item() ) { … … 211 350 $bp->bp_options_title = __( 'My Groups', 'buddypress' ); 212 351 213 } else if ( !bp_is_my_profile() && ! $bp->is_single_item) {352 } else if ( !bp_is_my_profile() && !bp_is_single_item() ) { 214 353 215 354 $bp->bp_options_avatar = bp_core_fetch_avatar( array( … … 222 361 // group navigation menu using the $this->current_group global. 223 362 } else if ( bp_is_single_item() ) { 224 // When in a single group, the first action is bumped down one because of the225 // group name, so we need to adjust this and set the group name to current_item.226 $bp->current_item = isset( $bp->current_action ) ? $bp->current_action : false;227 $bp->current_action = isset( $bp->action_variables[0] ) ? $bp->action_variables[0] : false;228 array_shift( $bp->action_variables );229 230 363 $bp->bp_options_title = $this->current_group->name; 231 364 $bp->bp_options_avatar = bp_core_fetch_avatar( array( … … 238 371 if ( empty( $bp->bp_options_avatar ) ) 239 372 $bp->bp_options_avatar = '<img src="' . esc_attr( $group->avatar_full ) . '" class="avatar" alt="' . esc_attr( $group->name ) . '" />'; 240 241 // Add 'Groups' to the main navigation242 bp_core_new_nav_item( array(243 'name' => __( 'Groups', 'buddypress' ),244 'slug' => $this->root_slug,245 'position' => -1, // Do not show in BuddyBar246 'screen_function' => 'groups_screen_group_home',247 'default_subnav_slug' => 'home',248 'item_css_id' => $this->id249 ) );250 251 $group_link = trailingslashit( $bp->root_domain . '/' . $this->root_slug . '/' . $this->current_group->slug );252 253 // If this is a private or hidden group, does the user have access?254 if ( 'private' == $this->current_group->status || 'hidden' == $this->current_group->status ) {255 if ( $this->current_group->is_user_member && is_user_logged_in() || is_super_admin() )256 $this->current_group->user_has_access = true;257 else258 $this->current_group->user_has_access = false;259 } else {260 $this->current_group->user_has_access = true;261 }262 263 // Add the "Home" subnav item, as this will always be present264 bp_core_new_subnav_item( array(265 'name' => __( 'Home', 'buddypress' ),266 'slug' => 'home',267 'parent_url' => $group_link,268 'parent_slug' => $this->root_slug,269 'screen_function' => 'groups_screen_group_home',270 'position' => 10,271 'item_css_id' => 'home'272 ) );273 274 // If the user is a group mod or more, then show the group admin nav item275 if ( bp_is_item_admin() || bp_is_item_mod() ) {276 bp_core_new_subnav_item( array(277 'name' => __( 'Admin', 'buddypress' ),278 'slug' => 'admin',279 'parent_url' => $group_link,280 'parent_slug' => $this->root_slug,281 'screen_function' => 'groups_screen_group_admin',282 'position' => 20,283 'user_has_access' => ( $bp->is_item_admin + (int)$bp->is_item_mod ),284 'item_css_id' => 'admin'285 ) );286 }287 288 // If this is a private group, and the user is not a member, show a "Request Membership" nav item.289 if ( is_user_logged_in() &&290 !is_super_admin() &&291 !$this->current_group->is_user_member &&292 !groups_check_for_membership_request( $bp->loggedin_user->id, $this->current_group->id ) &&293 $this->current_group->status == 'private'294 ) {295 bp_core_new_subnav_item( array(296 'name' => __( 'Request Membership', 'buddypress' ),297 'slug' => 'request-membership',298 'parent_url' => $group_link,299 'parent_slug' => $this->root_slug,300 'screen_function' => 'groups_screen_group_request_membership',301 'position' => 30302 ) );303 }304 305 // Forums are enabled and turned on306 if ( $this->current_group->enable_forum && bp_is_active( 'forums' ) ) {307 bp_core_new_subnav_item( array(308 'name' => __( 'Forum', 'buddypress' ),309 'slug' => 'forum',310 'parent_url' => $group_link,311 'parent_slug' => $this->root_slug,312 'screen_function' => 'groups_screen_group_forum',313 'position' => 40,314 'user_has_access' => $this->current_group->user_has_access,315 'item_css_id' => 'forums'316 ) );317 }318 319 bp_core_new_subnav_item( array(320 'name' => sprintf( __( 'Members (%s)', 'buddypress' ), number_format( $this->current_group->total_member_count ) ),321 'slug' => 'members',322 'parent_url' => $group_link,323 'parent_slug' => $this->root_slug,324 'screen_function' => 'groups_screen_group_members',325 'position' => 60,326 'user_has_access' => $this->current_group->user_has_access,327 'item_css_id' => 'members'328 ) );329 330 if ( is_user_logged_in() && groups_is_user_member( $bp->loggedin_user->id, $this->current_group->id ) ) {331 if ( bp_is_active( 'friends' ) ) {332 bp_core_new_subnav_item( array(333 'name' => __( 'Send Invites', 'buddypress' ),334 'slug' => 'send-invites',335 'parent_url' => $group_link,336 'parent_slug' => $this->root_slug,337 'screen_function' => 'groups_screen_group_invite',338 'item_css_id' => 'invite',339 'position' => 70,340 'user_has_access' => $this->current_group->user_has_access341 ) );342 }343 }344 373 } 345 374 } 346 375 347 if ( isset( $this->current_group->user_has_access ) ) 348 do_action( 'groups_setup_nav', $this->current_group->user_has_access ); 349 else 350 do_action( 'groups_setup_nav'); 376 parent::_setup_title(); 351 377 } 352 378 }
Note: See TracChangeset
for help on using the changeset viewer.