Changeset 3728 for trunk/bp-groups.php
- Timestamp:
- 01/18/2011 12:53:31 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-groups.php
r3648 r3728 1 1 <?php 2 3 // Required Files 2 4 require ( BP_PLUGIN_DIR . '/bp-groups/bp-groups-classes.php' ); 3 5 require ( BP_PLUGIN_DIR . '/bp-groups/bp-groups-templatetags.php' ); … … 14 16 global $bp; 15 17 18 // Define a slug, if necessary 16 19 if ( !defined( 'BP_GROUPS_SLUG' ) ) 17 define ( 'BP_GROUPS_SLUG', $bp->pages->groups->slug ); 18 19 /* For internal identification */ 20 $bp->groups->id = 'groups'; 21 $bp->groups->name = $bp->pages->groups->name; 22 $bp->groups->slug = BP_GROUPS_SLUG; 23 20 define ( 'BP_GROUPS_SLUG', bp_core_component_slug_from_root_slug( $bp->pages->groups->slug ) ); 21 22 // For internal identification 23 $bp->groups->id = 'groups'; 24 $bp->groups->name = $bp->pages->groups->name; 25 26 // Slugs 27 $bp->groups->slug = BP_GROUPS_SLUG; 28 $bp->groups->root_slug = $bp->pages->groups->slug; 29 30 // Tables 24 31 $bp->groups->table_name = $bp->table_prefix . 'bp_groups'; 25 32 $bp->groups->table_name_members = $bp->table_prefix . 'bp_groups_members'; 26 33 $bp->groups->table_name_groupmeta = $bp->table_prefix . 'bp_groups_groupmeta'; 27 34 35 // Notifications 28 36 $bp->groups->format_notification_function = 'groups_format_notifications'; 29 37 30 / * Register this in the active components array */38 // Register this in the active components array 31 39 $bp->active_components[$bp->groups->slug] = $bp->groups->id; 32 40 … … 34 42 35 43 $bp->groups->group_creation_steps = apply_filters( 'groups_create_group_steps', array( 36 'group-details' => array( 'name' => __( 'Details', 'buddypress' ), 'position' => 0 ),44 'group-details' => array( 'name' => __( 'Details', 'buddypress' ), 'position' => 0 ), 37 45 'group-settings' => array( 'name' => __( 'Settings', 'buddypress' ), 'position' => 10 ), 38 'group-avatar' => array( 'name' => __( 'Avatar', 'buddypress' ), 'position' => 20 ),46 'group-avatar' => array( 'name' => __( 'Avatar', 'buddypress' ), 'position' => 20 ), 39 47 ) ); 40 48 … … 48 56 49 57 // The default text for the groups directory search box 50 58 $bp->default_search_strings[$bp->groups->slug] = __( 'Search Groups...', 'buddypress' ); 51 59 52 60 do_action( 'groups_setup_globals' ); … … 57 65 global $bp; 58 66 59 if ( $bp->current_component == $bp->groups->slug&& $group_id = BP_Groups_Group::group_exists($bp->current_action) ) {60 61 / * This is a single group page. */67 if ( bp_is_current_component( $bp->groups->slug ) && $group_id = BP_Groups_Group::group_exists($bp->current_action) ) { 68 69 // This is a single group page. 62 70 $bp->is_single_item = true; 63 71 $bp->groups->current_group = new BP_Groups_Group( $group_id ); 64 72 65 / * Using "item" not "group" for generic support in other components. */73 // Using "item" not "group" for generic support in other components. 66 74 if ( is_super_admin() ) 67 75 $bp->is_item_admin = 1; … … 69 77 $bp->is_item_admin = groups_is_user_admin( $bp->loggedin_user->id, $bp->groups->current_group->id ); 70 78 71 / * If the user is not an admin, check if they are a moderator */79 // If the user is not an admin, check if they are a moderator 72 80 if ( !$bp->is_item_admin ) 73 81 $bp->is_item_mod = groups_is_user_mod( $bp->loggedin_user->id, $bp->groups->current_group->id ); 74 82 75 / * Is the logged in user a member of the group? */83 // Is the logged in user a member of the group? 76 84 $bp->groups->current_group->is_user_member = ( is_user_logged_in() && groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) ? true : false; 77 85 78 / * Should this group be visible to the logged in user? */86 // Should this group be visible to the logged in user? 79 87 $bp->groups->current_group->is_group_visible_to_member = ( 'public' == $bp->groups->current_group->status || $bp->groups->current_group->is_user_member ) ? true : false; 80 88 } 81 89 82 / * Add 'Groups' to the main navigation */83 bp_core_new_nav_item( array( 'name' => sprintf( __( 'Groups <span>(%d)</span>', 'buddypress' ), groups_total_groups_for_user() ), 'slug' => $bp->groups-> name, 'position' => 70, 'screen_function' => 'groups_screen_my_groups', 'default_subnav_slug' => 'my-groups', 'item_css_id' => $bp->groups->id ) );84 85 $groups_link = $bp->loggedin_user->domain . $bp->groups-> name. '/';86 87 / * Add the subnav items to the groups nav item */88 bp_core_new_subnav_item( array( 'name' => __( 'My Groups', 'buddypress' ), 'slug' => 'my-groups', 'parent_url' => $groups_link, 'parent_slug' => $bp->groups-> name, 'screen_function' => 'groups_screen_my_groups', 'position' => 10, 'item_css_id'=> 'groups-my-groups' ) );89 bp_core_new_subnav_item( array( 'name' => __( 'Invites', 'buddypress' ), 'slug' => 'invites', 'parent_url' => $groups_link, 'parent_slug' => $bp->groups->name, 'screen_function' => 'groups_screen_group_invites', 'position' => 30, 'user_has_access' => bp_is_my_profile() ) );90 91 if ( $bp->current_component == $bp->groups->slug) {90 // Add 'Groups' to the main navigation 91 bp_core_new_nav_item( array( 'name' => sprintf( __( 'Groups <span>(%d)</span>', 'buddypress' ), groups_total_groups_for_user() ), 'slug' => $bp->groups->slug, 'position' => 70, 'screen_function' => 'groups_screen_my_groups', 'default_subnav_slug' => 'my-groups', 'item_css_id' => $bp->groups->id ) ); 92 93 $groups_link = $bp->loggedin_user->domain . $bp->groups->slug . '/'; 94 95 // Add the subnav items to the groups nav item 96 bp_core_new_subnav_item( array( 'name' => __( 'My Groups', 'buddypress' ), 'slug' => 'my-groups', 'parent_url' => $groups_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_my_groups', 'position' => 10, 'item_css_id' => 'groups-my-groups' ) ); 97 bp_core_new_subnav_item( array( 'name' => __( 'Invites', 'buddypress' ), 'slug' => 'invites', 'parent_url' => $groups_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_invites', 'position' => 30, 'user_has_access' => bp_is_my_profile() ) ); 98 99 if ( bp_is_current_component( $bp->groups->slug ) ) { 92 100 93 101 if ( bp_is_my_profile() && !$bp->is_single_item ) { … … 104 112 // group navigation menu using the $bp->groups->current_group global. 105 113 106 / *When in a single group, the first action is bumped down one because of the107 group name, so we need to adjust this and set the group name to current_item. */108 $bp->current_item = isset( $bp->current_action ) ? $bp->current_action: false;114 // When in a single group, the first action is bumped down one because of the 115 // group name, so we need to adjust this and set the group name to current_item. 116 $bp->current_item = isset( $bp->current_action ) ? $bp->current_action : false; 109 117 $bp->current_action = isset( $bp->action_variables[0] ) ? $bp->action_variables[0] : false; 110 array_shift( $bp->action_variables);118 array_shift( $bp->action_variables ); 111 119 112 120 $bp->bp_options_title = $bp->groups->current_group->name; … … 115 123 $bp->bp_options_avatar = '<img src="' . esc_attr( $group->avatar_full ) . '" class="avatar" alt="' . esc_attr( $group->name ) . '" />'; 116 124 117 $group_link = $bp->root_domain . '/' . $bp->groups-> slug . '/' . $bp->groups->current_group->slug . '/';125 $group_link = $bp->root_domain . '/' . $bp->groups->root_slug . '/' . $bp->groups->current_group->slug . '/'; 118 126 119 127 // If this is a private or hidden group, does the user have access? … … 127 135 } 128 136 129 / * Reset the existing subnav items */130 bp_core_reset_subnav_items( $bp->groups->slug);131 132 / * Add a new default subnav item for when the groups nav is selected. */133 bp_core_new_nav_default( array( 'parent_slug' => $bp->groups-> slug, 'screen_function' => 'groups_screen_group_home', 'subnav_slug' => 'home' ) );134 135 / * Add the "Home" subnav item, as this will always be present */136 bp_core_new_subnav_item( array( 'name' => __( 'Home', 'buddypress' ), 'slug' => 'home', 'parent_url' => $group_link, 'parent_slug' => $bp->groups-> slug, 'screen_function' => 'groups_screen_group_home', 'position' => 10, 'item_css_id' => 'home' ) );137 138 / * If the user is a group mod or more, then show the group admin nav item */137 // Reset the existing subnav items 138 bp_core_reset_subnav_items( $bp->groups->root_slug ); 139 140 // Add a new default subnav item for when the groups nav is selected. 141 bp_core_new_nav_default( array( 'parent_slug' => $bp->groups->root_slug, 'screen_function' => 'groups_screen_group_home', 'subnav_slug' => 'home' ) ); 142 143 // Add the "Home" subnav item, as this will always be present 144 bp_core_new_subnav_item( array( 'name' => __( 'Home', 'buddypress' ), 'slug' => 'home', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->root_slug, 'screen_function' => 'groups_screen_group_home', 'position' => 10, 'item_css_id' => 'home' ) ); 145 146 // If the user is a group mod or more, then show the group admin nav item 139 147 if ( $bp->is_item_mod || $bp->is_item_admin ) 140 bp_core_new_subnav_item( array( 'name' => __( 'Admin', 'buddypress' ), 'slug' => 'admin', 'parent_url' => $group_link, 'parent_slug' => $bp->groups-> slug, 'screen_function' => 'groups_screen_group_admin', 'position' => 20, 'user_has_access' => ( $bp->is_item_admin + (int)$bp->is_item_mod ), 'item_css_id' => 'admin' ) );148 bp_core_new_subnav_item( array( 'name' => __( 'Admin', 'buddypress' ), 'slug' => 'admin', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->root_slug, 'screen_function' => 'groups_screen_group_admin', 'position' => 20, 'user_has_access' => ( $bp->is_item_admin + (int)$bp->is_item_mod ), 'item_css_id' => 'admin' ) ); 141 149 142 150 // If this is a private group, and the user is not a member, show a "Request Membership" nav item. 143 151 if ( !is_super_admin() && is_user_logged_in() && !$bp->groups->current_group->is_user_member && !groups_check_for_membership_request( $bp->loggedin_user->id, $bp->groups->current_group->id ) && $bp->groups->current_group->status == 'private' ) 144 bp_core_new_subnav_item( array( 'name' => __( 'Request Membership', 'buddypress' ), 'slug' => 'request-membership', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_request_membership', 'position' => 30 ) ); 145 146 if ( $bp->groups->current_group->enable_forum && function_exists('bp_forums_setup') ) 147 bp_core_new_subnav_item( array( 'name' => __( 'Forum', 'buddypress' ), 'slug' => 'forum', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_forum', 'position' => 40, 'user_has_access' => $bp->groups->current_group->user_has_access, 'item_css_id' => 'forums' ) ); 148 149 bp_core_new_subnav_item( array( 'name' => sprintf( __( 'Members (%s)', 'buddypress' ), number_format( $bp->groups->current_group->total_member_count ) ), 'slug' => 'members', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_members', 'position' => 60, 'user_has_access' => $bp->groups->current_group->user_has_access, 'item_css_id' => 'members' ) ); 152 bp_core_new_subnav_item( array( 'name' => __( 'Request Membership', 'buddypress' ), 'slug' => 'request-membership', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->root_slug, 'screen_function' => 'groups_screen_group_request_membership', 'position' => 30 ) ); 153 154 // Forums are enabled and turned on 155 if ( $bp->groups->current_group->enable_forum && function_exists( 'bp_forums_setup' ) ) 156 bp_core_new_subnav_item( array( 'name' => __( 'Forum', 'buddypress' ), 'slug' => 'forum', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->root_slug, 'screen_function' => 'groups_screen_group_forum', 'position' => 40, 'user_has_access' => $bp->groups->current_group->user_has_access, 'item_css_id' => 'forums' ) ); 157 158 bp_core_new_subnav_item( array( 'name' => sprintf( __( 'Members (%s)', 'buddypress' ), number_format( $bp->groups->current_group->total_member_count ) ), 'slug' => 'members', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->root_slug, 'screen_function' => 'groups_screen_group_members', 'position' => 60, 'user_has_access' => $bp->groups->current_group->user_has_access, 'item_css_id' => 'members' ) ); 150 159 151 160 if ( is_user_logged_in() && groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) { 152 161 if ( bp_is_active('friends') ) 153 bp_core_new_subnav_item( array( 'name' => __( 'Send Invites', 'buddypress' ), 'slug' => 'send-invites', 'parent_url' => $group_link, 'parent_slug' => $bp->groups-> slug, 'screen_function' => 'groups_screen_group_invite', 'item_css_id' => 'invite', 'position' => 70, 'user_has_access' => $bp->groups->current_group->user_has_access ) );162 bp_core_new_subnav_item( array( 'name' => __( 'Send Invites', 'buddypress' ), 'slug' => 'send-invites', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->root_slug, 'screen_function' => 'groups_screen_group_invite', 'item_css_id' => 'invite', 'position' => 70, 'user_has_access' => $bp->groups->current_group->user_has_access ) ); 154 163 } 155 164 } … … 165 174 function groups_directory_groups_setup() { 166 175 global $bp; 167 168 if ( $bp->current_component == $bp->groups->slug&& empty( $bp->current_action ) && empty( $bp->current_item ) ) {176 177 if ( bp_is_current_component( $bp->groups->slug ) && empty( $bp->current_action ) && empty( $bp->current_item ) ) { 169 178 $bp->is_directory = true; 170 179 … … 181 190 return false; 182 191 183 / * Don't show this menu to non site admins or if you're viewing your own profile */192 // Don't show this menu to non site admins or if you're viewing your own profile 184 193 if ( !is_super_admin() ) 185 return false; 186 ?> 194 return false; ?> 195 187 196 <li id="bp-adminbar-adminoptions-menu"> 188 197 <a href=""><?php _e( 'Admin Options', 'buddypress' ) ?></a> … … 192 201 193 202 <?php do_action( 'groups_adminbar_menu_items' ) ?> 203 194 204 </ul> 195 205 </li> 206 196 207 <?php 197 208 } 198 209 add_action( 'bp_adminbar_menus', 'groups_setup_adminbar_menu', 20 ); 199 200 210 201 211 /******************************************************************************** … … 210 220 global $bp; 211 221 212 if ( isset($_GET['n']) ) {213 // Delete group request notifications for the user222 // Delete group request notifications for the user 223 if ( isset( $_GET['n'] ) ) { 214 224 bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'membership_request_accepted' ); 215 225 bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'membership_request_rejected' ); 216 bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'member_promoted_to_mod' );217 bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'member_promoted_to_admin' );226 bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'member_promoted_to_mod' ); 227 bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'member_promoted_to_admin' ); 218 228 } 219 229 … … 231 241 232 242 if ( isset( $bp->action_variables ) && in_array( 'accept', (array)$bp->action_variables ) && is_numeric( $group_id ) ) { 233 / * Check the nonce */243 // Check the nonce 234 244 if ( !check_admin_referer( 'groups_accept_invite' ) ) 235 245 return false; … … 240 250 bp_core_add_message( __('Group invite accepted', 'buddypress') ); 241 251 242 / * Record this in activity streams */252 // Record this in activity streams 243 253 $group = new BP_Groups_Group( $group_id ); 244 254 245 255 groups_record_activity( array( 246 'action' => apply_filters( 'groups_activity_accepted_invite_action', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), $bp->loggedin_user->id, &$group ),247 'type' => 'joined_group',256 'action' => apply_filters( 'groups_activity_accepted_invite_action', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), $bp->loggedin_user->id, &$group ), 257 'type' => 'joined_group', 248 258 'item_id' => $group->id 249 259 ) ); … … 253 263 254 264 } elseif ( isset( $bp->action_variables ) && in_array( 'reject', (array)$bp->action_variables ) && is_numeric( $group_id ) ) { 255 / * Check the nonce */265 // Check the nonce 256 266 if ( !check_admin_referer( 'groups_reject_invite' ) ) 257 267 return false; … … 277 287 278 288 if ( $bp->is_single_item ) { 279 if ( isset($_GET['n']) ) { 280 // Delete group request notifications for the user 289 if ( isset( $_GET['n'] ) ) { 281 290 bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'membership_request_accepted' ); 282 291 bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'membership_request_rejected' ); 283 bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'member_promoted_to_mod' );284 bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'member_promoted_to_admin' );292 bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'member_promoted_to_mod' ); 293 bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'member_promoted_to_admin' ); 285 294 } 286 295 … … 296 305 if ( $bp->is_single_item && $bp->groups->current_group->user_has_access ) { 297 306 298 /* Fetch the details we need */ 299 $topic_slug = isset( $bp->action_variables[1] ) ? $bp->action_variables[1] : false; 300 $topic_id = bp_forums_get_topic_id_from_slug( $topic_slug ); 301 $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ); 302 307 // Fetch the details we need 308 $topic_slug = isset( $bp->action_variables[1] ) ? $bp->action_variables[1] : false; 309 $topic_id = bp_forums_get_topic_id_from_slug( $topic_slug ); 310 $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ); 303 311 $user_is_banned = false; 312 304 313 if ( !is_super_admin() && groups_is_user_banned( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) 305 314 $user_is_banned = true; … … 307 316 if ( $topic_slug && $topic_id ) { 308 317 309 / * Posting a reply */318 // Posting a reply 310 319 if ( !$user_is_banned && !isset( $bp->action_variables[2] ) && isset( $_POST['submit_reply'] ) ) { 311 / * Check the nonce */320 // Check the nonce 312 321 check_admin_referer( 'bp_forums_new_reply' ); 313 322 314 / * Auto join this user if they are not yet a member of this group */323 // Auto join this user if they are not yet a member of this group 315 324 if ( $bp->groups->auto_join && !is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) 316 325 groups_join_group( $bp->groups->current_group->id, $bp->loggedin_user->id ); 317 326 318 327 $topic_page = isset( $_GET['topic_page'] ) ? $_GET['topic_page'] : false; 319 328 320 329 if ( !$post_id = groups_new_group_forum_post( $_POST['reply_text'], $topic_id, $topic_page ) ) … … 329 338 } 330 339 331 / * Sticky a topic */340 // Sticky a topic 332 341 else if ( isset( $bp->action_variables[2] ) && 'stick' == $bp->action_variables[2] && ( isset( $bp->is_item_admin ) || isset( $bp->is_item_mod ) ) ) { 333 / * Check the nonce */342 // Check the nonce 334 343 check_admin_referer( 'bp_forums_stick_topic' ); 335 344 … … 343 352 } 344 353 345 / * Un-Sticky a topic */354 // Un-Sticky a topic 346 355 else if ( isset( $bp->action_variables[2] ) && 'unstick' == $bp->action_variables[2] && ( isset( $bp->is_item_admin ) || isset( $bp->is_item_mod ) ) ) { 347 / * Check the nonce */356 // Check the nonce 348 357 check_admin_referer( 'bp_forums_unstick_topic' ); 349 358 … … 357 366 } 358 367 359 / * Close a topic */368 // Close a topic 360 369 else if ( isset( $bp->action_variables[2] ) && 'close' == $bp->action_variables[2] && ( isset( $bp->is_item_admin ) || isset( $bp->is_item_mod ) ) ) { 361 / * Check the nonce */370 // Check the nonce 362 371 check_admin_referer( 'bp_forums_close_topic' ); 363 372 … … 371 380 } 372 381 373 / * Open a topic */382 // Open a topic 374 383 else if ( isset( $bp->action_variables[2] ) && 'open' == $bp->action_variables[2] && ( isset( $bp->is_item_admin ) || isset( $bp->is_item_mod ) ) ) { 375 / * Check the nonce */384 // Check the nonce 376 385 check_admin_referer( 'bp_forums_open_topic' ); 377 386 … … 385 394 } 386 395 387 / * Delete a topic */396 // Delete a topic 388 397 else if ( !$user_is_banned && isset( $bp->action_variables[2] ) && 'delete' == $bp->action_variables[2] && empty( $bp->action_variables[3] ) ) { 389 / * Fetch the topic */398 // Fetch the topic 390 399 $topic = bp_forums_get_topic_details( $topic_id ); 391 400 … … 394 403 bp_core_redirect( wp_get_referer() ); 395 404 396 / * Check the nonce */405 // Check the nonce 397 406 check_admin_referer( 'bp_forums_delete_topic' ); 398 407 … … 407 416 } 408 417 409 / * Editing a topic */418 // Editing a topic 410 419 else if ( !$user_is_banned && isset( $bp->action_variables[2] ) && 'edit' == $bp->action_variables[2] && empty( $bp->action_variables[3] ) ) { 411 / * Fetch the topic */420 // Fetch the topic 412 421 $topic = bp_forums_get_topic_details( $topic_id ); 413 422 414 / * Check the logged in user can edit this topic */423 // Check the logged in user can edit this topic 415 424 if ( !$bp->is_item_admin && !$bp->is_item_mod && (int)$bp->loggedin_user->id != (int)$topic->topic_poster ) 416 425 bp_core_redirect( wp_get_referer() ); 417 426 418 427 if ( isset( $_POST['save_changes'] ) ) { 419 / * Check the nonce */428 // Check the nonce 420 429 check_admin_referer( 'bp_forums_edit_topic' ); 421 430 … … 432 441 } 433 442 434 / * Delete a post */443 // Delete a post 435 444 else if ( !$user_is_banned && isset( $bp->action_variables[2] ) && 'delete' == $bp->action_variables[2] && isset( $bp->action_variables[4] ) && $post_id = $bp->action_variables[4] ) { 436 / * Fetch the post */445 // Fetch the post 437 446 $post = bp_forums_get_post( $post_id ); 438 447 439 / * Check the logged in user can edit this topic */448 // Check the logged in user can edit this topic 440 449 if ( !$bp->is_item_admin && !$bp->is_item_mod && (int)$bp->loggedin_user->id != (int)$post->poster_id ) 441 450 bp_core_redirect( wp_get_referer() ); 442 451 443 / * Check the nonce */452 // Check the nonce 444 453 check_admin_referer( 'bp_forums_delete_post' ); 445 454 … … 455 464 } 456 465 457 / * Editing a post */466 // Editing a post 458 467 else if ( !$user_is_banned && isset( $bp->action_variables[2] ) && 'edit' == $bp->action_variables[2] && isset( $bp->action_variables[4] ) && $post_id = $bp->action_variables[4] ) { 459 / * Fetch the post */468 // Fetch the post 460 469 $post = bp_forums_get_post( $bp->action_variables[4] ); 461 470 462 / * Check the logged in user can edit this topic */471 // Check the logged in user can edit this topic 463 472 if ( !$bp->is_item_admin && !$bp->is_item_mod && (int)$bp->loggedin_user->id != (int)$post->poster_id ) 464 473 bp_core_redirect( wp_get_referer() ); 465 474 466 475 if ( isset( $_POST['save_changes'] ) ) { 467 / * Check the nonce */476 // Check the nonce 468 477 check_admin_referer( 'bp_forums_edit_post' ); 469 478 … … 483 492 } 484 493 485 / * Standard topic display */494 // Standard topic display 486 495 else { 487 496 if ( $user_is_banned ) … … 492 501 493 502 } else { 494 / * Posting a topic */503 // Posting a topic 495 504 if ( isset( $_POST['submit_topic'] ) && function_exists( 'bp_forums_new_topic') ) { 496 / * Check the nonce */505 // Check the nonce 497 506 check_admin_referer( 'bp_forums_new_topic' ); 498 507 … … 578 587 // If the user has submitted a request, send it. 579 588 if ( isset( $_POST['group-request-send']) ) { 580 / * Check the nonce first. */589 // Check the nonce 581 590 if ( !check_admin_referer( 'groups_request_membership' ) ) 582 591 return false; … … 599 608 global $bp; 600 609 601 if ( $bp->current_component != $bp->groups->slug|| $bp->current_action != $bp->activity->slug || empty( $bp->action_variables[0] ) )610 if ( !bp_is_current_component( $bp->groups->slug ) || $bp->current_action != $bp->activity->slug || empty( $bp->action_variables[0] ) ) 602 611 return false; 603 612 … … 611 620 global $bp; 612 621 613 if ( $bp->current_component != BP_GROUPS_SLUG|| 'admin' != $bp->current_action )622 if ( !bp_is_current_component( BP_GROUPS_SLUG ) || 'admin' != $bp->current_action ) 614 623 return false; 615 624 … … 623 632 global $bp; 624 633 625 if ( $bp->current_component == $bp->groups->slug&& 'edit-details' == $bp->action_variables[0] ) {634 if ( bp_is_current_component( $bp->groups->slug ) && 'edit-details' == $bp->action_variables[0] ) { 626 635 627 636 if ( $bp->is_item_admin || $bp->is_item_mod ) { … … 629 638 // If the edit form has been submitted, save the edited details 630 639 if ( isset( $_POST['save'] ) ) { 631 / * Check the nonce first. */640 // Check the nonce 632 641 if ( !check_admin_referer( 'groups_edit_group_details' ) ) 633 642 return false; … … 655 664 global $bp; 656 665 657 if ( $bp->current_component == $bp->groups->slug&& 'group-settings' == $bp->action_variables[0] ) {666 if ( bp_is_current_component( $bp->groups->slug ) && 'group-settings' == $bp->action_variables[0] ) { 658 667 659 668 if ( !$bp->is_item_admin ) … … 667 676 $status = ( in_array( $_POST['group-status'], (array)$allowed_status ) ) ? $_POST['group-status'] : 'public'; 668 677 669 / * Check the nonce first. */678 // Check the nonce 670 679 if ( !check_admin_referer( 'groups_edit_group_settings' ) ) 671 680 return false; … … 692 701 global $bp; 693 702 694 if ( $bp->current_component == $bp->groups->slug&& 'group-avatar' == $bp->action_variables[0] ) {703 if ( bp_is_current_component( $bp->groups->slug ) && 'group-avatar' == $bp->action_variables[0] ) { 695 704 696 705 if ( !$bp->is_item_admin ) 697 706 return false; 698 707 699 / * If the group admin has deleted the admin avatar */708 // If the group admin has deleted the admin avatar 700 709 if ( 'delete' == $bp->action_variables[1] ) { 701 710 702 / * Check the nonce */711 // Check the nonce 703 712 check_admin_referer( 'bp_group_avatar_delete' ); 704 713 … … 714 723 if ( !empty( $_FILES ) ) { 715 724 716 / * Check the nonce */725 // Check the nonce 717 726 check_admin_referer( 'bp_avatar_upload' ); 718 727 719 / * Pass the file to the avatar upload handler */728 // Pass the file to the avatar upload handler 720 729 if ( bp_core_avatar_handle_upload( $_FILES, 'groups_avatar_upload_dir' ) ) { 721 730 $bp->avatar_admin->step = 'crop-image'; 722 731 723 / * Make sure we include the jQuery jCrop file for image cropping */732 // Make sure we include the jQuery jCrop file for image cropping 724 733 add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' ); 725 734 } … … 727 736 } 728 737 729 / * If the image cropping is done, crop the image and save a full/thumb version */738 // If the image cropping is done, crop the image and save a full/thumb version 730 739 if ( isset( $_POST['avatar-crop-submit'] ) ) { 731 740 732 / * Check the nonce */741 // Check the nonce 733 742 check_admin_referer( 'bp_avatar_cropstore' ); 734 743 … … 750 759 global $bp; 751 760 752 if ( $bp->current_component == $bp->groups->slug&& 'manage-members' == $bp->action_variables[0] ) {761 if ( bp_is_current_component( $bp->groups->slug ) && 'manage-members' == $bp->action_variables[0] ) { 753 762 754 763 if ( !$bp->is_item_admin ) … … 856 865 global $bp; 857 866 858 if ( $bp->current_component == $bp->groups->slug&& 'membership-requests' == $bp->action_variables[0] ) {859 860 / * Ask for a login if the user is coming here via an email notification */867 if ( bp_is_current_component( $bp->groups->slug ) && 'membership-requests' == $bp->action_variables[0] ) { 868 869 // Ask for a login if the user is coming here via an email notification 861 870 if ( !is_user_logged_in() ) 862 871 bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/admin/membership-requests/' ) ); … … 874 883 if ( 'accept' == $request_action && is_numeric($membership_id) ) { 875 884 876 / * Check the nonce first. */885 // Check the nonce first. 877 886 if ( !check_admin_referer( 'groups_accept_membership_request' ) ) 878 887 return false; … … 914 923 global $bp; 915 924 916 if ( $bp->current_component == $bp->groups->slug&& 'delete-group' == $bp->action_variables[0] ) {925 if ( bp_is_current_component( $bp->groups->slug ) && 'delete-group' == $bp->action_variables[0] ) { 917 926 918 927 if ( !$bp->is_item_admin && !is_super_admin() ) … … 920 929 921 930 if ( isset( $_REQUEST['delete-group-button'] ) && isset( $_REQUEST['delete-group-understand'] ) ) { 922 / * Check the nonce first. */931 // Check the nonce first. 923 932 if ( !check_admin_referer( 'groups_delete_group' ) ) 924 933 return false; … … 950 959 global $bp; 951 960 952 $group_invite = get_user_meta( $bp->displayed_user->id, 'notification_groups_invite', true ); 953 if ( !$group_invite ) 954 $group_invite = 'yes'; 955 956 $group_update = get_user_meta( $bp->displayed_user->id, 'notification_groups_group_updated', true ); 957 if ( !$group_update ) 958 $group_update = 'yes'; 959 960 $group_promo = get_user_meta( $bp->displayed_user->id, 'notification_groups_admin_promotion', true ); 961 if ( !$group_promo ) 962 $group_promo = 'yes'; 963 964 $group_request = get_user_meta( $bp->displayed_user->id, 'notification_groups_membership_request', true ); 965 if ( !$group_request ) 961 if ( !$group_invite = get_user_meta( $bp->displayed_user->id, 'notification_groups_invite', true ) ) 962 $group_invite = 'yes'; 963 964 if ( !$group_update = get_user_meta( $bp->displayed_user->id, 'notification_groups_group_updated', true ) ) 965 $group_update = 'yes'; 966 967 if ( !$group_promo = get_user_meta( $bp->displayed_user->id, 'notification_groups_admin_promotion', true ) ) 968 $group_promo = 'yes'; 969 970 if ( !$group_request = get_user_meta( $bp->displayed_user->id, 'notification_groups_membership_request', true ) ) 966 971 $group_request = 'yes'; 967 972 ?> 973 968 974 <table class="notification-settings zebra" id="groups-notification-settings"> 969 975 <thead> … … 1003 1009 1004 1010 <?php do_action( 'groups_screen_notification_settings' ); ?> 1011 1005 1012 </tbody> 1006 1013 </table> 1014 1007 1015 <?php 1008 1016 } … … 1021 1029 global $bp; 1022 1030 1023 / * If we're not at domain.org/groups/create/ then return false */1024 if ( $bp->current_component != $bp->groups->slug|| 'create' != $bp->current_action )1031 // If we're not at domain.org/groups/create/ then return false 1032 if ( !bp_is_current_component( $bp->groups->slug ) || 'create' != $bp->current_action ) 1025 1033 return false; 1026 1034 … … 1028 1036 return false; 1029 1037 1030 / * Make sure creation steps are in the right order */1038 // Make sure creation steps are in the right order 1031 1039 groups_action_sort_creation_steps(); 1032 1040 1033 / * If no current step is set, reset everything so we can start a fresh group creation */1041 // If no current step is set, reset everything so we can start a fresh group creation 1034 1042 if ( !isset( $bp->action_variables[1] ) || !$bp->groups->current_create_step = $bp->action_variables[1] ) { 1035 1043 … … 1041 1049 1042 1050 $reset_steps = true; 1043 bp_core_redirect( $bp->root_domain . '/' . $bp->groups-> slug . '/create/step/' . array_shift( array_keys( $bp->groups->group_creation_steps ) ) . '/' );1044 } 1045 1046 / * If this is a creation step that is not recognized, just redirect them back to the first screen */1051 bp_core_redirect( $bp->root_domain . '/' . $bp->groups->root_slug . '/create/step/' . array_shift( array_keys( $bp->groups->group_creation_steps ) ) . '/' ); 1052 } 1053 1054 // If this is a creation step that is not recognized, just redirect them back to the first screen 1047 1055 if ( $bp->action_variables[1] && !$bp->groups->group_creation_steps[$bp->action_variables[1]] ) { 1048 1056 bp_core_add_message( __('There was an error saving group details. Please try again.', 'buddypress'), 'error' ); 1049 bp_core_redirect( $bp->root_domain . '/' . $bp->groups-> slug . '/create/' );1050 } 1051 1052 / * Fetch the currently completed steps variable */1057 bp_core_redirect( $bp->root_domain . '/' . $bp->groups->root_slug . '/create/' ); 1058 } 1059 1060 // Fetch the currently completed steps variable 1053 1061 if ( isset( $_COOKIE['bp_completed_create_steps'] ) && !isset( $reset_steps ) ) 1054 1062 $bp->groups->completed_create_steps = unserialize( stripslashes( $_COOKIE['bp_completed_create_steps'] ) ); 1055 1063 1056 / * Set the ID of the new group, if it has already been created in a previous step */1064 // Set the ID of the new group, if it has already been created in a previous step 1057 1065 if ( isset( $_COOKIE['bp_new_group_id'] ) ) { 1058 1066 $bp->groups->new_group_id = $_COOKIE['bp_new_group_id']; … … 1060 1068 } 1061 1069 1062 / * If the save, upload or skip button is hit, lets calculate what we need to save */1070 // If the save, upload or skip button is hit, lets calculate what we need to save 1063 1071 if ( isset( $_POST['save'] ) ) { 1064 1072 1065 / * Check the nonce */1073 // Check the nonce 1066 1074 check_admin_referer( 'groups_create_save_' . $bp->groups->current_create_step ); 1067 1075 … … 1069 1077 if ( empty( $_POST['group-name'] ) || empty( $_POST['group-desc'] ) || !strlen( trim( $_POST['group-name'] ) ) || !strlen( trim( $_POST['group-desc'] ) ) ) { 1070 1078 bp_core_add_message( __( 'Please fill in all of the required fields', 'buddypress' ), 'error' ); 1071 bp_core_redirect( $bp->root_domain . '/' . $bp->groups-> slug . '/create/step/' . $bp->groups->current_create_step . '/' );1079 bp_core_redirect( $bp->root_domain . '/' . $bp->groups->root_slug . '/create/step/' . $bp->groups->current_create_step . '/' ); 1072 1080 } 1073 1081 … … 1076 1084 if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug( sanitize_title( esc_attr( $_POST['group-name'] ) ) ), 'date_created' => bp_core_current_time(), 'status' => 'public' ) ) ) { 1077 1085 bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' ); 1078 bp_core_redirect( $bp->root_domain . '/' . $bp->groups-> slug . '/create/step/' . $bp->groups->current_create_step . '/' );1086 bp_core_redirect( $bp->root_domain . '/' . $bp->groups->root_slug . '/create/step/' . $bp->groups->current_create_step . '/' ); 1079 1087 } 1080 1088 … … 1090 1098 $group_enable_forum = 0; 1091 1099 } else { 1092 / * Create the forum if enable_forum = 1 */1100 // Create the forum if enable_forum = 1 1093 1101 if ( function_exists( 'bp_forums_setup' ) && '' == groups_get_groupmeta( $bp->groups->new_group_id, 'forum_id' ) ) { 1094 1102 groups_new_group_forum(); … … 1103 1111 if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_forum' => $group_enable_forum ) ) ) { 1104 1112 bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' ); 1105 bp_core_redirect( $bp->root_domain . '/' . $bp->groups-> slug . '/create/step/' . $bp->groups->current_create_step . '/' );1113 bp_core_redirect( $bp->root_domain . '/' . $bp->groups->root_slug . '/create/step/' . $bp->groups->current_create_step . '/' ); 1106 1114 } 1107 1115 } 1108 1116 1109 if ( 'group-invites' == $bp->groups->current_create_step ) {1117 if ( 'group-invites' == $bp->groups->current_create_step ) 1110 1118 groups_send_invites( $bp->loggedin_user->id, $bp->groups->new_group_id ); 1111 }1112 1119 1113 1120 do_action( 'groups_create_group_step_save_' . $bp->groups->current_create_step ); … … 1123 1130 $bp->groups->completed_create_steps[] = $bp->groups->current_create_step; 1124 1131 1125 / * Reset cookie info */1132 // Reset cookie info 1126 1133 setcookie( 'bp_new_group_id', $bp->groups->new_group_id, time()+60*60*24, COOKIEPATH ); 1127 1134 setcookie( 'bp_completed_create_steps', serialize( $bp->groups->completed_create_steps ), time()+60*60*24, COOKIEPATH ); 1128 1135 1129 /* If we have completed all steps and hit done on the final step we can redirect to the completed group */ 1136 // If we have completed all steps and hit done on the final step we 1137 // can redirect to the completed group 1130 1138 if ( count( $bp->groups->completed_create_steps ) == count( $bp->groups->group_creation_steps ) && $bp->groups->current_create_step == array_pop( array_keys( $bp->groups->group_creation_steps ) ) ) { 1131 1139 unset( $bp->groups->current_create_step ); 1132 1140 unset( $bp->groups->completed_create_steps ); 1133 1141 1134 / * Once we compelete all steps, record the group creation in the activity stream. */1142 // Once we compelete all steps, record the group creation in the activity stream. 1135 1143 groups_record_activity( array( 1136 1144 'action' => apply_filters( 'groups_activity_created_group_action', sprintf( __( '%1$s created the group %2$s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' ) ), … … 1159 1167 } 1160 1168 1161 bp_core_redirect( $bp->root_domain . '/' . $bp->groups-> slug . '/create/step/' . $next_step . '/' );1162 } 1163 } 1164 1165 / * Group avatar is handled separately */1169 bp_core_redirect( $bp->root_domain . '/' . $bp->groups->root_slug . '/create/step/' . $next_step . '/' ); 1170 } 1171 } 1172 1173 // Group avatar is handled separately 1166 1174 if ( 'group-avatar' == $bp->groups->current_create_step && isset( $_POST['upload'] ) ) { 1167 1175 if ( !empty( $_FILES ) && isset( $_POST['upload'] ) ) { 1168 / * Normally we would check a nonce here, but the group save nonce is used instead */1169 1170 / * Pass the file to the avatar upload handler */1176 // Normally we would check a nonce here, but the group save nonce is used instead 1177 1178 // Pass the file to the avatar upload handler 1171 1179 if ( bp_core_avatar_handle_upload( $_FILES, 'groups_avatar_upload_dir' ) ) { 1172 1180 $bp->avatar_admin->step = 'crop-image'; 1173 1181 1174 / * Make sure we include the jQuery jCrop file for image cropping */1182 // Make sure we include the jQuery jCrop file for image cropping 1175 1183 add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' ); 1176 1184 } 1177 1185 } 1178 1186 1179 / * If the image cropping is done, crop the image and save a full/thumb version */1187 // If the image cropping is done, crop the image and save a full/thumb version 1180 1188 if ( isset( $_POST['avatar-crop-submit'] ) && isset( $_POST['upload'] ) ) { 1181 / * Normally we would check a nonce here, but the group save nonce is used instead */1189 // Normally we would check a nonce here, but the group save nonce is used instead 1182 1190 1183 1191 if ( !bp_core_avatar_handle_crop( array( 'object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h'] ) ) ) … … 1195 1203 global $bp; 1196 1204 1197 if ( !$bp->is_single_item || $bp->current_component != $bp->groups->slug|| $bp->current_action != 'join' )1205 if ( !$bp->is_single_item || !bp_is_current_component( $bp->groups->slug ) || $bp->current_action != 'join' ) 1198 1206 return false; 1199 1207 … … 1230 1238 global $bp; 1231 1239 1232 if ( !$bp->is_single_item || $bp->current_component != $bp->groups->slug|| $bp->current_action != 'leave-group' )1240 if ( !$bp->is_single_item || !bp_is_current_component( $bp->groups->slug ) || $bp->current_action != 'leave-group' ) 1233 1241 return false; 1234 1242 … … 1255 1263 global $bp; 1256 1264 1257 if ( $bp->current_component != BP_GROUPS_SLUG&& $bp->current_action != 'create' )1265 if ( !bp_is_current_component( BP_GROUPS_SLUG ) && $bp->current_action != 'create' ) 1258 1266 return false; 1259 1267 … … 1268 1276 } 1269 1277 1270 / * Sort the steps by their position key */1278 // Sort the steps by their position key 1271 1279 ksort($temp); 1272 1280 unset($bp->groups->group_creation_steps); … … 1279 1287 global $bp, $wpdb; 1280 1288 1281 if ( $bp->current_component == $bp->groups->slug&& isset( $_GET['random-group'] ) ) {1289 if ( bp_is_current_component( $bp->groups->slug ) && isset( $_GET['random-group'] ) ) { 1282 1290 $group = groups_get_groups( array( 'type' => 'random', 'per_page' => 1 ) ); 1283 1291 … … 1290 1298 global $bp, $wp_query; 1291 1299 1292 if ( !bp_is_active( 'activity' ) || $bp->current_component != $bp->groups->slug|| !isset( $bp->groups->current_group ) || $bp->current_action != 'feed' )1300 if ( !bp_is_active( 'activity' ) || !bp_is_current_component( $bp->groups->slug ) || !isset( $bp->groups->current_group ) || $bp->current_action != 'feed' ) 1293 1301 return false; 1294 1302 … … 1320 1328 return false; 1321 1329 1322 bp_activity_set_action( $bp->groups->id, 'created_group', __( 'Created a group','buddypress' ) );1323 bp_activity_set_action( $bp->groups->id, 'joined_group', __( 'Joined a group','buddypress' ) );1330 bp_activity_set_action( $bp->groups->id, 'created_group', __( 'Created a group', 'buddypress' ) ); 1331 bp_activity_set_action( $bp->groups->id, 'joined_group', __( 'Joined a group', 'buddypress' ) ); 1324 1332 bp_activity_set_action( $bp->groups->id, 'new_forum_topic', __( 'New group forum topic', 'buddypress' ) ); 1325 bp_activity_set_action( $bp->groups->id, 'new_forum_post', __( 'New group forum post','buddypress' ) );1333 bp_activity_set_action( $bp->groups->id, 'new_forum_post', __( 'New group forum post', 'buddypress' ) ); 1326 1334 1327 1335 do_action( 'groups_register_activity_actions' ); … … 1335 1343 return false; 1336 1344 1337 / * If the group is not public, hide the activity sitewide. */1345 // If the group is not public, hide the activity sitewide. 1338 1346 if ( 'public' == $bp->groups->current_group->status ) 1339 1347 $hide_sitewide = false; … … 1341 1349 $hide_sitewide = true; 1342 1350 1343 $defaults = array (1344 'id' => false,1345 'user_id' => $bp->loggedin_user->id,1346 'action' => '',1347 'content' => '',1348 'primary_link' => '',1349 'component' => $bp->groups->id,1350 'type' => false,1351 'item_id' => false,1351 $defaults = array ( 1352 'id' => false, 1353 'user_id' => $bp->loggedin_user->id, 1354 'action' => '', 1355 'content' => '', 1356 'primary_link' => '', 1357 'component' => $bp->groups->id, 1358 'type' => false, 1359 'item_id' => false, 1352 1360 'secondary_item_id' => false, 1353 'recorded_time' => bp_core_current_time(),1354 'hide_sitewide' => $hide_sitewide1361 'recorded_time' => bp_core_current_time(), 1362 'hide_sitewide' => $hide_sitewide 1355 1363 ); 1356 1364 … … 1361 1369 } 1362 1370 1363 function groups_update_last_activity( $group_id = false) {1371 function groups_update_last_activity( $group_id = 0 ) { 1364 1372 global $bp; 1365 1373 … … 1395 1403 return apply_filters( 'bp_groups_single_new_membership_request_notification', '<a href="' . $group_link . 'admin/membership-requests/?n=1" title="' . sprintf( __( '%s requests group membership', 'buddypress' ), $user_fullname ) . '">' . sprintf( __( '%1$s requests membership for the group "%2$s"', 'buddypress' ), $user_fullname, $group->name ) . '</a>', $group_link, $user_fullname, $group->name ); 1396 1404 } 1397 break;1405 break; 1398 1406 1399 1407 case 'membership_request_accepted': … … 1408 1416 return apply_filters( 'bp_groups_single_membership_request_accepted_notification', '<a href="' . $group_link . '?n=1">' . sprintf( __( 'Membership for group "%s" accepted', 'buddypress' ), $group->name ) . '</a>', $group_link, $group->name ); 1409 1417 1410 break;1418 break; 1411 1419 1412 1420 case 'membership_request_rejected': … … 1421 1429 return apply_filters( 'bp_groups_single_membership_request_rejected_notification', '<a href="' . $group_link . '?n=1">' . sprintf( __( 'Membership for group "%s" rejected', 'buddypress' ), $group->name ) . '</a>', $group_link, $group->name ); 1422 1430 1423 break;1431 break; 1424 1432 1425 1433 case 'member_promoted_to_admin': … … 1434 1442 return apply_filters( 'bp_groups_single_member_promoted_to_admin_notification', '<a href="' . $group_link . '?n=1">' . sprintf( __( 'You were promoted to an admin in the group %s', 'buddypress' ), $group->name ) . '</a>', $group_link, $group->name ); 1435 1443 1436 break;1444 break; 1437 1445 1438 1446 case 'member_promoted_to_mod': … … 1447 1455 return apply_filters( 'bp_groups_single_member_promoted_to_mod_notification', '<a href="' . $group_link . '?n=1">' . sprintf( __( 'You were promoted to a mod in the group %s', 'buddypress' ), $group->name ) . '</a>', $group_link, $group->name ); 1448 1456 1449 break;1457 break; 1450 1458 1451 1459 case 'group_invite': … … 1460 1468 return apply_filters( 'bp_groups_single_group_invite_notification', '<a href="' . $bp->loggedin_user->domain . $bp->groups->slug . '/invites/?n=1" title="' . __( 'Group Invites', 'buddypress' ) . '">' . sprintf( __( 'You have an invitation to the group: %s', 'buddypress' ), $group->name ) . '</a>', $group->name ); 1461 1469 1462 break;1470 break; 1463 1471 } 1464 1472 … … 1480 1488 function groups_get_group( $args = '' ) { 1481 1489 $defaults = array( 1482 'group_id' => false,1490 'group_id' => false, 1483 1491 'load_users' => false 1484 1492 ); … … 1544 1552 return false; 1545 1553 1554 // If this is a new group, set up the creator as the first member and admin 1546 1555 if ( !$group_id ) { 1547 // If this is a new group, set up the creator as the first member and admin 1548 $member = new BP_Groups_Member; 1549 $member->group_id = $group->id; 1550 $member->user_id = $group->creator_id; 1551 $member->is_admin = 1; 1552 $member->user_title = __( 'Group Admin', 'buddypress' ); 1553 $member->is_confirmed = 1; 1556 $member = new BP_Groups_Member; 1557 $member->group_id = $group->id; 1558 $member->user_id = $group->creator_id; 1559 $member->is_admin = 1; 1560 $member->user_title = __( 'Group Admin', 'buddypress' ); 1561 $member->is_confirmed = 1; 1554 1562 $member->date_modified = bp_core_current_time(); 1555 1563 … … 1572 1580 return false; 1573 1581 1574 $group = new BP_Groups_Group( $group_id );1575 $group->name = $group_name;1582 $group = new BP_Groups_Group( $group_id ); 1583 $group->name = $group_name; 1576 1584 $group->description = $group_desc; 1577 1585 … … 1602 1610 groups_accept_all_pending_membership_requests( $group->id ); 1603 1611 1604 / * Now update the status */1612 // Now update the status 1605 1613 $group->status = $status; 1606 1614 … … 1608 1616 return false; 1609 1617 1610 / * If forums have been enabled, and a forum does not yet exist, we need to create one. */1618 // If forums have been enabled, and a forum does not yet exist, we need to create one. 1611 1619 if ( $group->enable_forum ) { 1612 1620 if ( function_exists( 'bp_forums_setup' ) && '' == groups_get_groupmeta( $group->id, 'forum_id' ) ) { … … 1675 1683 $slug = substr( $slug, 2, strlen( $slug ) - 2 ); 1676 1684 1677 if ( in_array( $slug, (array)$bp->groups->forbidden_names ) ) {1685 if ( in_array( $slug, (array)$bp->groups->forbidden_names ) ) 1678 1686 $slug = $slug . '-' . rand(); 1679 }1680 1687 1681 1688 if ( BP_Groups_Group::check_slug( $slug ) ) { … … 1696 1703 /*** User Actions ***************************************************************/ 1697 1704 1698 function groups_leave_group( $group_id, $user_id = false) {1705 function groups_leave_group( $group_id, $user_id = 0 ) { 1699 1706 global $bp; 1700 1707 … … 1702 1709 $user_id = $bp->loggedin_user->id; 1703 1710 1704 / * Don't let single admins leave the group. */1711 // Don't let single admins leave the group. 1705 1712 if ( count( groups_get_group_admins( $group_id ) ) < 2 ) { 1706 1713 if ( groups_is_user_admin( $user_id, $group_id ) ) { … … 1716 1723 return false; 1717 1724 1718 / * Modify group member count */1725 // Modify group member count 1719 1726 groups_update_groupmeta( $group_id, 'total_member_count', (int) groups_get_groupmeta( $group_id, 'total_member_count') - 1 ); 1720 1727 1721 / * Modify user's group memberhip count */1728 // Modify user's group memberhip count 1722 1729 update_user_meta( $user_id, 'total_group_count', (int) get_user_meta( $user_id, 'total_group_count', true ) - 1 ); 1723 1730 1724 /* If the user joined this group less than five minutes ago, remove the joined_group activity so 1725 * users cannot flood the activity stream by joining/leaving the group in quick succession. 1731 /** 1732 * If the user joined this group less than five minutes ago, remove the 1733 * joined_group activity so users cannot flood the activity stream by 1734 * joining/leaving the group in quick succession. 1726 1735 */ 1727 1736 if ( function_exists( 'bp_activity_delete' ) && gmmktime() <= strtotime( '+5 minutes', (int)strtotime( $membership->date_modified ) ) ) … … 1735 1744 } 1736 1745 1737 function groups_join_group( $group_id, $user_id = false) {1746 function groups_join_group( $group_id, $user_id = 0 ) { 1738 1747 global $bp; 1739 1748 … … 1753 1762 return true; 1754 1763 1755 $new_member = new BP_Groups_Member;1756 $new_member->group_id = $group_id;1757 $new_member->user_id = $user_id;1758 $new_member->inviter_id = 0;1759 $new_member->is_admin = 0;1760 $new_member->user_title = '';1764 $new_member = new BP_Groups_Member; 1765 $new_member->group_id = $group_id; 1766 $new_member->user_id = $user_id; 1767 $new_member->inviter_id = 0; 1768 $new_member->is_admin = 0; 1769 $new_member->user_title = ''; 1761 1770 $new_member->date_modified = bp_core_current_time(); 1762 $new_member->is_confirmed = 1;1771 $new_member->is_confirmed = 1; 1763 1772 1764 1773 if ( !$new_member->save() ) … … 1772 1781 // Record this in activity streams 1773 1782 groups_record_activity( array( 1774 'action' => apply_filters( 'groups_activity_joined_group', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( bp_get_group_name( $group ) ) . '</a>' ) ),1775 'type' => 'joined_group',1783 'action' => apply_filters( 'groups_activity_joined_group', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( bp_get_group_name( $group ) ) . '</a>' ) ), 1784 'type' => 'joined_group', 1776 1785 'item_id' => $group_id, 1777 1786 'user_id' => $user_id … … 1815 1824 1816 1825 $defaults = array( 1817 'type' => 'active', // active, newest, alphabetical, random, popular, most-forum-topics or most-forum-posts1818 'user_id' => false,// Pass a user_id to limit to only groups that this user is a member of1819 'include' => false,// Only include these specific groups (group_ids)1820 'exclude' => false,// Do not include these specific groups (group_ids)1821 'search_terms' => false,// Limit to groups that match these search terms1822 'show_hidden' => false,// Show hidden groups to non-admins1823 1824 'per_page' => 20,// The number of results to return per page1825 'page' => 1,// The page to return if limiting per page1826 'populate_extras' => true, // Fetch meta such as is_banned and is_member1826 'type' => 'active', // active, newest, alphabetical, random, popular, most-forum-topics or most-forum-posts 1827 'user_id' => false, // Pass a user_id to limit to only groups that this user is a member of 1828 'include' => false, // Only include these specific groups (group_ids) 1829 'exclude' => false, // Do not include these specific groups (group_ids) 1830 'search_terms' => false, // Limit to groups that match these search terms 1831 'show_hidden' => false, // Show hidden groups to non-admins 1832 1833 'per_page' => 20, // The number of results to return per page 1834 'page' => 1, // The page to return if limiting per page 1835 'populate_extras' => true, // Fetch meta such as is_banned and is_member 1827 1836 ); 1828 1837 … … 1844 1853 } 1845 1854 1846 function groups_get_user_groups( $user_id = false, $pag_num = false, $pag_page = false) {1855 function groups_get_user_groups( $user_id = 0, $pag_num = 0, $pag_page = 0 ) { 1847 1856 global $bp; 1848 1857 … … 1853 1862 } 1854 1863 1855 function groups_total_groups_for_user( $user_id = false) {1864 function groups_total_groups_for_user( $user_id = 0 ) { 1856 1865 global $bp; 1857 1866 … … 1869 1878 /*** Group Avatars *************************************************************/ 1870 1879 1871 function groups_avatar_upload_dir( $group_id = false) {1880 function groups_avatar_upload_dir( $group_id = 0 ) { 1872 1881 global $bp; 1873 1882 … … 1875 1884 $group_id = $bp->groups->current_group->id; 1876 1885 1877 $path = BP_AVATAR_UPLOAD_PATH . '/group-avatars/' . $group_id;1886 $path = BP_AVATAR_UPLOAD_PATH . '/group-avatars/' . $group_id; 1878 1887 $newbdir = $path; 1879 1888 … … 1881 1890 @wp_mkdir_p( $path ); 1882 1891 1883 $newurl = BP_AVATAR_URL . '/group-avatars/' . $group_id;1884 $newburl = $newurl;1892 $newurl = BP_AVATAR_URL . '/group-avatars/' . $group_id; 1893 $newburl = $newurl; 1885 1894 $newsubdir = '/group-avatars/' . $group_id; 1886 1895 … … 1924 1933 1925 1934 $defaults = array( 1926 'content' => false,1927 'user_id' => $bp->loggedin_user->id,1935 'content' => false, 1936 'user_id' => $bp->loggedin_user->id, 1928 1937 'group_id' => $bp->groups->current_group->id 1929 1938 ); … … 1932 1941 extract( $r, EXTR_SKIP ); 1933 1942 1934 if ( empty( $content) || !strlen( trim( $content ) ) || empty($user_id) || empty($group_id) )1943 if ( empty( $content ) || !strlen( trim( $content ) ) || empty( $user_id ) || empty( $group_id ) ) 1935 1944 return false; 1936 1945 1937 1946 $bp->groups->current_group = new BP_Groups_Group( $group_id ); 1938 1947 1939 / * Be sure the user is a member of the group before posting. */1948 // Be sure the user is a member of the group before posting. 1940 1949 if ( !is_super_admin() && !groups_is_user_member( $user_id, $group_id ) ) 1941 1950 return false; 1942 1951 1943 / * Record this in activity streams */1944 $activity_action = sprintf( __( '%1$s posted an update in the group %2$s:', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' );1952 // Record this in activity streams 1953 $activity_action = sprintf( __( '%1$s posted an update in the group %2$s:', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' ); 1945 1954 $activity_content = $content; 1946 1955 1947 1956 $activity_id = groups_record_activity( array( 1948 1957 'user_id' => $user_id, 1949 'action' => apply_filters( 'groups_activity_new_update_action', $activity_action),1958 'action' => apply_filters( 'groups_activity_new_update_action', $activity_action ), 1950 1959 'content' => apply_filters( 'groups_activity_new_update_content', $activity_content ), 1951 'type' => 'activity_update',1960 'type' => 'activity_update', 1952 1961 'item_id' => $group_id 1953 1962 ) ); 1954 1963 1955 /* Require the notifications code so email notifications can be set on the 'bp_activity_posted_update' action. */ 1964 // Require the notifications code so email notifications can be set on 1965 // the 'bp_activity_posted_update' action. 1956 1966 require_once( BP_PLUGIN_DIR . '/bp-groups/bp-groups-notifications.php' ); 1957 1967 … … 1964 1974 /*** Group Forums **************************************************************/ 1965 1975 1966 function groups_new_group_forum( $group_id = false, $group_name = false, $group_desc = false) {1976 function groups_new_group_forum( $group_id = 0, $group_name = '', $group_desc = '' ) { 1967 1977 global $bp; 1968 1978 … … 2008 2018 2009 2019 $post_text = apply_filters( 'group_forum_post_text_before_save', $post_text ); 2010 $topic_id = apply_filters( 'group_forum_post_topic_id_before_save', $topic_id );2020 $topic_id = apply_filters( 'group_forum_post_topic_id_before_save', $topic_id ); 2011 2021 2012 2022 if ( $post_id = bp_forums_insert_post( array( 'post_text' => $post_text, 'topic_id' => $topic_id ) ) ) { … … 2020 2030 $primary_link .= "?topic_page=" . $page; 2021 2031 2022 / * Record this in activity streams */2032 // Record this in activity streams 2023 2033 groups_record_activity( array( 2024 'action' => apply_filters( 'groups_activity_new_forum_post_action', $activity_action, $post_id, $post_text, &$topic ),2025 'content' => apply_filters( 'groups_activity_new_forum_post_content', $activity_content, $post_id, $post_text, &$topic ),2026 'primary_link' => apply_filters( 'groups_activity_new_forum_post_primary_link', "{$primary_link}#post-{$post_id}" ),2027 'type' => 'new_forum_post',2028 'item_id' => $bp->groups->current_group->id,2034 'action' => apply_filters( 'groups_activity_new_forum_post_action', $activity_action, $post_id, $post_text, &$topic ), 2035 'content' => apply_filters( 'groups_activity_new_forum_post_content', $activity_content, $post_id, $post_text, &$topic ), 2036 'primary_link' => apply_filters( 'groups_activity_new_forum_post_primary_link', "{$primary_link}#post-{$post_id}" ), 2037 'type' => 'new_forum_post', 2038 'item_id' => $bp->groups->current_group->id, 2029 2039 'secondary_item_id' => $post_id 2030 2040 ) ); … … 2045 2055 2046 2056 $topic_title = apply_filters( 'group_forum_topic_title_before_save', $topic_title ); 2047 $topic_text = apply_filters( 'group_forum_topic_text_before_save', $topic_text );2048 $topic_tags = apply_filters( 'group_forum_topic_tags_before_save', $topic_tags );2049 $forum_id = apply_filters( 'group_forum_topic_forum_id_before_save', $forum_id );2057 $topic_text = apply_filters( 'group_forum_topic_text_before_save', $topic_text ); 2058 $topic_tags = apply_filters( 'group_forum_topic_tags_before_save', $topic_tags ); 2059 $forum_id = apply_filters( 'group_forum_topic_forum_id_before_save', $forum_id ); 2050 2060 2051 2061 if ( $topic_id = bp_forums_new_topic( array( 'topic_title' => $topic_title, 'topic_text' => $topic_text, 'topic_tags' => $topic_tags, 'forum_id' => $forum_id ) ) ) { … … 2055 2065 $activity_content = bp_create_excerpt( $topic_text ); 2056 2066 2057 / * Record this in activity streams */2067 // Record this in activity streams 2058 2068 groups_record_activity( array( 2059 'action' => apply_filters( 'groups_activity_new_forum_topic_action', $activity_action, $topic_text, &$topic ),2060 'content' => apply_filters( 'groups_activity_new_forum_topic_content', $activity_content, $topic_text, &$topic ),2061 'primary_link' => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/' ),2062 'type' => 'new_forum_topic',2063 'item_id' => $bp->groups->current_group->id,2069 'action' => apply_filters( 'groups_activity_new_forum_topic_action', $activity_action, $topic_text, &$topic ), 2070 'content' => apply_filters( 'groups_activity_new_forum_topic_content', $activity_content, $topic_text, &$topic ), 2071 'primary_link' => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/' ), 2072 'type' => 'new_forum_topic', 2073 'item_id' => $bp->groups->current_group->id, 2064 2074 'secondary_item_id' => $topic->topic_id 2065 2075 ) ); … … 2077 2087 2078 2088 $topic_title = apply_filters( 'group_forum_topic_title_before_save', $topic_title ); 2079 $topic_text = apply_filters( 'group_forum_topic_text_before_save', $topic_text);2089 $topic_text = apply_filters( 'group_forum_topic_text_before_save', $topic_text ); 2080 2090 2081 2091 if ( $topic = bp_forums_update_topic( array( 'topic_title' => $topic_title, 'topic_text' => $topic_text, 'topic_id' => $topic_id ) ) ) { 2082 / * Update the activity stream item */2092 // Update the activity stream item 2083 2093 if ( function_exists( 'bp_activity_delete_by_item_id' ) ) 2084 2094 bp_activity_delete_by_item_id( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $topic_id, 'component' => $bp->groups->id, 'type' => 'new_forum_topic' ) ); … … 2087 2097 $activity_content = bp_create_excerpt( $topic_text ); 2088 2098 2089 / * Record this in activity streams */2099 // Record this in activity streams 2090 2100 groups_record_activity( array( 2091 'action' => apply_filters( 'groups_activity_new_forum_topic_action', $activity_action, $topic_text, &$topic ),2092 'content' => apply_filters( 'groups_activity_new_forum_topic_content', $activity_content, $topic_text, &$topic ),2093 'primary_link' => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/' ),2094 'type' => 'new_forum_topic',2095 'item_id' => (int)$bp->groups->current_group->id,2096 'user_id' => (int)$topic->topic_poster,2101 'action' => apply_filters( 'groups_activity_new_forum_topic_action', $activity_action, $topic_text, &$topic ), 2102 'content' => apply_filters( 'groups_activity_new_forum_topic_content', $activity_content, $topic_text, &$topic ), 2103 'primary_link' => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/' ), 2104 'type' => 'new_forum_topic', 2105 'item_id' => (int)$bp->groups->current_group->id, 2106 'user_id' => (int)$topic->topic_poster, 2097 2107 'secondary_item_id' => $topic->topic_id, 2098 'recorded_time '=> $topic->topic_time2108 'recorded_time ' => $topic->topic_time 2099 2109 ) ); 2100 2110 … … 2111 2121 2112 2122 $post_text = apply_filters( 'group_forum_post_text_before_save', $post_text ); 2113 $topic_id = apply_filters( 'group_forum_post_topic_id_before_save', $topic_id ); 2114 2115 $post = bp_forums_get_post( $post_id ); 2123 $topic_id = apply_filters( 'group_forum_post_topic_id_before_save', $topic_id ); 2124 $post = bp_forums_get_post( $post_id ); 2116 2125 2117 2126 if ( $post_id = bp_forums_insert_post( array( 'post_id' => $post_id, 'post_text' => $post_text, 'post_time' => $post->post_time, 'topic_id' => $topic_id, 'poster_id' => $post->poster_id ) ) ) { … … 2125 2134 $primary_link .= "?topic_page=" . $page; 2126 2135 2127 / * Fetch an existing entry and update if one exists. */2136 // Fetch an existing entry and update if one exists. 2128 2137 if ( function_exists( 'bp_activity_get_activity_id' ) ) 2129 2138 $id = bp_activity_get_activity_id( array( 'user_id' => $post->poster_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post', 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $post_id ) ); 2130 2139 2131 / * Update the entry in activity streams */2140 // Update the entry in activity streams 2132 2141 groups_record_activity( array( 2133 'id' => $id,2134 'action' => apply_filters( 'groups_activity_new_forum_post_action', $activity_action, $post_text, &$topic, &$forum_post ),2135 'content' => apply_filters( 'groups_activity_new_forum_post_content', $activity_content, $post_text, &$topic, &$forum_post ),2136 'primary_link' => apply_filters( 'groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id ),2137 'type' => 'new_forum_post',2138 'item_id' => (int)$bp->groups->current_group->id,2139 'user_id' => (int)$post->poster_id,2142 'id' => $id, 2143 'action' => apply_filters( 'groups_activity_new_forum_post_action', $activity_action, $post_text, &$topic, &$forum_post ), 2144 'content' => apply_filters( 'groups_activity_new_forum_post_content', $activity_content, $post_text, &$topic, &$forum_post ), 2145 'primary_link' => apply_filters( 'groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id ), 2146 'type' => 'new_forum_post', 2147 'item_id' => (int)$bp->groups->current_group->id, 2148 'user_id' => (int)$post->poster_id, 2140 2149 'secondary_item_id' => $post_id, 2141 'recorded_time' => $post->post_time2150 'recorded_time' => $post->post_time 2142 2151 ) ); 2143 2152 … … 2156 2165 do_action( 'groups_before_delete_group_forum_topic', $topic_id ); 2157 2166 2158 / * Delete the activity stream item */2159 if ( function_exists( 'bp_activity_delete' ) ) {2167 // Delete the activity stream item 2168 if ( function_exists( 'bp_activity_delete' ) ) 2160 2169 bp_activity_delete( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $topic_id, 'component' => $bp->groups->id, 'type' => 'new_forum_topic' ) ); 2161 }2162 2170 2163 2171 do_action( 'groups_delete_group_forum_topic', $topic_id ); … … 2175 2183 do_action( 'groups_before_delete_group_forum_post', $post_id, $topic_id ); 2176 2184 2177 / * Delete the activity stream item */2178 if ( function_exists( 'bp_activity_delete' ) ) {2185 // Delete the activity stream item 2186 if ( function_exists( 'bp_activity_delete' ) ) 2179 2187 bp_activity_delete( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $post_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post' ) ); 2180 }2181 2188 2182 2189 do_action( 'groups_delete_group_forum_post', $post_id, $topic_id ); … … 2208 2215 2209 2216 $defaults = array( 2210 'user_id' => false,2211 'group_id' => false,2212 'inviter_id' => $bp->loggedin_user->id,2217 'user_id' => false, 2218 'group_id' => false, 2219 'inviter_id' => $bp->loggedin_user->id, 2213 2220 'date_modified' => bp_core_current_time(), 2214 'is_confirmed' => 02221 'is_confirmed' => 0 2215 2222 ); 2216 2223 … … 2222 2229 2223 2230 if ( !groups_is_user_member( $user_id, $group_id ) && !groups_check_user_has_invite( $user_id, $group_id ) ) { 2224 $invite = new BP_Groups_Member;2225 $invite->group_id = $group_id;2226 $invite->user_id = $user_id;2231 $invite = new BP_Groups_Member; 2232 $invite->group_id = $group_id; 2233 $invite->user_id = $user_id; 2227 2234 $invite->date_modified = $date_modified; 2228 $invite->inviter_id = $inviter_id;2229 $invite->is_confirmed = $is_confirmed;2235 $invite->inviter_id = $inviter_id; 2236 $invite->is_confirmed = $is_confirmed; 2230 2237 2231 2238 if ( !$invite->save() ) … … 2261 2268 return false; 2262 2269 2263 / * Remove request to join */2270 // Remove request to join 2264 2271 if ( $member->check_for_membership_request( $user_id, $group_id ) ) 2265 2272 $member->delete_request( $user_id, $group_id ); 2266 2273 2267 / * Modify group meta */2274 // Modify group meta 2268 2275 groups_update_groupmeta( $group_id, 'total_member_count', (int) groups_get_groupmeta( $group_id, 'total_member_count') + 1 ); 2269 2276 groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() ); … … 2403 2410 global $bp; 2404 2411 2405 / * Prevent duplicate requests */2412 // Prevent duplicate requests 2406 2413 if ( groups_check_for_membership_request( $requesting_user_id, $group_id ) ) 2407 2414 return false; 2408 2415 2409 / * Check if the user is already a member or is banned */2416 // Check if the user is already a member or is banned 2410 2417 if ( groups_is_user_member( $requesting_user_id, $group_id ) || groups_is_user_banned( $requesting_user_id, $group_id ) ) 2411 2418 return false; 2412 2419 2413 $requesting_user = new BP_Groups_Member;2414 $requesting_user->group_id = $group_id;2415 $requesting_user->user_id = $requesting_user_id;2416 $requesting_user->inviter_id = 0;2417 $requesting_user->is_admin = 0;2418 $requesting_user->user_title = '';2420 $requesting_user = new BP_Groups_Member; 2421 $requesting_user->group_id = $group_id; 2422 $requesting_user->user_id = $requesting_user_id; 2423 $requesting_user->inviter_id = 0; 2424 $requesting_user->is_admin = 0; 2425 $requesting_user->user_title = ''; 2419 2426 $requesting_user->date_modified = bp_core_current_time(); 2420 $requesting_user->is_confirmed = 0;2421 $requesting_user->comments = $_POST['group-request-membership-comments'];2427 $requesting_user->is_confirmed = 0; 2428 $requesting_user->comments = $_POST['group-request-membership-comments']; 2422 2429 2423 2430 if ( $requesting_user->save() ) { … … 2426 2433 require_once ( BP_PLUGIN_DIR . '/bp-groups/bp-groups-notifications.php' ); 2427 2434 2428 for ( $i = 0; $i < count( $admins ); $i++ ) {2429 // Saved okay, now send the email notification2435 // Saved okay, now send the email notification 2436 for ( $i = 0; $i < count( $admins ); $i++ ) 2430 2437 groups_notification_new_membership_request( $requesting_user_id, $admins[$i]->user_id, $group_id, $requesting_user->id ); 2431 }2432 2438 2433 2439 do_action( 'groups_membership_requested', $requesting_user_id, $admins, $group_id, $requesting_user->id ); … … 2452 2458 return false; 2453 2459 2454 / * Check if the user has an outstanding invite, if so delete it. */2460 // Check if the user has an outstanding invite, if so delete it. 2455 2461 if ( groups_check_user_has_invite( $membership->user_id, $membership->group_id ) ) 2456 2462 groups_delete_invite( $membership->user_id, $membership->group_id ); 2457 2463 2458 / * Modify group member count */2464 // Modify group member count 2459 2465 groups_update_groupmeta( $membership->group_id, 'total_member_count', (int) groups_get_groupmeta( $membership->group_id, 'total_member_count') + 1 ); 2460 2466 2461 / * Record this in activity streams */2467 // Record this in activity streams 2462 2468 $group = new BP_Groups_Group( $membership->group_id ); 2463 2469 2464 2470 groups_record_activity( array( 2465 'action' 2466 'type' 2467 'item_id' 2468 'user_id' 2471 'action' => apply_filters( 'groups_activity_membership_accepted_action', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $membership->user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), $membership->user_id, &$group ), 2472 'type' => 'joined_group', 2473 'item_id' => $membership->group_id, 2474 'user_id' => $membership->user_id 2469 2475 ) ); 2470 2476 2471 / * Send a notification to the user. */2477 // Send a notification to the user. 2472 2478 require_once ( BP_PLUGIN_DIR . '/bp-groups/bp-groups-notifications.php' ); 2473 2479 groups_notification_membership_request_completed( $membership->user_id, $membership->group_id, true ); … … 2513 2519 return false; 2514 2520 2515 foreach ( (array) $user_ids as $user_id ) {2521 foreach ( (array) $user_ids as $user_id ) 2516 2522 groups_accept_membership_request( false, $user_id, $group_id ); 2517 }2518 2523 2519 2524 do_action( 'groups_accept_all_pending_membership_requests', $group_id ); … … 2530 2535 return false; 2531 2536 2532 $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key);2533 2534 if ( is_array( $meta_value) || is_object($meta_value) )2537 $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key ); 2538 2539 if ( is_array( $meta_value ) || is_object( $meta_value ) ) 2535 2540 $meta_value = serialize($meta_value); 2536 2541 2537 2542 $meta_value = trim( $meta_value ); 2538 2543 2539 if ( !$meta_key ) {2544 if ( !$meta_key ) 2540 2545 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->groups->table_name_groupmeta . " WHERE group_id = %d", $group_id ) ); 2541 } else if ( $meta_value ) {2546 else if ( $meta_value ) 2542 2547 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->groups->table_name_groupmeta . " WHERE group_id = %d AND meta_key = %s AND meta_value = %s", $group_id, $meta_key, $meta_value ) ); 2543 } else {2548 else 2544 2549 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->groups->table_name_groupmeta . " WHERE group_id = %d AND meta_key = %s", $group_id, $meta_key ) ); 2545 } 2546 2547 /* Delete the cached object */ 2550 2551 // Delete the cached object 2548 2552 wp_cache_delete( 'bp_groups_groupmeta_' . $group_id . '_' . $meta_key, 'bp' ); 2549 2553 … … 2560 2564 2561 2565 if ( !empty($meta_key) ) { 2562 $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key);2566 $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key ); 2563 2567 2564 2568 if ( !$metas = wp_cache_get( 'bp_groups_groupmeta_' . $group_id . '_' . $meta_key, 'bp' ) ) { … … 2570 2574 } 2571 2575 2572 if ( empty( $metas) ) {2573 if ( empty( $meta_key) )2576 if ( empty( $metas ) ) { 2577 if ( empty( $meta_key ) ) 2574 2578 return array(); 2575 2579 else … … 2577 2581 } 2578 2582 2579 $metas = array_map( 'maybe_unserialize', (array)$metas);2580 2581 if ( 1 == count( $metas) )2583 $metas = array_map( 'maybe_unserialize', (array)$metas ); 2584 2585 if ( 1 == count( $metas ) ) 2582 2586 return $metas[0]; 2583 2587 else … … 2593 2597 $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key ); 2594 2598 2595 if ( is_string( $meta_value) )2596 $meta_value = stripslashes( $wpdb->escape($meta_value));2597 2598 $meta_value = maybe_serialize( $meta_value);2599 2600 if ( empty($meta_value)) {2599 if ( is_string( $meta_value ) ) 2600 $meta_value = stripslashes( $wpdb->escape( $meta_value ) ); 2601 2602 $meta_value = maybe_serialize( $meta_value ); 2603 2604 if ( empty( $meta_value ) ) 2601 2605 return groups_delete_groupmeta( $group_id, $meta_key ); 2602 }2603 2606 2604 2607 $cur = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $bp->groups->table_name_groupmeta . " WHERE group_id = %d AND meta_key = %s", $group_id, $meta_key ) ); 2605 2608 2606 if ( !$cur ) {2609 if ( !$cur ) 2607 2610 $wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp->groups->table_name_groupmeta . " ( group_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", $group_id, $meta_key, $meta_value ) ); 2608 } else if ( $cur->meta_value != $meta_value ) {2611 else if ( $cur->meta_value != $meta_value ) 2609 2612 $wpdb->query( $wpdb->prepare( "UPDATE " . $bp->groups->table_name_groupmeta . " SET meta_value = %s WHERE group_id = %d AND meta_key = %s", $meta_value, $group_id, $meta_key ) ); 2610 } else { 2611 return false; 2612 } 2613 2614 /* Update the cached object and recache */ 2613 else 2614 return false; 2615 2616 // Update the cached object and recache 2615 2617 wp_cache_set( 'bp_groups_groupmeta_' . $group_id . '_' . $meta_key, $meta_value, 'bp' ); 2616 2618 … … 2621 2623 2622 2624 function groups_remove_data_for_user( $user_id ) { 2623 BP_Groups_Member::delete_all_for_user( $user_id);2625 BP_Groups_Member::delete_all_for_user( $user_id ); 2624 2626 2625 2627 do_action( 'groups_remove_data_for_user', $user_id ); 2626 2628 } 2627 add_action( 'wpmu_delete_user', 'groups_remove_data_for_user' );2628 add_action( 'delete_user', 'groups_remove_data_for_user' );2629 add_action( 'wpmu_delete_user', 'groups_remove_data_for_user' ); 2630 add_action( 'delete_user', 'groups_remove_data_for_user' ); 2629 2631 add_action( 'bp_make_spam_user', 'groups_remove_data_for_user' ); 2630 2632 … … 2640 2642 wp_cache_delete( 'bp_total_group_count', 'bp' ); 2641 2643 } 2642 add_action( 'groups_group_deleted', 'groups_clear_group_object_cache' );2643 add_action( 'groups_settings_updated', 'groups_clear_group_object_cache' );2644 add_action( 'groups_details_updated', 'groups_clear_group_object_cache' );2645 add_action( 'groups_group_avatar_updated', 'groups_clear_group_object_cache' );2644 add_action( 'groups_group_deleted', 'groups_clear_group_object_cache' ); 2645 add_action( 'groups_settings_updated', 'groups_clear_group_object_cache' ); 2646 add_action( 'groups_details_updated', 'groups_clear_group_object_cache' ); 2647 add_action( 'groups_group_avatar_updated', 'groups_clear_group_object_cache' ); 2646 2648 add_action( 'groups_create_group_step_complete', 'groups_clear_group_object_cache' ); 2647 2649 … … 2649 2651 wp_cache_delete( 'bp_total_groups_for_user_' . $user_id ); 2650 2652 } 2651 add_action( 'groups_join_group', 'groups_clear_group_user_object_cache', 10, 2 );2652 add_action( 'groups_leave_group', 'groups_clear_group_user_object_cache', 10, 2 );2653 add_action( 'groups_ban_member', 'groups_clear_group_user_object_cache', 10, 2 );2653 add_action( 'groups_join_group', 'groups_clear_group_user_object_cache', 10, 2 ); 2654 add_action( 'groups_leave_group', 'groups_clear_group_user_object_cache', 10, 2 ); 2655 add_action( 'groups_ban_member', 'groups_clear_group_user_object_cache', 10, 2 ); 2654 2656 add_action( 'groups_unban_member', 'groups_clear_group_user_object_cache', 10, 2 ); 2655 2657 2656 2658 /* List actions to clear super cached pages on, if super cache is installed */ 2657 add_action( 'groups_join_group', 'bp_core_clear_cache' );2658 add_action( 'groups_leave_group', 'bp_core_clear_cache' );2659 add_action( 'groups_accept_invite', 'bp_core_clear_cache' );2660 add_action( 'groups_reject_invite', 'bp_core_clear_cache' );2661 add_action( 'groups_invite_user', 'bp_core_clear_cache' );2662 add_action( 'groups_uninvite_user', 'bp_core_clear_cache' );2663 add_action( 'groups_details_updated', 'bp_core_clear_cache' );2664 add_action( 'groups_settings_updated', 'bp_core_clear_cache' );2665 add_action( 'groups_unban_member', 'bp_core_clear_cache' );2666 add_action( 'groups_ban_member', 'bp_core_clear_cache' );2667 add_action( 'groups_demote_member', 'bp_core_clear_cache' );2668 add_action( 'groups_premote_member', 'bp_core_clear_cache' );2669 add_action( 'groups_membership_rejected', 'bp_core_clear_cache' );2670 add_action( 'groups_membership_accepted', 'bp_core_clear_cache' );2671 add_action( 'groups_membership_requested', 'bp_core_clear_cache' );2659 add_action( 'groups_join_group', 'bp_core_clear_cache' ); 2660 add_action( 'groups_leave_group', 'bp_core_clear_cache' ); 2661 add_action( 'groups_accept_invite', 'bp_core_clear_cache' ); 2662 add_action( 'groups_reject_invite', 'bp_core_clear_cache' ); 2663 add_action( 'groups_invite_user', 'bp_core_clear_cache' ); 2664 add_action( 'groups_uninvite_user', 'bp_core_clear_cache' ); 2665 add_action( 'groups_details_updated', 'bp_core_clear_cache' ); 2666 add_action( 'groups_settings_updated', 'bp_core_clear_cache' ); 2667 add_action( 'groups_unban_member', 'bp_core_clear_cache' ); 2668 add_action( 'groups_ban_member', 'bp_core_clear_cache' ); 2669 add_action( 'groups_demote_member', 'bp_core_clear_cache' ); 2670 add_action( 'groups_premote_member', 'bp_core_clear_cache' ); 2671 add_action( 'groups_membership_rejected', 'bp_core_clear_cache' ); 2672 add_action( 'groups_membership_accepted', 'bp_core_clear_cache' ); 2673 add_action( 'groups_membership_requested', 'bp_core_clear_cache' ); 2672 2674 add_action( 'groups_create_group_step_complete', 'bp_core_clear_cache' ); 2673 add_action( 'groups_created_group', 'bp_core_clear_cache' );2674 add_action( 'groups_group_avatar_updated', 'bp_core_clear_cache' );2675 add_action( 'groups_created_group', 'bp_core_clear_cache' ); 2676 add_action( 'groups_group_avatar_updated', 'bp_core_clear_cache' ); 2675 2677 2676 2678 ?>
Note: See TracChangeset
for help on using the changeset viewer.