Changeset 359 for trunk/bp-groups.php
- Timestamp:
- 09/24/2008 05:31:27 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/bp-groups.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-groups.php
r352 r359 93 93 'table_name_members' => $wpdb->base_prefix . 'bp_groups_members', 94 94 'image_base' => get_option('siteurl') . '/wp-content/mu-plugins/bp-groups/images', 95 'format_activity_function' => 'groups_format_activity', 95 96 'slug' => 'groups' 96 97 ); … … 115 116 global $wpdb, $bp, $userdata; 116 117 117 if ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' )) {118 if ( $wpdb->blogid == $bp['current_homebase_id'] ) { 118 119 /* Add the administration tab under the "Site Admin" tab for site administrators */ 119 120 //add_submenu_page( 'wpmu-admin.php', __("Friends"), __("Friends"), 1, basename(__FILE__), "friends_settings" ); … … 137 138 global $group_obj, $is_single_group; 138 139 139 $nav_key = count($bp['bp_nav']) + 1; 140 $user_nav_key = count($bp['bp_users_nav']) + 1; 141 142 $bp['bp_nav'][$nav_key] = array( 143 'id' => $bp['groups']['slug'], 144 'name' => __('Groups'), 145 'link' => $bp['loggedin_domain'] . $bp['groups']['slug'] . '/' 146 ); 147 148 $bp['bp_users_nav'][$user_nav_key] = array( 149 'id' => $bp['groups']['slug'], 150 'name' => __('Groups'), 151 'link' => $bp['current_domain'] . $bp['groups']['slug'] . '/' 152 ); 153 154 $bp['bp_options_nav'][$bp['groups']['slug']] = array( 155 'my-groups' => array( 156 'name' => __('My Groups'), 157 'link' => $bp['loggedin_domain'] . $bp['groups']['slug'] . '/my-groups' ), 158 'group-finder' => array( 159 'name' => __('Group Finder'), 160 'link' => $bp['loggedin_domain'] . $bp['groups']['slug'] . '/group-finder' ), 161 'create' => array( 162 'name' => __('Create a Group'), 163 'link' => $bp['loggedin_domain'] . $bp['groups']['slug'] . '/create' ), 164 'invites' => array( 165 'name' => __('Invites'), 166 'link' => $bp['loggedin_domain'] . $bp['groups']['slug'] . '/invites' ) 167 ); 140 if ( $group_id = BP_Groups_Group::group_exists($bp['current_action']) ) { 141 /* This is a single group page. */ 142 $is_single_group = true; 143 $group_obj = new BP_Groups_Group( $group_id ); 144 145 /* Using "item" not "group" for generic support in other components. */ 146 $bp['is_item_admin'] = groups_is_user_admin( $bp['loggedin_userid'], $group_obj->id ); 147 } 148 149 /* Add 'Groups' to the main navigation */ 150 bp_core_add_nav_item( __('Groups'), $bp['groups']['slug'] ); 151 bp_core_add_nav_default( $bp['groups']['slug'], 'groups_screen_my_groups', 'my-groups' ); 152 153 $groups_link = $group_link = $bp['loggedin_domain'] . $bp['groups']['slug'] . '/'; 154 155 /* Add the subnav items to the groups nav item */ 156 bp_core_add_subnav_item( $bp['groups']['slug'], 'my-groups', __('My Groups'), $groups_link, 'groups_screen_my_groups' ); 157 bp_core_add_subnav_item( $bp['groups']['slug'], 'group-finder', __('Group Finder'), $groups_link, 'groups_screen_group_finder' ); 158 bp_core_add_subnav_item( $bp['groups']['slug'], 'create', __('Create a Group'), $groups_link, 'groups_screen_create_group' ); 159 bp_core_add_subnav_item( $bp['groups']['slug'], 'invites', __('Invites'), $groups_link, 'groups_screen_group_invites' ); 168 160 169 161 if ( $bp['current_component'] == $bp['groups']['slug'] ) { … … 174 166 175 167 } else if ( !bp_is_home() && !$is_single_group ) { 176 168 177 169 $bp['bp_options_avatar'] = bp_core_get_avatar( $bp['current_userid'], 1 ); 178 $bp['bp_options_title'] = bp_user_fullname( $bp['current_userid'], false );170 $bp['bp_options_title'] = $bp['current_fullname']; 179 171 180 172 } else if ( $is_single_group ) { 181 182 173 // We are viewing a single group, so set up the 183 174 // group navigation menu using the $group_obj global. 184 175 176 /* When in a single group, the first action is bumped down one because of the 177 group name, so we need to adjust this and set the group name to current_item. */ 178 $bp['current_item'] = $bp['current_action']; 179 $bp['current_action'] = $bp['action_variables'][0]; 180 unset($bp['action_variables'][0]); 181 185 182 $bp['bp_options_title'] = bp_create_excerpt( $group_obj->name, 1 ); 186 183 $bp['bp_options_avatar'] = '<img src="' . $group_obj->avatar_thumb . '" alt="Group Avatar Thumbnail" />'; 187 184 188 $bp['bp_options_nav'][$bp['groups']['slug']] = array( 189 '' => array( 190 'id' => 'group-home', 191 'name' => __('Home'), 192 'link' => $bp['loggedin_domain'] . $bp['groups']['slug'] . '/' . $group_obj->slug ), 193 'forum' => array( 194 'id' => 'group-forum', 195 'name' => __('Forum'), 196 'link' => $bp['loggedin_domain'] . $bp['groups']['slug'] . '/' . $group_obj->slug . '/forum' ) 197 ); 185 $group_link = $bp['loggedin_domain'] . $bp['groups']['slug'] . '/' . $group_obj->slug . '/'; 186 187 // Reset the existing subnav items 188 bp_core_reset_subnav_items($bp['groups']['slug']); 189 190 bp_core_add_nav_default( $bp['groups']['slug'], 'groups_screen_group_home', 'home' ); 191 192 bp_core_add_subnav_item( $bp['groups']['slug'], 'home', __('Home'), $group_link, 'groups_screen_group_home', 'group-home' ); 193 bp_core_add_subnav_item( $bp['groups']['slug'], 'forum', __('Forum'), $group_link , 'groups_screen_group_forum', 'group-forum'); 198 194 199 195 if ( function_exists('bp_wire_install') ) { 200 $wire = array( 201 'wire' => array( 202 'id' => 'group-wire', 203 'name' => __('Wire'), 204 'link' => $bp['loggedin_domain'] . $bp['groups']['slug'] . '/' . $group_obj->slug . '/wire' ) 205 ); 206 $bp['bp_options_nav'][$bp['groups']['slug']] = array_merge( $bp['bp_options_nav'][$bp['groups']['slug']], $wire ); 196 bp_core_add_subnav_item( $bp['groups']['slug'], 'wire', __('Wire'), $group_link, 'groups_screen_group_wire', 'group-wire' ); 207 197 } 208 198 209 199 if ( function_exists('bp_gallery_install') ) { 210 $photos = array( 211 'photos' => array( 212 'id' => 'group-photos', 213 'name' => __('Photos'), 214 'link' => $bp['loggedin_domain'] . $bp['groups']['slug'] . '/' . $group_obj->slug . '/photos' ) 215 ); 216 $bp['bp_options_nav'][$bp['groups']['slug']] = array_merge( $bp['bp_options_nav'][$bp['groups']['slug']], $photos ); 200 bp_core_add_subnav_item( $bp['groups']['slug'], 'photos', __('Photos'), $group_link, 'groups_screen_group_photos', 'group-photos' ); 217 201 } 218 202 219 $options_nav = array( 220 'members' => array( 221 'id' => 'group-members', 222 'name' => __('Members'), 223 'link' => $bp['loggedin_domain'] . $bp['groups']['slug'] . '/' . $group_obj->slug . '/members' ), 224 'send-invites' => array( 225 'id' => 'group-invite', 226 'name' => __('Send Invites'), 227 'link' => $bp['loggedin_domain'] . $bp['groups']['slug'] . '/' . $group_obj->slug . '/send-invites' ), 228 ); 229 $bp['bp_options_nav'][$bp['groups']['slug']] = array_merge( $bp['bp_options_nav'][$bp['groups']['slug']], $options_nav ); 203 bp_core_add_subnav_item( $bp['groups']['slug'], 'members', __('Members'), $group_link, 'groups_screen_group_members', 'group-members' ); 204 bp_core_add_subnav_item( $bp['groups']['slug'], 'send-invites', __('Send Invites'), $group_link, 'groups_screen_group_invite', 'group-invite' ); 230 205 231 206 if ( is_user_logged_in() && groups_is_user_member( $bp['loggedin_userid'], $group_obj->id ) ) { 232 $leave_nav = array( 233 'leave-group' => array( 234 'id' => 'group-leave', 235 'name' => __('Leave Group'), 236 'link' => $bp['loggedin_domain'] . $bp['groups']['slug'] . '/' . $group_obj->slug . '/leave-group' ) 237 ); 238 $bp['bp_options_nav'][$bp['groups']['slug']] = array_merge( $bp['bp_options_nav'][$bp['groups']['slug']], $leave_nav ); 207 bp_core_add_subnav_item( $bp['groups']['slug'], 'leave-group', __('Leave Group'), $group_link, 'groups_screen_group_leave', 'group-leave' ); 239 208 } 240 209 } 241 210 } 242 211 } 243 add_action( 'wp', 'groups_setup_nav', 4 ); 244 245 246 /************************************************************************** 247 groups_catch_action() 248 249 Catch actions via pretty urls. 212 add_action( 'wp', 'groups_setup_nav', 2 ); 213 214 /***** Screens **********/ 215 216 function groups_screen_my_groups() { 217 bp_catch_uri( 'groups/index' ); 218 } 219 220 function groups_screen_group_finder() { 221 bp_catch_uri( 'groups/group-finder' ); 222 } 223 224 function groups_screen_group_invites() { 225 global $bp; 226 227 if ( isset($bp['action_variables']) && in_array( 'accept', $bp['action_variables'] ) && is_numeric($bp['action_variables'][1]) ) { 228 $member = new BP_Groups_Member( $bp['loggedin_userid'], $bp['action_variables'][1] ); 229 $member->accept_invite(); 230 231 if ( $member->save() ) { 232 $bp['message'] = __('Group invite accepted'); 233 $bp['message_type'] = 'success'; 234 } else { 235 $bp['message'] = __('Group invite could not be accepted'); 236 $bp['message_type'] = 'error'; 237 } 238 add_action( 'template_notices', 'bp_core_render_notice' ); 239 } else if ( isset($bp['action_variables']) && in_array( 'reject', $bp['action_variables'] ) && is_numeric($bp['action_variables'][1]) ) { 240 if ( BP_Groups_Member::delete( $bp['loggedin_userid'], $bp['action_variables'][1] ) ) { 241 $bp['message'] = __('Group invite rejected'); 242 $bp['message_type'] = 'success'; 243 } else { 244 $bp['message'] = __('Group invite could not be rejected'); 245 $bp['message_type'] = 'error'; 246 } 247 add_action( 'template_notices', 'bp_core_render_notice' ); 248 } 249 bp_catch_uri( 'groups/list-invites' ); 250 } 251 252 function groups_screen_create_group() { 253 global $bp; 254 global $create_group_step, $group_obj, $completed_to_step; 255 256 if ( !$create_group_step = $bp['action_variables'][1] ) { 257 $create_group_step = '1'; 258 $completed_to_step = 0; 259 setcookie('group_obj_id', NULL, time() - 3600, COOKIEPATH, COOKIE_DOMAIN); 260 setcookie('completed_to_step', NULL, time() - 3600, COOKIEPATH, COOKIE_DOMAIN); 261 $no_instantiate = true; 262 $reset_steps = true; 263 } 264 265 if ( isset($_COOKIE['completed_to_step']) && !$reset_steps ) { 266 $completed_to_step = (int)$_COOKIE['completed_to_step']; 267 } 268 269 if ( isset( $_POST['save'] ) || isset( $_POST['skip'] ) ) { 270 // If the user skipped the avatar step, move onto the next step and don't save anything. 271 if ( isset( $_POST['skip'] ) && $create_group_step == "3" ) { 272 $create_group_step++; 273 $completed_to_step++; 274 setcookie('completed_to_step', (string)$completed_to_step, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); 275 setcookie('group_obj_id', (string)$_COOKIE['group_obj_id'], time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); 276 $group_obj = new BP_Groups_Group( $_COOKIE['group_obj_id'] ); 277 } else { 278 if ( !$group_obj_id = &groups_manage_group( $create_group_step, $_COOKIE['group_obj_id'] ) ) { 279 $bp['message'] = __('There was an error saving group details. Please try again.'); 280 $bp['message_type'] = 'error'; 281 282 add_action( 'template_notices', 'bp_core_render_notice' ); 283 } else { 284 $create_group_step++; 285 $completed_to_step++; 286 setcookie('completed_to_step', (string)$completed_to_step, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); 287 setcookie('group_obj_id', (string)$group_obj_id, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); 288 $group_obj = new BP_Groups_Group( $group_obj_id ); 289 } 290 } 291 } 292 293 if ( isset($_COOKIE['group_obj_id']) && !$group_obj && !$no_instantiate ) 294 $group_obj = new BP_Groups_Group( (int)$_COOKIE['group_obj_id'] ); 295 296 bp_catch_uri( 'groups/create' ); 297 } 298 299 function groups_screen_group_home() { 300 global $is_single_group; 301 302 if ( $is_single_group ) { 303 bp_catch_uri( 'groups/group-home' ); 304 } 305 } 306 307 function groups_screen_group_forum() { 308 global $is_single_group; 309 310 if ( $is_single_group ) { 311 // Not implemented yet. 312 bp_catch_uri( 'groups/forum' ); 313 } 314 } 315 316 function groups_screen_group_wire() { 317 global $bp; 318 global $is_single_group, $group_obj; 319 320 if ( $is_single_group ) { 321 if ( $bp['action_variables'][1] == 'post' && BP_Groups_Member::check_is_member( $bp['loggedin_userid'], $group_obj->id ) ) { 322 323 if ( !groups_new_wire_post( $group_obj->id, $_POST['wire-post-textarea'] ) ) { 324 bp_catch_uri( 'groups/group-home' ); 325 } else { 326 $bp['message'] = __('Wire message successfully posted.'); 327 $bp['message_type'] = 'success'; 328 329 add_action( 'template_notices', 'bp_core_render_notice' ); 330 if ( !strpos( $_SERVER['HTTP_REFERER'], 'wire' ) ) { 331 bp_catch_uri( 'groups/group-home' ); 332 } else { 333 bp_catch_uri( 'groups/wire' ); 334 } 335 } 336 337 } else if ( $bp['action_variables'][1] == 'delete' && BP_Groups_Member::check_is_member( $bp['loggedin_userid'], $group_obj->id ) ) { 338 339 if ( !groups_delete_wire_post( $bp['action_variables'][2], $bp['groups']['table_name_wire'] ) ) { 340 bp_catch_uri( 'groups/group-home' ); 341 } else { 342 $bp['message'] = __('Wire message successfully deleted.'); 343 $bp['message_type'] = 'success'; 344 345 add_action( 'template_notices', 'bp_core_render_notice' ); 346 347 if ( !strpos( $_SERVER['HTTP_REFERER'], 'wire' ) ) { 348 bp_catch_uri( 'groups/group-home' ); 349 } else { 350 bp_catch_uri( 'groups/wire' ); 351 } 352 } 353 354 } else if ( ( !$bp['action_variables'][1] || $bp['action_variables'][1] == 'latest' ) ) { 355 bp_catch_uri( 'groups/wire' ); 356 } else { 357 bp_catch_uri( 'groups/group-home' ); 358 } 359 } 360 } 361 362 function groups_screen_group_members() { 363 global $bp; 364 global $is_single_group, $group_obj; 365 366 if ( $is_single_group ) { 367 bp_catch_uri( 'groups/list-members' ); 368 } 369 } 370 371 function groups_screen_group_photos() { 372 global $bp; 373 global $is_single_group, $group_obj; 374 375 if ( $is_single_group ) { 376 // Not implemented yet. 377 bp_catch_uri( 'groups/group-home' ); 378 } 379 } 380 381 function groups_screen_group_invite() { 382 global $bp; 383 global $is_single_group, $group_obj; 384 385 if ( $is_single_group ) { 386 if ( isset($bp['action_variables']) && $bp['action_variables'][1] == 'send' ) { 387 // Send the invites. 388 groups_send_invites($group_obj); 389 390 $bp['message'] = __('Group invites sent.'); 391 $bp['message_type'] = 'success'; 392 393 add_action( 'template_notices', 'bp_core_render_notice' ); 394 bp_catch_uri( 'groups/group-home' ); 395 } else { 396 // Show send invite page 397 bp_catch_uri( 'groups/send-invite' ); 398 } 399 } 400 } 401 402 function groups_screen_group_leave() { 403 global $bp; 404 global $is_single_group, $group_obj; 405 406 if ( $is_single_group ) { 407 if ( isset($bp['action_variables']) && $bp['action_variables'][1] == 'yes' ) { 408 // remove the user from the group. 409 if ( !groups_leave_group( $group_obj->id ) ) { 410 $bp['message'] = __('There was an error leaving the group. Please try again.'); 411 $bp['message_type'] = 'error'; 412 } else { 413 $bp['message'] = __('You left the group successfully.'); 414 $bp['message_type'] = 'success'; 415 } 416 add_action( 'template_notices', 'bp_core_render_notice' ); 417 418 $is_single_group = false; 419 $bp['current_action'] = 'group-finder'; 420 bp_catch_uri( 'groups/group-finder' ); 421 422 } else if ( isset($bp['action_variables']) && $bp['action_variables'][1] == 'no' ) { 423 bp_catch_uri( 'groups/group-home' ); 424 } else { 425 // Show leave group page 426 bp_catch_uri( 'groups/leave-group-confirm' ); 427 } 428 } 429 } 430 431 /***** Actions **********/ 432 433 function groups_action_join_group() { 434 global $bp; 435 global $is_single_group, $group_obj; 436 437 if ( !$is_single_group || $bp['current_component'] != $bp['groups']['slug'] || $bp['current_action'] != 'join' ) 438 return false; 439 440 // user wants to join a group 441 if ( !BP_Groups_Member::check_is_member( $bp['loggedin_userid'], $group_obj->id ) ) { 442 if ( !groups_join_group($group_obj->id) ) { 443 $bp['message'] = __('There was an error joining the group. Please try again.'); 444 $bp['message_type'] = 'error'; 445 } else { 446 $bp['message'] = __('You joined the group!'); 447 $bp['message_type'] = 'success'; 448 } 449 450 add_action( 'template_notices', 'bp_core_render_notice' ); 451 } 452 453 bp_catch_uri( 'groups/group-home' ); 454 } 455 add_action( 'wp', 'groups_action_join_group', 3 ); 456 457 458 /************************************************************************** 459 groups_record_activity() 460 461 Records activity for the logged in user within the friends component so that 462 it will show in the users activity stream (if installed) 250 463 **************************************************************************/ 251 464 252 function groups_catch_action() { 253 global $bp, $current_blog; 254 global $is_single_group; 255 global $create_group_step, $group_obj, $completed_to_step; 256 257 if ( $bp['current_component'] == $bp['groups']['slug'] && $current_blog->blog_id > 1 ) { 258 259 switch ( $bp['current_action'] ) { 260 261 /**** My Groups ****************************/ 262 case 'my-groups': 263 bp_catch_uri( 'groups/index' ); 264 break; 265 266 /**** Group Finder ****************************/ 267 case 'group-finder': 268 bp_catch_uri( 'groups/group-finder' ); 269 break; 270 271 /**** Group Invites ****************************/ 272 case 'invites': 273 if ( isset($bp['action_variables']) && in_array( 'accept', $bp['action_variables'] ) && is_numeric($bp['action_variables'][1]) ) { 274 $member = new BP_Groups_Member( $bp['loggedin_userid'], $bp['action_variables'][1] ); 275 $member->accept_invite(); 276 277 if ( $member->save() ) { 278 $bp['message'] = __('Group invite accepted'); 279 $bp['message_type'] = 'success'; 280 } else { 281 $bp['message'] = __('Group invite could not be accepted'); 282 $bp['message_type'] = 'error'; 283 } 284 add_action( 'template_notices', 'bp_core_render_notice' ); 285 } else if ( isset($bp['action_variables']) && in_array( 'reject', $bp['action_variables'] ) && is_numeric($bp['action_variables'][1]) ) { 286 if ( BP_Groups_Member::delete( $bp['loggedin_userid'], $bp['action_variables'][1] ) ) { 287 $bp['message'] = __('Group invite rejected'); 288 $bp['message_type'] = 'success'; 289 } else { 290 $bp['message'] = __('Group invite could not be rejected'); 291 $bp['message_type'] = 'error'; 292 } 293 add_action( 'template_notices', 'bp_core_render_notice' ); 294 } 295 bp_catch_uri( 'groups/list-invites' ); 296 break; 297 298 /**** Create Group ****************************/ 299 case 'create': 300 if ( !$create_group_step = $bp['action_variables'][1] ) { 301 $create_group_step = '1'; 302 $completed_to_step = 0; 303 setcookie('group_obj_id', NULL, time() - 3600, COOKIEPATH, COOKIE_DOMAIN); 304 setcookie('completed_to_step', NULL, time() - 3600, COOKIEPATH, COOKIE_DOMAIN); 305 $no_instantiate = true; 306 $reset_steps = true; 307 } 308 309 if ( isset($_COOKIE['completed_to_step']) && !$reset_steps ) { 310 $completed_to_step = (int)$_COOKIE['completed_to_step']; 311 } 312 313 if ( isset( $_POST['save'] ) || isset( $_POST['skip'] ) ) { 314 // If the user skipped the avatar step, move onto the next step and don't save anything. 315 if ( isset( $_POST['skip'] ) && $create_group_step == "3" ) { 316 $create_group_step++; 317 $completed_to_step++; 318 setcookie('completed_to_step', (string)$completed_to_step, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); 319 setcookie('group_obj_id', (string)$_COOKIE['group_obj_id'], time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); 320 $group_obj = new BP_Groups_Group( $_COOKIE['group_obj_id'] ); 321 } else { 322 if ( !$group_obj_id = &groups_manage_group( $create_group_step, $_COOKIE['group_obj_id'] ) ) { 323 $bp['message'] = __('There was an error saving group details. Please try again.'); 324 $bp['message_type'] = 'error'; 465 function groups_record_activity( $args = true ) { 466 if ( function_exists('bp_activity_record') ) { 467 extract($args); 468 bp_activity_record( $item_id, $component_name, $component_action, $is_private ); 469 } 470 } 471 add_action( 'bp_groups_joined_group', 'groups_record_activity' ); 472 add_action( 'bp_groups_created_group', 'groups_record_activity' ); 473 add_action( 'bp_groups_new_wire_post', 'groups_record_activity' ); 474 475 /************************************************************************** 476 groups_format_activity() 477 478 Selects and formats recorded groups component activity. 479 Example: Selects the groups details for a joined group, then 480 formats it to read "Andy Peatling joined the group 'A Cool Group'" 481 **************************************************************************/ 482 483 function groups_format_activity( $item_id, $action, $for_secondary_user = false ) { 484 global $bp; 485 486 switch( $action ) { 487 case 'joined_group': 488 $group = new BP_Groups_Group( $item_id ); 489 490 if ( !$group ) 491 return false; 492 493 return bp_core_get_userlink($bp['current_userid']) . ' ' . __('joined the group') . ' ' . '<a href="' . $bp['current_domain'] . $bp['groups']['slug'] . '/' . $group->slug . '">' . $group->name . '</a>. <span class="time-since">%s</span>'; 494 break; 495 case 'created_group': 496 $group = new BP_Groups_Group( $item_id ); 497 498 if ( !$group ) 499 return false; 500 501 return bp_core_get_userlink($bp['current_userid']) . ' ' . __('created the group') . ' ' . '<a href="' . $bp['current_domain'] . $bp['groups']['slug'] . '/' . $group->slug . '">' . $group->name . '</a>. <span class="time-since">%s</span>'; 502 break; 503 case 'new_wire_post': 504 $wire_post = new BP_Wire_Post( $bp['groups']['table_name_wire'], $item_id ); 505 $group = new BP_Groups_Group( $wire_post->item_id ); 506 507 if ( !$group || !$wire_post ) 508 return false; 325 509 326 add_action( 'template_notices', 'bp_core_render_notice' ); 327 } else { 328 $create_group_step++; 329 $completed_to_step++; 330 setcookie('completed_to_step', (string)$completed_to_step, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); 331 setcookie('group_obj_id', (string)$group_obj_id, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); 332 $group_obj = new BP_Groups_Group( $group_obj_id ); 333 } 334 } 335 } 336 337 if ( isset($_COOKIE['group_obj_id']) && !$group_obj && !$no_instantiate ) 338 $group_obj = new BP_Groups_Group( (int)$_COOKIE['group_obj_id'] ); 339 340 bp_catch_uri( 'groups/create' ); 341 break; 342 343 /**** Default / Single Group ****************************/ 344 default: 345 if ( $bp['current_action'] != '' ) { 346 if ( $group_id = BP_Groups_Group::group_exists($bp['current_action']) ) { 347 348 // This is a single group page. 349 $is_single_group = true; 350 $group_obj = new BP_Groups_Group( $group_id ); 351 352 /* Using "item" not "group" for generic support in other components. */ 353 $bp['is_item_admin'] = groups_is_user_admin( $bp['loggedin_userid'], $group_obj->id ); 354 355 switch ( $bp['action_variables'][0] ) { 356 357 /**** Group Forum ****************************/ 358 case 'forum': 359 // Not implemented yet. 360 bp_catch_uri( 'groups/forum' ); 361 break; 362 363 /**** Group Wire ****************************/ 364 case 'wire': 365 if ( $bp['action_variables'][1] == 'post' && BP_Groups_Member::check_is_member( $bp['loggedin_userid'], $group_obj->id ) ) { 366 367 if ( !bp_wire_new_post( $group_obj->id, $_POST['wire-post-textarea'] ) ) { 368 bp_catch_uri( 'groups/group-home' ); 369 } else { 370 $bp['message'] = __('Wire message successfully posted.'); 371 $bp['message_type'] = 'success'; 372 373 add_action( 'template_notices', 'bp_core_render_notice' ); 374 375 if ( !strpos( $_SERVER['HTTP_REFERER'], 'wire' ) ) { 376 unset($bp['action_variables'][0]); 377 bp_catch_uri( 'groups/group-home' ); 378 } else { 379 bp_catch_uri( 'groups/wire' ); 380 } 381 } 382 383 } else if ( $bp['action_variables'][1] == 'delete' && BP_Groups_Member::check_is_member( $bp['loggedin_userid'], $group_obj->id ) ) { 384 385 if ( !bp_wire_delete_post( $bp['action_variables'][2], $bp['groups']['table_name_wire'] ) ) { 386 bp_catch_uri( 'groups/group-home' ); 387 } else { 388 $bp['message'] = __('Wire message successfully deleted.'); 389 $bp['message_type'] = 'success'; 390 391 add_action( 'template_notices', 'bp_core_render_notice' ); 392 393 if ( !strpos( $_SERVER['HTTP_REFERER'], 'wire' ) ) { 394 unset($bp['action_variables'][0]); 395 bp_catch_uri( 'groups/group-home' ); 396 } else { 397 bp_catch_uri( 'groups/wire' ); 398 } 399 } 400 401 } else if ( ( !$bp['action_variables'][1] || $bp['action_variables'][1] == 'latest' ) && BP_Groups_Member::check_is_member( $bp['loggedin_userid'], $group_obj->id ) ) { 402 403 bp_catch_uri( 'groups/wire' ); 404 405 } else { 406 407 bp_catch_uri( 'groups/group-home' ); 408 409 } 410 break; 411 412 /**** Group Photo Gallery ****************************/ 413 case 'gallery': 414 // Not implemented yet. 415 bp_catch_uri( 'groups/group-home' ); 416 break; 417 418 /**** Group Member List ****************************/ 419 case 'members': 420 // List group members 421 bp_catch_uri( 'groups/list-members' ); 422 break; 423 424 /**** Send Group Invites ****************************/ 425 case 'send-invites': 426 if ( isset($bp['action_variables']) && $bp['action_variables'][1] == 'send' ) { 427 // Send the invites. 428 groups_send_invites($group_obj); 429 430 $bp['message'] = __('Group invites sent.'); 431 $bp['message_type'] = 'success'; 432 433 add_action( 'template_notices', 'bp_core_render_notice' ); 434 bp_catch_uri( 'groups/group-home' ); 435 } else { 436 // Show send invite page 437 bp_catch_uri( 'groups/send-invite' ); 438 } 439 break; 440 441 /**** Join Group ****************************/ 442 case 'join': 443 // user wants to join a group 444 445 if ( !BP_Groups_Member::check_is_member( $bp['loggedin_userid'], $group_obj->id ) ) { 446 if ( !groups_join_group($group_obj->id) ) { 447 $bp['message'] = __('There was an error joining the group. Please try again.'); 448 $bp['message_type'] = 'error'; 449 } else { 450 $bp['message'] = __('You joined the group! <a'); 451 $bp['message_type'] = 'success'; 452 } 453 454 add_action( 'template_notices', 'bp_core_render_notice' ); 455 } 456 457 bp_catch_uri( 'groups/group-home' ); 458 break; 459 460 /**** Leave Group ****************************/ 461 case 'leave-group': 462 if ( isset($bp['action_variables']) && $bp['action_variables'][1] == 'yes' ) { 463 // remove the user from the group. 464 if ( !groups_leave_group( $group_obj->id ) ) { 465 $bp['message'] = __('There was an error leaving the group. Please try again.'); 466 $bp['message_type'] = 'error'; 467 } else { 468 $bp['message'] = __('You left the group successfully.'); 469 $bp['message_type'] = 'success'; 470 } 471 add_action( 'template_notices', 'bp_core_render_notice' ); 472 473 $is_single_group = false; 474 $bp['current_action'] = 'group-finder'; 475 bp_catch_uri( 'groups/group-finder' ); 476 477 } else if ( isset($bp['action_variables']) && $bp['action_variables'][1] == 'no' ) { 478 bp_catch_uri( 'groups/group-home' ); 479 } else { 480 // Show leave group page 481 bp_catch_uri( 'groups/leave-group-confirm' ); 482 } 483 break; 484 485 /**** Default ****************************/ 486 default: 487 bp_catch_uri( 'groups/group-home' ); 488 break; 489 } 490 } else { 491 $bp['current_action'] = 'my-groups'; 492 bp_catch_uri( 'groups/index' ); 493 } 494 } else { 495 $bp['current_action'] = 'my-groups'; 496 bp_catch_uri( 'groups/index' ); 497 } 498 break; 499 } 500 } 501 } 502 add_action( 'wp', 'groups_catch_action', 3 ); 503 510 $content = bp_core_get_userlink($bp['current_userid']) . ' ' . __('wrote on the wire of the group') . ' ' . '<a href="' . $bp['current_domain'] . $bp['groups']['slug'] . '/' . $group->slug . '">' . $group->name . '</a>: <span class="time-since">%s</span>'; 511 $content .= '<blockquote>' . bp_create_excerpt($wire_post->content) . '</blockquote>'; 512 return $content; 513 break; 514 } 515 516 return false; 517 } 504 518 505 519 /************************************************************************** … … 707 721 case '4': 708 722 groups_send_invites($group); 709 723 724 do_action( 'bp_groups_created_group', array( 'item_id' => $group->id, 'component_name' => 'groups', 'component_action' => 'created_group', 'is_private' => 0 ) ); 725 710 726 header( "Location: " . $bp['loggedin_domain'] . $bp['groups']['slug'] . "/" . $group->slug ); 711 727 … … 731 747 return $slug; 732 748 } 733 734 /**************************************************************************735 groups_is_user_admin()736 737 Check if a user is an administrator of a group.738 **************************************************************************/739 749 740 750 function groups_is_user_admin( $user_id, $group_id ) { … … 786 796 } 787 797 788 function groups_leave_group( $group_id ) {789 global $bp;790 791 // This is exactly the same as deleting and invite, just is_confirmed = 1 NOT 0.792 if ( !groups_uninvite_user( $bp['loggedin_userid'], $group_id ) )793 return false;794 795 return true;796 }797 798 798 799 function groups_send_invites( $group_obj ) { … … 818 819 wp_mail( $invited_user->email, __("New Group Invitation:") . $group_obj->name, $message, "From: noreply@" . $_SERVER[ 'HTTP_HOST' ] ); 819 820 } 821 } 822 823 function groups_leave_group( $group_id ) { 824 global $bp; 825 826 // This is exactly the same as deleting and invite, just is_confirmed = 1 NOT 0. 827 if ( !groups_uninvite_user( $bp['loggedin_userid'], $group_id ) ) 828 return false; 829 830 return true; 820 831 } 821 832 … … 835 846 return false; 836 847 848 do_action( 'bp_groups_joined_group', array( 'item_id' => $new_member->group_id, 'component_name' => 'groups', 'component_action' => 'joined_group', 'is_private' => 0 ) ); 849 837 850 return true; 838 851 } 852 853 function groups_new_wire_post( $group_id, $content ) { 854 if ( $wire_post_id = bp_wire_new_post( $group_id, $content ) ) { 855 do_action( 'bp_groups_new_wire_post', array( 'item_id' => $wire_post_id, 'component_name' => 'groups', 'component_action' => 'new_wire_post', 'is_private' => 0 ) ); 856 return true; 857 } 858 859 return false; 860 } 861 862 function groups_delete_wire_post( $wire_post_id, $table_name ) { 863 if ( bp_wire_delete_post( $wire_post_id, $table_name ) ) { 864 do_action( 'bp_groups_deleted_wire_post', array( 'wire_post_id' => $wire_post_id ) ); 865 return true; 866 } 867 868 return false; 869 } 870 871 839 872 ?>
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)