Changeset 359
- Timestamp:
- 09/24/2008 05:31:27 AM (17 years ago)
- Location:
- trunk
- Files:
-
- 3 deleted
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-blogs.php
r348 r359 76 76 global $wpdb, $bp, $userdata; 77 77 78 if ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' )) {78 if ( $wpdb->blogid == $bp['current_homebase_id'] ) { 79 79 add_menu_page( __("Blogs"), __("Blogs"), 10, 'bp-blogs/admin-tabs/bp-blogs-tab.php' ); 80 80 add_submenu_page( 'bp-blogs/admin-tabs/bp-blogs-tab.php', __("My Blogs"), __("My Blogs"), 10, 'bp-blogs/admin-tabs/bp-blogs-tab.php' ); … … 104 104 'table_name_blog_posts' => $wpdb->base_prefix . 'bp_user_blogs_posts', 105 105 'table_name_blog_comments' => $wpdb->base_prefix . 'bp_user_blogs_comments', 106 'format_activity_function' => 'bp_blogs_format_activity', 106 107 'image_base' => get_option('siteurl') . '/wp-content/mu-plugins/bp-groups/images', 107 108 'slug' => 'blogs' … … 127 128 global $bp; 128 129 129 $nav_key = count($bp['bp_nav']) + 1; 130 $user_nav_key = count($bp['bp_users_nav']) + 1; 131 132 /* Add "Blogs" to the main component navigation */ 133 $bp['bp_nav'][$nav_key] = array( 134 'id' => 'blogs', 135 'name' => 'Blogs', 136 'link' => $bp['loggedin_domain'] . $bp['blogs']['slug'] 137 ); 138 139 /* Add "Blogs" to the sub nav for a current user */ 140 $bp['bp_users_nav'][$user_nav_key] = array( 141 'id' => 'blogs', 142 'name' => 'Blogs', 143 'link' => $bp['current_domain'] . 'blogs' 144 ); 145 146 /* Add blog options to the sub nav for the logged in user */ 147 $bp['bp_options_nav']['blogs'] = array( 148 'my-blogs' => array( 149 'name' => __('My Blogs'), 150 'link' => $bp['loggedin_domain'] . $bp['blogs']['slug'] . '/my-blogs/' ), 151 'recent-posts' => array( 152 'name' => __('Recent Posts'), 153 'link' => $bp['loggedin_domain'] . $bp['blogs']['slug'] . '/recent-posts/' ), 154 'recent-comments' => array( 155 'name' => __('Recent Comments'), 156 'link' => $bp['loggedin_domain'] . $bp['blogs']['slug'] . '/recent-comments/' ), 157 'create-a-blog' => array( 158 'name' => __('Create a Blog'), 159 'link' => $bp['loggedin_domain'] . $bp['blogs']['slug'] . '/create-a-blog/' ) 160 ); 130 /* Add 'Blogs' to the main navigation */ 131 bp_core_add_nav_item( __('Blogs'), $bp['blogs']['slug'] ); 132 bp_core_add_nav_default( $bp['blogs']['slug'], 'bp_blogs_screen_my_blogs', 'my-blogs' ); 133 134 $blogs_link = $bp['loggedin_domain'] . $bp['blogs']['slug'] . '/'; 135 136 /* Add the subnav items to the blogs nav item */ 137 bp_core_add_subnav_item( $bp['blogs']['slug'], 'my-blogs', __('My Blogs'), $blogs_link, 'bp_blogs_screen_my_blogs' ); 138 bp_core_add_subnav_item( $bp['blogs']['slug'], 'recent-posts', __('Recent Posts'), $blogs_link, 'bp_blogs_screen_recent_posts' ); 139 bp_core_add_subnav_item( $bp['blogs']['slug'], 'recent-comments', __('Recent Comments'), $blogs_link, 'bp_blogs_screen_recent_comments' ); 140 bp_core_add_subnav_item( $bp['blogs']['slug'], 'create-a-blog', __('Create a Blog'), $blogs_link, 'bp_blogs_screen_create_a_blog' ); 161 141 162 142 /* Set up the component options navigation for Blog */ … … 169 149 /* If we are not viewing the logged in user, set up the current users avatar and name */ 170 150 $bp['bp_options_avatar'] = bp_core_get_avatar( $bp['current_userid'], 1 ); 171 $bp['bp_options_title'] = bp_user_fullname( $bp['current_userid'], false );151 $bp['bp_options_title'] = $bp['current_fullname']; 172 152 } 173 153 } … … 175 155 add_action( 'wp', 'bp_blogs_setup_nav', 2 ); 176 156 157 /***** Screens **********/ 158 159 function bp_blogs_screen_my_blogs() { 160 bp_catch_uri( 'blogs/my-blogs' ); 161 } 162 163 function bp_blogs_screen_recent_posts() { 164 bp_catch_uri( 'blogs/recent-posts' ); 165 } 166 167 function bp_blogs_screen_recent_comments() { 168 bp_catch_uri( 'blogs/recent-comments' ); 169 } 170 171 function bp_blogs_screen_create_a_blog() { 172 bp_catch_uri( 'blogs/create' ); 173 } 174 177 175 178 176 /************************************************************************** 179 bp_blogs_ catch_action()177 bp_blogs_record_activity() 180 178 181 Catch actions via pretty urls. 179 Records activity for the logged in user within the friends component so that 180 it will show in the users activity stream (if installed) 182 181 **************************************************************************/ 183 182 184 function bp_blogs_catch_action() { 185 global $bp, $current_blog; 186 187 if ( $bp['current_component'] == $bp['blogs']['slug'] && $current_blog->blog_id > 1 ) { 188 switch ( $bp['current_action'] ) { 189 case 'my-blogs': 190 bp_catch_uri( 'blogs/my-blogs' ); 191 break; 183 function bp_blogs_record_activity( $args = true ) { 184 global $bp; 185 186 /* Because blog, comment, and blog post code execution happens before anything else 187 we need to manually instantiate the activity component globals */ 188 if ( !$bp['activity'] && function_exists('bp_activity_setup_globals') ) 189 bp_activity_setup_globals(); 190 191 if ( function_exists('bp_activity_record') ) { 192 extract($args); 193 bp_activity_record( $item_id, $component_name, $component_action, $is_private ); 194 } 195 } 196 add_action( 'bp_blogs_new_blog', 'bp_blogs_record_activity' ); 197 add_action( 'bp_blogs_new_blog_post', 'bp_blogs_record_activity' ); 198 add_action( 'bp_blogs_new_blog_comment', 'bp_blogs_record_activity' ); 199 200 /************************************************************************** 201 bp_blogs_format_activity() 202 203 Selects and formats recorded blogs component activity. 204 **************************************************************************/ 205 206 function bp_blogs_format_activity( $item_id, $action, $for_secondary_user = false ) { 207 global $bp; 208 209 switch( $action ) { 210 case 'new_blog': 211 $blog = new BP_Blogs_Blog($item_id); 212 213 if ( !$blog ) 214 return false; 215 216 return bp_core_get_userlink($bp['loggedin_userid']) . ' ' . __('created a new blog:') . ' <a href="' . get_blog_option( $blog->blog_id, 'siteurl' ) . '">' . get_blog_option( $blog->blog_id, 'blogname' ) . '</a> <span class="time-since">%s</span>'; 217 break; 218 case 'new_blog_post': 219 $post = new BP_Blogs_Post($item_id); 220 221 if ( !$post ) 222 return false; 223 224 $post = BP_Blogs_Post::fetch_post_content($post); 225 226 $content = bp_core_get_userlink($bp['loggedin_userid']) . ' ' . __('wrote a new blog post') . ' <a href="' . bp_post_get_permalink( $post, $post->blog_id ) . '">' . $post->post_title . '</a> <span class="time-since">%s</span>'; 227 $content .= '<blockquote>' . bp_create_excerpt($post->post_content) . '</blockquote>'; 228 return $content; 229 break; 230 case 'new_blog_comment': 192 231 193 case 'recent-posts': 194 bp_catch_uri( 'blogs/recent-posts' ); 195 break; 196 197 case 'recent-comments': 198 bp_catch_uri( 'blogs/recent-comments' ); 199 break; 200 201 case 'create-a-blog': 202 bp_catch_uri( 'blogs/create' ); 203 break; 204 205 default: 206 $bp['current_action'] = 'my-blogs'; 207 bp_catch_uri( 'blogs/my-blogs' ); 208 break; 209 } 210 } 211 } 212 add_action( 'wp', 'bp_blogs_catch_action', 3 ); 232 if ( !is_user_logged_in() ) 233 return false; 234 235 $comment = new BP_Blogs_Comment($item_id); 236 237 if ( !$comment ) 238 return false; 239 240 $comment = BP_Blogs_Comment::fetch_comment_content($comment); 241 $content = bp_core_get_userlink($bp['loggedin_userid']) . ' ' . __('commented on the blog post ') . ' <a href="' . bp_post_get_permalink( $comment->post, $comment->blog_id ) . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a> <span class="time-since">%s</span>'; 242 $content .= '<blockquote>' . bp_create_excerpt($comment->comment_content) . '</blockquote>'; 243 return $content; 244 break; 245 } 246 247 return false; 248 } 249 213 250 214 251 function bp_blogs_record_blog( $blog_id = '', $user_id = '' ) { … … 226 263 $recorded_blog->blog_id = $blog_id; 227 264 228 $recorded_blog->save(); 265 $recorded_blog_id = $recorded_blog->save(); 266 267 do_action( 'bp_blogs_new_blog', array( 'item_id' => $recorded_blog_id, 'component_name' => 'blogs', 'component_action' => 'new_blog', 'is_private' => 0 ) ); 229 268 } 230 269 } … … 255 294 $recorded_post->date_created = strtotime( $post->post_date ); 256 295 257 $recorded_post->save(); 296 $recorded_post_id = $recorded_post->save(); 297 298 do_action( 'bp_blogs_new_blog_post', array( 'item_id' => $recorded_post_id, 'component_name' => 'blogs', 'component_action' => 'new_blog_post', 'is_private' => 0 ) ); 258 299 } 259 300 } else { … … 305 346 $recorded_comment->date_created = strtotime( $comment->comment_date ); 306 347 307 $recorded_comment->save(); 348 $recorded_commment_id = $recorded_comment->save(); 349 350 do_action( 'bp_blogs_new_blog_comment', array( 'item_id' => $recorded_commment_id, 'component_name' => 'blogs', 'component_action' => 'new_blog_comment', 'is_private' => 0 ) ); 308 351 } 309 352 } else { … … 376 419 add_action( 'delete_comment', 'bp_blogs_remove_comment' ); 377 420 378 function bp_blogs_remove_ all_data_for_user( $blog_id ) {379 /* Only delete profile data if we are removing a home base */ 421 function bp_blogs_remove_data( $blog_id ) { 422 380 423 if ( $user_id = bp_core_get_homebase_userid( $blog_id ) ) { 424 /* If this is a home base, delete everything for that user. */ 381 425 BP_Blogs_Blog::delete_blogs_for_user( $user_id ); 382 426 BP_Blogs_Post::delete_posts_for_user( $user_id ); 383 427 BP_Blogs_Comment::delete_comments_for_user( $user_id ); 384 } 385 } 386 add_action( 'delete_blog', 'bp_blogs_remove_all_data_for_user', 1 ); 428 } else { 429 /* If this is regular blog, delete all data for that blog. */ 430 BP_Blogs_Blog::delete_blog_for_all( $blog_id ); 431 BP_Blogs_Post::delete_posts_for_blog( $blog_id ); 432 BP_Blogs_Comment::delete_comments_for_blog( $blog_id ); 433 } 434 435 } 436 add_action( 'delete_blog', 'bp_blogs_remove_data', 1 ); 387 437 388 438 function bp_blogs_register_existing_content( $blog_id ) { -
trunk/bp-blogs/bp-blogs-classes.php
r308 r359 6 6 var $blog_id; 7 7 8 function bp_blogs_blog( $ blog_id = null, $user_id = null ) {9 global $bp, $wpdb; 10 11 if ( !$user_id ) 12 $user_id = $bp['current_userid']; 13 14 if ( $ blog_id && $user_id ) {15 $this-> populate( $blog_id, $user_id );16 }17 }18 19 function populate( $blog_id, $user_id ) {20 global $wpdb, $bp;21 22 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $bp['blogs']['table_name'] . " WHERE blog_id = %d AND user_id = %d", $blog_id, $user_id ) );23 24 $this->id = $blog->id; 8 function bp_blogs_blog( $id = null ) { 9 global $bp, $wpdb; 10 11 if ( !$user_id ) 12 $user_id = $bp['current_userid']; 13 14 if ( $id ) { 15 $this->id = $id; 16 $this->populate(); 17 } 18 } 19 20 function populate() { 21 global $wpdb, $bp; 22 23 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $bp['blogs']['table_name'] . " WHERE id = %d", $this->id ) ); 24 25 25 $this->user_id = $blog->user_id; 26 26 $this->blog_id = $blog->blog_id; … … 41 41 } 42 42 43 return $wpdb->query($sql); 43 if ( !$wpdb->query($sql) ) 44 return false; 45 46 if ( $this->id ) 47 return $this->id; 48 else 49 return $wpdb->insert_id; 44 50 } 45 51 … … 99 105 var $date_created; 100 106 101 function bp_blogs_post( $ post_id = null, $blog_id = null, $user_id = null ) {102 global $bp, $wpdb; 103 104 if ( !$user_id ) 105 $user_id = $bp['current_userid']; 106 107 if ( $ post_id && $blog_id && $user_id ) {108 $this-> populate( $post_id, $blog_id, $user_id );109 }110 }111 112 function populate( $post_id, $blog_id, $user_id ) { 113 global $wpdb, $bp;114 115 $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $bp['blogs']['table_name_blog_posts'] . " WHERE post_id = %d AND blog_id = %d AND user_id = %d", $post_id, $blog_id, $user_id ) );116 117 $this->id = $post->id; 107 function bp_blogs_post( $id = null ) { 108 global $bp, $wpdb; 109 110 if ( !$user_id ) 111 $user_id = $bp['current_userid']; 112 113 if ( $id ) { 114 $this->id = $id; 115 $this->populate(); 116 } 117 } 118 119 function populate() { 120 global $wpdb, $bp; 121 122 $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $bp['blogs']['table_name_blog_posts'] . " WHERE id = %d", $this->id ) ); 123 118 124 $this->user_id = $post->user_id; 119 125 $this->blog_id = $post->blog_id; … … 133 139 } 134 140 135 return $wpdb->query($sql); 141 if ( !$wpdb->query($sql) ) 142 return false; 143 144 if ( $this->id ) 145 return $this->id; 146 else 147 return $wpdb->insert_id; 136 148 } 137 149 … … 163 175 164 176 return $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['blogs']['table_name_blog_posts'] . " WHERE user_id = %d", $user_id ) ); 177 } 178 179 function delete_posts_for_blog( $blog_id ) { 180 global $wpdb, $bp; 181 182 return $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['blogs']['table_name_blog_posts'] . " WHERE blog_id = %d", $blog_id ) ); 165 183 } 166 184 … … 175 193 176 194 for ( $i = 0; $i < count($post_ids); $i++ ) { 177 switch_to_blog($post_ids[$i]->blog_id); 178 $posts[$i] = get_post($post_ids[$i]->post_id); 179 $posts[$i]->blog_id = $post_ids[$i]->blog_id; 195 $posts[$i] = BP_Blogs_Post::fetch_post_content($post_ids[$i]); 180 196 } 181 197 182 198 return array( 'posts' => $posts, 'count' => $total_post_count ); 199 } 200 201 function fetch_post_content( $post_object ) { 202 switch_to_blog( $post_object->blog_id ); 203 $post = get_post($post_object->post_id); 204 $post->blog_id = $post_object->blog_id; 205 206 return $post; 183 207 } 184 208 … … 210 234 var $date_created; 211 235 212 function bp_blogs_comment( $ comment_id = null, $comment_post_id = null, $blog_id = null, $user_id = null ) {213 global $bp, $wpdb; 214 215 if ( !$user_id ) 216 $user_id = $bp['current_userid']; 217 218 if ( $ comment_id && $comment_post_id && $blog_id && $user_id) {219 $this-> populate( $comment_id, $comment_post_id, $blog_id, $user_id );220 }221 }222 223 function populate( $comment_id, $comment_post_id, $blog_id, $user_id ) { 224 global $wpdb, $bp;225 226 $comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $bp['blogs']['table_name_blog_comments'] . " WHERE comment_id = %d AND commment_post_id = %d AND blog_id = %d AND user_id = %d", $comment_id, $comment_post_id, $blog_id, $user_id ) );227 228 $this->id = $comment->id; 236 function bp_blogs_comment( $id = null ) { 237 global $bp, $wpdb; 238 239 if ( !$user_id ) 240 $user_id = $bp['current_userid']; 241 242 if ( $id ) { 243 $this->id = $id; 244 $this->populate( $id ); 245 } 246 } 247 248 function populate( $id ) { 249 global $wpdb, $bp; 250 251 $comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $bp['blogs']['table_name_blog_comments'] . " WHERE id = %d", $this->id ) ); 252 229 253 $this->comment_id = $comment->comment_id; 230 254 $this->user_id = $comment->user_id; … … 245 269 } 246 270 247 return $wpdb->query($sql); 271 if ( !$wpdb->query($sql) ) 272 return false; 273 274 if ( $this->id ) 275 return $this->id; 276 else 277 return $wpdb->insert_id; 248 278 } 249 279 … … 277 307 } 278 308 309 function delete_comments_for_blog( $blog_id ) { 310 global $wpdb, $bp; 311 312 return $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['blogs']['table_name_blog_comments'] . " WHERE blog_id = %d", $blog_id ) ); 313 } 314 279 315 function get_comments_for_user( $user_id = null ) { 280 316 global $bp, $wpdb; … … 287 323 288 324 for ( $i = 0; $i < count($comment_ids); $i++ ) { 289 switch_to_blog($comment_ids[$i]->blog_id); 290 $comments[$i] = get_comment($comment_ids[$i]->comment_id); 291 $comments[$i]->blog_id = $comment_ids[$i]->blog_id; 292 $comments[$i]->post = &get_post( $comments[$i]->comment_post_ID ); 325 $comments[$i] = BP_Blogs_Comment::fetch_comment_content($comment_ids[$i]); 293 326 } 294 327 295 328 return array( 'comments' => $comments, 'count' => $total_comment_count ); 329 } 330 331 function fetch_comment_content( $comment_object ) { 332 switch_to_blog($comment_object->blog_id); 333 $comment = get_comment($comment_object->comment_id); 334 $comment->blog_id = $comment_object->blog_id; 335 $comment->post = &get_post( $comment->comment_post_ID ); 336 337 return $comment; 296 338 } 297 339 -
trunk/bp-blogs/bp-blogs-cssjs.php
r308 r359 4 4 global $bp, $wpdb; 5 5 6 if ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' )) {6 if ( $wpdb->blogid == $bp['current_homebase_id'] ) { 7 7 if ( strpos( $_GET['page'], 'bp-blogs' ) !== false ) { 8 8 wp_enqueue_style('bp-blogs-admin-css', get_option('siteurl') . '/wp-content/mu-plugins/bp-blogs/admin-tabs/admin.css'); -
trunk/bp-blogs/bp-blogs-templatetags.php
r351 r359 312 312 function bp_post_category( $separator = '', $parents='', $post_id = false ) { 313 313 global $posts_template; 314 echo get_the_category_list($separator, $parents, $posts_template->post->ID );314 echo get_the_category_list($separator, $parents, $posts_template->post->ID ); 315 315 } 316 316 -
trunk/bp-core.php
r352 r359 40 40 global $action_variables; 41 41 42 $bp = array( 43 /* The user ID of the user who is currently logged in. */ 44 'loggedin_userid' => $current_user->ID, 45 46 /* The domain for the user currently logged in. eg: http://andy.domain.com/ */ 47 'loggedin_domain' => bp_core_get_loggedin_domain(), 48 49 /* The domain for the user currently being viewed */ 50 'current_domain' => bp_core_get_current_domain(), 51 52 /* The user id of the user currently being viewed */ 53 'current_userid' => bp_core_get_current_userid(), 54 55 /* The component being used eg: http://andy.domain.com/ [profile] */ 56 'current_component' => $current_component, // type: string 57 58 /* The current action for the component eg: http://andy.domain.com/profile/ [edit] */ 59 'current_action' => $current_action, // type: string 60 61 /* The action variables for the current action eg: http://andy.domain.com/profile/edit/ [group] / [6] */ 62 'action_variables' => $action_variables, // type: array 63 64 /* The default component to use if none are set and someone visits: http://andy.domain.com/ */ 65 'default_component' => 'profile', 66 67 /* Sets up the array container for the component navigation rendered by bp_get_nav() */ 68 'bp_nav' => array(), 69 70 /* Sets up the array container for the user navigation rendered by bp_get_user_nav() */ 71 'bp_users_nav' => array(), 72 73 /* Sets up the array container for the component options navigation rendered by bp_get_options_nav() */ 74 'bp_options_nav' => array(), 75 76 /* Sets up container used for the title of the current component option and rendered by bp_get_options_title() */ 77 'bp_options_title' => '', 78 79 /* Sets up container used for the avatar of the current component being viewed. Rendered by bp_get_options_avatar() */ 80 'bp_options_avatar' => '', 81 82 /* Sets up container for callback messages rendered by bp_core_render_notice() */ 83 'message' => '', 84 85 /* Sets up container for callback message type rendered by bp_core_render_notice() */ 86 'message_type' => '', // error/success, 87 88 /* Used to determine if user has admin rights on current content. If the logged in user is viewing 89 their own profile and wants to delete a post on their wire, is_item_admin is used. This is a 90 generic variable so it can be used in other components. It can also be modified, so when viewing a group 91 'is_item_admin' would be 1 if they are a group admin, 0 if they are not. */ 92 'is_item_admin' => bp_is_home() 93 ); 94 42 /* The user ID of the user who is currently logged in. */ 43 $bp['loggedin_userid'] = $current_user->ID; 44 45 /* The domain for the user currently logged in. eg: http://andy.domain.com/ */ 46 $bp['loggedin_domain'] = bp_core_get_loggedin_domain(); 47 48 /* The domain for the user currently being viewed */ 49 $bp['current_domain'] = bp_core_get_current_domain(); 50 51 /* The user id of the user currently being viewed */ 52 $bp['current_userid'] = bp_core_get_current_userid(); 53 54 /* The component being used eg: http://andy.domain.com/ [profile] */ 55 $bp['current_component'] = $current_component; // type: string 56 57 /* The current action for the component eg: http://andy.domain.com/profile/ [edit] */ 58 $bp['current_action'] = $current_action; // type: string 59 60 /* The action variables for the current action eg: http://andy.domain.com/profile/edit/ [group] / [6] */ 61 $bp['action_variables'] = $action_variables; // type: array 62 63 /* Only used where a component has a sub item, e.g. groups: http://andy.domain.com/groups/ [my-group] / home - manipulated in the actual component not in catch uri code.*/ 64 $bp['current_item'] = ''; // type: string 65 66 /* The default component to use if none are set and someone visits: http://andy.domain.com/ */ 67 $bp['default_component'] = 'profile'; 68 69 /* Sets up the array container for the component navigation rendered by bp_get_nav() */ 70 $bp['bp_nav'] = array(); 71 72 /* Sets up the array container for the user navigation rendered by bp_get_user_nav() */ 73 $bp['bp_users_nav'] = array(); 74 75 /* Sets up the array container for the component options navigation rendered by bp_get_options_nav() */ 76 $bp['bp_options_nav'] = array(); 77 78 /* Sets up container used for the title of the current component option and rendered by bp_get_options_title() */ 79 $bp['bp_options_title'] = ''; 80 81 /* Sets up container used for the avatar of the current component being viewed. Rendered by bp_get_options_avatar() */ 82 $bp['bp_options_avatar'] = ''; 83 84 /* Sets up container for callback messages rendered by bp_core_render_notice() */ 85 $bp['message'] = ''; 86 87 /* Sets up container for callback message type rendered by bp_core_render_notice() */ 88 $bp['message_type'] = ''; // error/success 89 90 /* Fetch the home base blog id for the logged in and current user */ 91 $bp['loggedin_homebase_id'] = get_usermeta( $bp['loggedin_userid'], 'home_base' ); 92 $bp['current_homebase_id'] = get_usermeta( $bp['current_userid'], 'home_base' ); 93 94 /* Fetch the full name for the logged in and current user */ 95 $bp['loggedin_fullname'] = bp_core_global_user_fullname( $bp['loggedin_userid'] ); 96 $bp['current_fullname'] = bp_core_global_user_fullname( $bp['current_userid'] ); 97 98 /* Used to determine if user has admin rights on current content. If the logged in user is viewing 99 their own profile and wants to delete a post on their wire, is_item_admin is used. This is a 100 generic variable so it can be used in other components. It can also be modified, so when viewing a group 101 'is_item_admin' would be 1 if they are a group admin, 0 if they are not. */ 102 $bp['is_item_admin'] = bp_is_home(); 103 95 104 if ( !$bp['current_component'] ) 96 105 $bp['current_component'] = $bp['default_component']; 106 97 107 } 98 108 add_action( 'wp', 'bp_core_setup_globals', 1 ); … … 112 122 global $bp, $wpdb; 113 123 114 if ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' )) {124 if ( $wpdb->blogid == $bp['current_homebase_id'] ) { 115 125 $component_check = $bp['current_component']; 116 126 … … 265 275 global $bp; 266 276 267 if ( get_usermeta( $bp['loggedin_userid'], 'home_base' )== '' )277 if ( $bp['loggedin_homebase_id'] == '' ) 268 278 return false; 269 279 … … 426 436 } 427 437 438 /** 439 * bp_core_replace_home_base_dashboard() 440 * 441 * Sets up the hook to start replacement of the dashboard on the users home base. 442 * 443 * @package BuddyPress Core 444 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 445 * @global $wpdb WordPress DB access object. 446 * @uses add_action() Hooks a function on to a specific action. 447 */ 428 448 function bp_core_replace_home_base_dashboard() { 429 449 global $wpdb, $bp; 430 431 if ( strpos( $_SERVER['SCRIPT_NAME'], '/index.php' ) && $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' )) {450 451 if ( strpos( $_SERVER['SCRIPT_NAME'], '/index.php' ) && $wpdb->blogid == $bp['current_homebase_id'] ) { 432 452 add_action( 'admin_head', 'bp_core_start_dash_replacement' ); 433 453 } … … 435 455 add_action( 'admin_menu', 'bp_core_replace_home_base_dashboard' ); 436 456 457 /** 458 * bp_core_start_dash_replacement() 459 * 460 * Starts the output buffer. 461 * 462 * @package BuddyPress Core 463 * @uses add_action() Hooks a function on to a specific action. 464 */ 437 465 function bp_core_start_dash_replacement( $dash_contents ) { 438 466 ob_start(); … … 440 468 } 441 469 470 /** 471 * bp_core_insert_new_dashboard() 472 * 473 * Inserts the new dashboard content. 474 * 475 * @package BuddyPress Core 476 * @uses add_action() Hooks a function on to a specific action. 477 */ 442 478 function bp_core_insert_new_dashboard( $dash_contents ) { 443 479 global $bp; 444 480 445 481 $filter = preg_split( '/\<div class=\"wrap\"\>[\S\s]*\<div id=\"footer\"\>/', $dash_contents ); 482 446 483 $filter[0] .= '<div class="wrap">'; 447 484 $filter[1] .= '</div>'; 448 485 449 486 echo $filter[0]; 450 487 //echo ABSPATH . 'wp-content/mu-plugins/bp-core/admin-mods/bp-core-homebase-dashboard.php'; 451 488 require_once( ABSPATH . '/wp-content/mu-plugins/bp-core/admin-mods/bp-core-homebase-dashboard.php' ); 452 489 … … 455 492 } 456 493 494 /** 495 * bp_core_end_dash_replacement() 496 * 497 * Gets output buffer contents and stops the output buffer. 498 * 499 * @package BuddyPress Core 500 * @uses bp_core_insert_new_dashboard() Inserts the new dashboard content. 501 */ 457 502 function bp_core_end_dash_replacement() { 458 503 $dash_contents = ob_get_contents(); 459 504 ob_end_clean(); 460 505 bp_core_insert_new_dashboard($dash_contents); 506 } 507 508 /** 509 * bp_core_add_nav_item() 510 * 511 * Adds a navigation item to the main navigation array used in BuddyPress themes. 512 * 513 * @package BuddyPress Core 514 * @param $id A unique id for the navigation item. 515 * @param $name The display name for the navigation item, e.g. 'Profile' or 'Messages' 516 * @param $slug The slug for the navigation item, e.g. 'profile' or 'messages' 517 * @param $function The function to run when this sub nav item is selected. 518 * @param $css_id The id to give the nav item in the HTML (for css highlighting) 519 * @param $add_to_usernav Should this navigation item show up on the users home when not logged in? Or when another user views the user's page? 520 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 521 */ 522 function bp_core_add_nav_item( $name, $slug, $css_id = false, $add_to_usernav = true ) { 523 global $bp; 524 525 $nav_key = count($bp['bp_nav']) + 1; 526 $user_nav_key = count($bp['bp_users_nav']) + 1; 527 528 if ( !$css_id ) 529 $css_id = $slug; 530 531 $bp['bp_nav'][$nav_key] = array( 532 'name' => $name, 533 'link' => $bp['loggedin_domain'] . $slug, 534 'css_id' => $css_id 535 ); 536 537 if ( $add_to_usernav ) { 538 $bp['bp_users_nav'][$user_nav_key] = array( 539 'name' => $name, 540 'link' => $bp['current_domain'] . $slug, 541 'css_id' => $css_id 542 ); 543 } 544 } 545 546 /** 547 * bp_core_add_subnav_item() 548 * 549 * Adds a navigation item to the sub navigation array used in BuddyPress themes. 550 * 551 * @package BuddyPress Core 552 * @param $parent_id The id of the parent navigation item. 553 * @param $id A unique id for the sub navigation item. 554 * @param $name The display name for the sub navigation item, e.g. 'Public' or 'Change Avatar' 555 * @param $link The url for the sub navigation item. 556 * @param $function The function to run when this sub nav item is selected. 557 * @param $css_id The id to give the nav item in the HTML (for css highlighting) 558 * @param $loggedin_user_only Should only the logged in user be able to access this page? 559 * @param $admin_only Should this sub nav item only be visible/accessible to the site admin? 560 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 561 */ 562 function bp_core_add_subnav_item( $parent_id, $slug, $name, $link, $function, $css_id = false, $loggedin_user_only = true, $admin_only = false ) { 563 global $bp; 564 565 if ( $admin_only && !is_site_admin() ) 566 return false; 567 568 if ( !$css_id ) 569 $css_id = $slug; 570 571 $bp['bp_options_nav'][$parent_id][$slug] = array( 572 'name' => $name, 573 'link' => $link . $slug, 574 'css_id' => $css_id 575 ); 576 577 if ( $loggedin_user_only && !bp_is_home() ) 578 return false; 579 580 if ( function_exists($function) && $bp['current_action'] == $slug && $bp['current_component'] == $parent_id ) 581 add_action( 'wp', $function, 3 ); 582 } 583 584 585 /** 586 * bp_core_reset_subnav_items() 587 * 588 * Clear the subnav items for a specific nav item. 589 * 590 * @package BuddyPress Core 591 * @param $parent_id The id of the parent navigation item. 592 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 593 */ 594 function bp_core_reset_subnav_items($parent_id) { 595 global $bp; 596 597 unset($bp['bp_options_nav'][$parent_id]); 598 } 599 600 /** 601 * bp_core_add_nav_default() 602 * 603 * Set a default action for a nav item, when a sub nav item has not yet been selected. 604 * 605 * @package BuddyPress Core 606 * @param $parent_id The id of the parent navigation item. 607 * @param $function The function to run when this sub nav item is selected. 608 * @param $slug The slug of the sub nav item to highlight. 609 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 610 */ 611 function bp_core_add_nav_default( $parent_id, $function, $slug = false ) { 612 global $bp; 613 614 if ( $bp['current_component'] == $parent_id && !$bp['current_action'] ) { 615 if ( function_exists($function) ) { 616 add_action( 'wp', $function, 3 ); 617 } 618 619 if ( $slug ) 620 $bp['current_action'] = $slug; 621 } 461 622 } 462 623 … … 559 720 * @return str The link text based on passed parameters. 560 721 */ 561 function bp_core_get_userlink( $u id, $no_anchor = false, $just_link = false, $no_you= false ) {722 function bp_core_get_userlink( $user_id, $no_anchor = false, $just_link = false, $no_you = false, $with_s = false ) { 562 723 global $userdata; 563 724 564 $ud = get_userdata($u id);725 $ud = get_userdata($user_id); 565 726 566 727 if ( !$ud ) 567 728 return false; 568 729 569 if ( function_exists('bp_user_fullname') ) 570 $display_name = bp_user_fullname( $uid, false ); 571 else 730 if ( function_exists('bp_fetch_user_fullname') ) { 731 $display_name = bp_fetch_user_fullname( $user_id, false ); 732 733 if ( $with_s ) 734 $display_name .= "'s"; 735 736 } else { 572 737 $display_name = $ud->display_name; 573 574 if ( $uid == $userdata->ID && !$no_you ) 738 } 739 740 if ( $user_id == $userdata->ID && !$no_you ) 575 741 $display_name = 'You'; 576 742 577 743 if ( $no_anchor ) 578 744 return $display_name; 579 745 580 $home_base_id = get_usermeta( $u id, 'home_base' );746 $home_base_id = get_usermeta( $user_id, 'home_base' ); 581 747 582 748 if ( !$home_base_id ) … … 584 750 585 751 $home_base_url = get_blog_option( $home_base_id, 'siteurl' ) . '/'; 586 752 587 753 if ( $just_link ) 588 754 return $home_base_url; 589 755 590 756 return '<a href="' . $home_base_url . '">' . $display_name . '</a>'; 757 } 758 759 function bp_core_global_user_fullname( $user_id ) { 760 if ( function_exists('bp_user_fullname') ) { 761 return bp_fetch_user_fullname( $user_id, false ); 762 } else { 763 $ud = get_userdata($user_id); 764 return $current_user->display_name; 765 } 591 766 } 592 767 … … 910 1085 global $bp; 911 1086 912 foreach ( (array)$nav_array as $nav_item ) { 913 switch ( $nav_item['id'] ) { 1087 foreach ( (array)$nav_array as $key => $value ) { 1088 switch ( $nav_array[$key]['css_id'] ) { 1089 case $bp['activity']['slug']: 1090 $new_nav[0] = $nav_array[$key]; 1091 unset($nav_array[$key]); 1092 break; 914 1093 case $bp['profile']['slug']: 915 $new_nav[0] = $nav_item; 1094 $new_nav[1] = $nav_array[$key]; 1095 unset($nav_array[$key]); 916 1096 break; 917 1097 case $bp['blogs']['slug']: 918 $new_nav[1] = $nav_item; 1098 $new_nav[2] = $nav_array[$key]; 1099 unset($nav_array[$key]); 919 1100 break; 920 1101 case $bp['wire']['slug']: 921 $new_nav[2] = $nav_item; 1102 $new_nav[3] = $nav_array[$key]; 1103 unset($nav_array[$key]); 922 1104 break; 923 1105 case $bp['messages']['slug']: 924 $new_nav[3] = $nav_item; 1106 $new_nav[4] = $nav_array[$key]; 1107 unset($nav_array[$key]); 925 1108 break; 926 1109 case $bp['friends']['slug']: 927 $new_nav[4] = $nav_item; 1110 $new_nav[5] = $nav_array[$key]; 1111 unset($nav_array[$key]); 928 1112 break; 929 1113 case $bp['groups']['slug']: 930 $new_nav[5] = $nav_item; 1114 $new_nav[6] = $nav_array[$key]; 1115 unset($nav_array[$key]); 931 1116 break; 932 1117 case $bp['gallery']['slug']: 933 $new_nav[6] = $nav_item; 1118 $new_nav[7] = $nav_array[$key]; 1119 unset($nav_array[$key]); 934 1120 break; 935 1121 case $bp['account']['slug']: 936 $new_nav[7] = $nav_item; 1122 $new_nav[8] = $nav_array[$key]; 1123 unset($nav_array[$key]); 937 1124 break; 938 1125 } … … 940 1127 941 1128 ksort($new_nav); 1129 1130 array_merge( $new_nav, $nav_array ); 942 1131 return $new_nav; 943 1132 } -
trunk/bp-core/admin-mods/bp-core-admin-styles.php
r309 r359 3 3 global $bp, $wpdb; 4 4 5 if ( function_exists('xprofile_install') && $wpdb->blogid == get_usermeta( $bp['loggedin_userid'], 'home_base' )) {5 if ( function_exists('xprofile_install') && $wpdb->blogid == $bp['loggedin_homebase_id'] ) { 6 6 $avatar_href = bp_core_get_avatar( $bp['loggedin_userid'], 1, true ); 7 7 -
trunk/bp-core/admin-mods/bp-core-homebase-dashboard.php
r309 r359 1 <?php 2 3 $name = bp_user_fullname( $bp['current_userid'], false ); 4 5 6 ?> 7 8 <h2><?php echo $name ?>'s Dashboard</h2> 1 <h2><?php echo $bp['current_fullname'] ?>'s Dashboard</h2> 9 2 10 3 <div id="rightnow"> -
trunk/bp-core/admin-mods/bp-core-remove-blogtabs.php
r309 r359 6 6 7 7 /* Unset all blog tabs if this is the home base for the user */ 8 if ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' )) {8 if ( $wpdb->blogid == $bp['current_homebase_id'] ) { 9 9 unset($menu[5]); 10 10 unset($menu[10]); … … 33 33 34 34 /* Reorder the 'Account' tab so it appears as a small right tab */ 35 if ( $wpdb->blogid != get_usermeta( $bp['current_userid'], 'home_base' )) {35 if ( $wpdb->blogid != $bp['current_homebase_id'] ) { 36 36 $menu[27] = $menu[41]; 37 37 unset($menu[41]); -
trunk/bp-core/bp-core-avatars.php
r339 r359 467 467 #avatar_v2 { display: none; } 468 468 .crop-img { float: left; margin: 0 20px 15px 0; } 469 .submit { clear: left; }470 469 </style> 471 470 -
trunk/bp-core/bp-core-catchuri.php
r309 r359 75 75 /* Reset the keys by merging with an empty array */ 76 76 $action_variables = array_merge( array(), $action_variables ); 77 78 77 } 79 add_action( 'wp', 'bp_core_set_uri_globals', 0);78 add_action( 'wp', 'bp_core_set_uri_globals', 1 ); 80 79 81 80 /** … … 111 110 $pages = $bp_path; 112 111 113 if ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' )) {112 if ( $wpdb->blogid == $bp['current_homebase_id'] ) { 114 113 if ( !file_exists( TEMPLATEPATH . "/header.php" ) || !file_exists( TEMPLATEPATH . "/footer.php" ) ) 115 114 wp_die( 'Please make sure your BuddyPress enabled theme includes a header.php and footer.php file.'); -
trunk/bp-core/bp-core-templatetags.php
r353 r359 28 28 29 29 /* Loop through each navigation item */ 30 foreach( $bp['bp_nav'] as $nav_item ) {30 foreach( (array) $bp['bp_nav'] as $nav_item ) { 31 31 /* If the current component matches the nav item id, then add a highlight CSS class. */ 32 if ( $bp['current_component'] == $nav_item[' id'] && $bp['current_userid'] == $bp['loggedin_userid'] ) {32 if ( $bp['current_component'] == $nav_item['css_id'] && $bp['current_userid'] == $bp['loggedin_userid'] ) { 33 33 $selected = ' class="current"'; 34 34 } else { … … 41 41 if ( $bp['current_userid'] != $bp['loggedin_userid'] ) { 42 42 if ( function_exists('friends_check_friendship') ) { 43 if ( friends_check_friendship( $bp['current_userid'] ) == 'is_friend' && $nav_item[' id'] == $bp['friends']['slug'] ) {43 if ( friends_check_friendship( $bp['current_userid'] ) == 'is_friend' && $nav_item['css_id'] == $bp['friends']['slug'] ) { 44 44 $selected = ' class="current"'; 45 45 } else { … … 50 50 51 51 /* echo out the final list item */ 52 echo '<li' . $selected . '><a id="' . $nav_item[' id'] . '" href="' . $nav_item['link'] . '">' . $nav_item['name'] . '</a></li>';52 echo '<li' . $selected . '><a id="' . $nav_item['css_id'] . '" href="' . $nav_item['link'] . '">' . $nav_item['name'] . '</a></li>'; 53 53 } 54 54 … … 75 75 */ 76 76 function bp_get_options_nav() { 77 global $bp ;77 global $bp, $is_single_group; 78 78 79 79 /* Only render this navigation when the logged in user is looking at one of their own pages. */ 80 if ( $bp['loggedin_userid'] == $bp['current_userid']) {80 if ( bp_is_home() || $is_single_group ) { 81 81 if ( count( $bp['bp_options_nav'][$bp['current_component']] ) < 1 ) 82 82 return false; … … 86 86 $title = $values['name']; 87 87 $link = $values['link']; 88 $ id = $values['id'];88 $css_id = $values['css_id']; 89 89 90 90 /* If the current action or an action variable matches the nav item id, then add a highlight CSS class. */ 91 if ( $slug == $bp['current_action'] || $slug == $bp['action_variables'][0]) {91 if ( $slug == $bp['current_action'] || in_array( $slug, $bp['action_variables'] ) ) { 92 92 $selected = ' class="current"'; 93 93 } else { … … 96 96 97 97 /* echo out the final list item */ 98 echo '<li' . $selected . '><a id="' . $ id . '" href="' . $link . '">' . $title . '</a></li>';98 echo '<li' . $selected . '><a id="' . $css_id . '" href="' . $link . '">' . $title . '</a></li>'; 99 99 } 100 100 } else { 101 if ( count( $bp['bp_users_nav'] ) < 1)101 if ( !$bp['bp_users_nav'] ) 102 102 return false; 103 103 … … 123 123 124 124 foreach ( $bp['bp_users_nav'] as $user_nav_item ) { 125 if ( $bp['current_component'] == $user_nav_item[' id'] ) {125 if ( $bp['current_component'] == $user_nav_item['css_id'] ) { 126 126 $selected = ' class="current"'; 127 127 } else { … … 129 129 } 130 130 131 echo '<li' . $selected . '><a id="' . $user_nav_item[' id'] . '" href="' . $user_nav_item['link'] . '">' . $user_nav_item['name'] . '</a></li>';131 echo '<li' . $selected . '><a id="' . $user_nav_item['css_id'] . '" href="' . $user_nav_item['link'] . '">' . $user_nav_item['name'] . '</a></li>'; 132 132 } 133 133 } … … 180 180 global $bp; 181 181 182 if ( !is_user_logged_in() )182 if ( !is_user_logged_in() || is_null($bp['loggedin_userid']) || is_null($bp['current_userid']) ) 183 183 return false; 184 184 185 185 if ( $bp['loggedin_userid'] == $bp['current_userid'] ) 186 186 return true; 187 187 188 188 return false; 189 189 } … … 231 231 } else { 232 232 if ( $echo ) 233 echo $bp[' bp_options_title'] . "'s";234 else 235 return $bp[' bp_options_title'] . "'s";233 echo $bp['current_fullname'] . "'s"; 234 else 235 return $bp['current_fullname'] . "'s"; 236 236 } 237 237 } … … 252 252 } else { 253 253 if ( $echo ) 254 echo $bp[' bp_options_title'] . " hasn't";255 else 256 return $bp[' bp_options_title'] . " hasn't";254 echo $bp['current_fullname'] . " hasn't"; 255 else 256 return $bp['current_fullname'] . " hasn't"; 257 257 } 258 258 } … … 273 273 } else { 274 274 if ( $echo ) 275 echo $bp['bp_options_title'] . "'s"; 276 else 277 return $bp['bp_options_title'] . "'s"; 278 } 275 echo $bp['current_fullname'] . "'s"; 276 else 277 return $bp['current_fullname'] . "'s"; 278 } 279 } 280 281 function bp_your_or_their( $capitalize = false, $echo = false ) { 282 global $bp; 283 284 $your = __('your'); 285 $their = __('their'); 286 287 if ( $capitalize ) 288 $your = ucfirst($your); 289 290 if ( $bp['current_userid'] == $bp['loggedin_userid'] ) { 291 if ( $echo ) 292 echo $your; 293 else 294 return $your; 295 } else { 296 if ( $echo ) 297 echo $their; 298 else 299 return $their; 300 } 301 } 302 303 /* Template functions for fetching globals, without querying the DB again 304 also means we dont have to use the $bp variable in the template (looks messy) */ 305 306 function bp_current_user_id() { 307 global $bp; 308 return $bp['current_userid']; 309 } 310 311 function bp_user_fullname() { 312 global $bp; 313 echo $bp['current_fullname']; 279 314 } 280 315 -
trunk/bp-core/homebase-creation/bp-core-homebase-functions.php
r309 r359 25 25 global $wpdb, $bp; 26 26 27 if ( ( is_site_admin() && $bp['current_userid'] != $bp['loggedin_userid'] ) && ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' )) ) { ?>27 if ( ( is_site_admin() && $bp['current_userid'] != $bp['loggedin_userid'] ) && ( $wpdb->blogid == $bp['current_homebase_id'] ) ) { ?> 28 28 <div id="update-nag"> 29 29 <p><strong><?php _e('Administrator Notice:') ?></strong> <?php _e('This is a user home base, not a blog.') ?></p> -
trunk/bp-core/homebase-creation/bp-core-homebase-tab.php
r309 r359 1 1 <?php 2 2 3 if ( get_usermeta( $bp['loggedin_userid'], 'home_base' )&& !wp_verify_nonce($_POST['nonce'], 'slick_avatars') )3 if ( $bp['loggedin_homebase_id'] && !wp_verify_nonce($_POST['nonce'], 'slick_avatars') ) 4 4 wp_die('Home Base already created.'); 5 5 -
trunk/bp-friends.php
r347 r359 54 54 'table_name' => $wpdb->base_prefix . 'bp_friends', 55 55 'image_base' => get_option('siteurl') . '/wp-content/mu-plugins/bp-friends/images', 56 'format_activity_function' => 'friends_format_activity', 56 57 'slug' => 'friends' 57 58 ); … … 71 72 global $wpdb, $bp, $userdata; 72 73 73 if ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' )) {74 if ( $wpdb->blogid == $bp['current_homebase_id'] ) { 74 75 /* Add the administration tab under the "Site Admin" tab for site administrators */ 75 76 //add_submenu_page( 'wpmu-admin.php', __("Friends"), __("Friends"), 1, basename(__FILE__), "friends_settings" ); … … 91 92 global $bp; 92 93 93 $nav_key = count($bp['bp_nav']) + 1; 94 $user_nav_key = count($bp['bp_users_nav']) + 1; 95 96 $bp['bp_nav'][$nav_key] = array( 97 'id' => $bp['friends']['slug'], 98 'name' => __('Friends'), 99 'link' => $bp['loggedin_domain'] . $bp['friends']['slug'] . '/' 100 ); 101 102 $bp['bp_users_nav'][$user_nav_key] = array( 103 'id' => $bp['friends']['slug'], 104 'name' => __('Friends'), 105 'link' => $bp['current_domain'] . $bp['friends']['slug'] . '/' 106 ); 107 108 $bp['bp_options_nav'][$bp['friends']['slug']] = array( 109 'my-friends' => array( 110 'name' => __('My Friends'), 111 'link' => $bp['loggedin_domain'] . $bp['friends']['slug'] . '/my-friends' ), 112 'requests' => array( 113 'name' => __('Requests'), 114 'link' => $bp['loggedin_domain'] . $bp['friends']['slug'] . '/requests' ), 115 'friend-finder' => array( 116 'name' => __('Friend Finder'), 117 'link' => $bp['loggedin_domain'] . $bp['friends']['slug'] . '/friend-finder' ), 118 'invite-friend' => array( 119 'name' => __('Invite Friends'), 120 'link' => $bp['loggedin_domain'] . $bp['friends']['slug'] . '/invite-friend' ) 121 ); 94 /* Add 'Friends' to the main navigation */ 95 bp_core_add_nav_item( __('Friends'), $bp['friends']['slug'] ); 96 bp_core_add_nav_default( $bp['friends']['slug'], 'friends_screen_my_friends', 'my-friends' ); 97 98 $friends_link = $bp['loggedin_domain'] . $bp['friends']['slug'] . '/'; 99 100 /* Add the subnav items to the friends nav item */ 101 bp_core_add_subnav_item( $bp['friends']['slug'], 'my-friends', __('My Friends'), $friends_link, 'friends_screen_my_friends' ); 102 bp_core_add_subnav_item( $bp['friends']['slug'], 'requests', __('Requests'), $friends_link, 'friends_screen_requests' ); 103 bp_core_add_subnav_item( $bp['friends']['slug'], 'friend-finder', __('Friend Finder'), $friends_link, 'friends_screen_friend_finder' ); 104 bp_core_add_subnav_item( $bp['friends']['slug'], 'invite-friend', __('Invite Friends'), $friends_link, 'friends_screen_invite_friends' ); 122 105 123 106 if ( $bp['current_component'] == $bp['friends']['slug'] ) { … … 126 109 } else { 127 110 $bp['bp_options_avatar'] = bp_core_get_avatar( $bp['current_userid'], 1 ); 128 $bp['bp_options_title'] = bp_user_fullname( $bp['current_userid'], false );111 $bp['bp_options_title'] = $bp['current_fullname']; 129 112 } 130 113 } 131 132 114 } 133 115 add_action( 'wp', 'friends_setup_nav', 2 ); 134 116 135 136 /************************************************************************** 137 friends_catch_action() 138 139 Catch actions via pretty urls. 140 **************************************************************************/ 141 142 function friends_catch_action() { 143 global $bp, $thread_id, $current_blog; 144 145 if ( $bp['current_component'] == $bp['friends']['slug'] && $current_blog->blog_id > 1 ) { 146 147 if ( $bp['current_action'] == '' ) 148 $bp['current_action'] = 'my-friends'; 149 150 switch ( $bp['current_action'] ) { 151 case 'my-friends': 152 bp_catch_uri( 'friends/index' ); 153 break; 117 /***** Screens **********/ 118 119 function friends_screen_my_friends() { 120 bp_catch_uri( 'friends/index' ); 121 } 122 123 function friends_screen_requests() { 124 global $bp; 125 126 if ( isset($bp['action_variables']) && in_array( 'accept', $bp['action_variables'] ) && is_numeric($bp['action_variables'][1]) ) { 127 128 if ( friends_accept_friendship( $bp['action_variables'][1] ) ) { 129 $bp['message'] = __('Friendship accepted'); 130 $bp['message_type'] = 'success'; 131 } else { 132 $bp['message'] = __('Friendship could not be accepted'); 133 $bp['message_type'] = 'error'; 134 } 135 add_action( 'template_notices', 'bp_core_render_notice' ); 136 137 } else if ( isset($bp['action_variables']) && in_array( 'reject', $bp['action_variables'] ) && is_numeric($bp['action_variables'][1]) ) { 138 139 if ( friends_reject_friendship( $bp['action_variables'][1] ) ) { 140 $bp['message'] = __('Friendship rejected'); 141 $bp['message_type'] = 'success'; 142 } else { 143 $bp['message'] = __('Friendship could not be rejected'); 144 $bp['message_type'] = 'error'; 145 } 146 add_action( 'template_notices', 'bp_core_render_notice' ); 147 148 } 149 bp_catch_uri( 'friends/requests' ); 150 } 151 152 function friends_screen_friend_finder() { 153 bp_catch_uri( 'friends/friend-finder' ); 154 } 155 156 function friends_screen_invite_friends() { 157 global $bp; 158 $bp['current_action'] = 'my-friends'; 159 160 // Not implemented yet. 161 bp_catch_uri( 'friends/index' ); 162 } 163 164 165 /************************************************************************** 166 friends_record_activity() 167 168 Records activity for the logged in user within the friends component so that 169 it will show in the users activity stream (if installed) 170 **************************************************************************/ 171 172 function friends_record_activity( $args = true ) { 173 if ( function_exists('bp_activity_record') ) { 174 extract($args); 175 bp_activity_record( $item_id, $component_name, $component_action, $is_private, $dual_record, $secondary_user_homebase_id ); 176 } 177 } 178 add_action( 'bp_friends_friendship_accepted', 'friends_record_activity' ); 179 180 181 /************************************************************************** 182 friends_format_activity() 183 184 Selects and formats recorded friends component activity. 185 Example: Selects the friend details for an added connection, then 186 formats it to read "Andy Peatling & John Smith are now friends" 187 **************************************************************************/ 188 189 function friends_format_activity( $friendship_id, $action, $for_secondary_user = false ) { 190 global $bp; 191 192 switch( $action ) { 193 case 'friendship_accepted': 194 $friendship = new BP_Friends_Friendship( $friendship_id, false, false ); 195 196 if ( !$friendship ) 197 return false; 154 198 155 case 'friend-finder': 156 bp_catch_uri( 'friends/friend-finder' ); 157 break; 158 159 case 'requests': 160 if ( isset($bp['action_variables']) && in_array( 'accept', $bp['action_variables'] ) && is_numeric($bp['action_variables'][1]) ) { 161 if ( BP_Friends_Friendship::accept( $bp['action_variables'][1] ) ) { 162 $bp['message'] = __('Friendship accepted'); 163 $bp['message_type'] = 'success'; 164 } else { 165 $bp['message'] = __('Friendship could not be accepted'); 166 $bp['message_type'] = 'error'; 167 } 168 add_action( 'template_notices', 'bp_core_render_notice' ); 169 } else if ( isset($bp['action_variables']) && in_array( 'reject', $bp['action_variables'] ) && is_numeric($bp['action_variables'][1]) ) { 170 if ( BP_Friends_Friendship::reject( $bp['action_variables'][1] ) ) { 171 $bp['message'] = __('Friendship rejected'); 172 $bp['message_type'] = 'success'; 173 } else { 174 $bp['message'] = __('Friendship could not be rejected'); 175 $bp['message_type'] = 'error'; 176 } 177 add_action( 'template_notices', 'bp_core_render_notice' ); 178 } 179 bp_catch_uri( 'friends/requests' ); 180 break; 181 182 default: 183 $bp['current_action'] = 'my-friends'; 184 bp_catch_uri( 'friends/index' ); 185 break; 186 } 187 } 188 } 189 add_action( 'wp', 'friends_catch_action', 3 ); 190 191 192 /************************************************************************** 193 friends_admin_setup() 194 195 Setup CSS, JS and other things needed for the xprofile component. 196 **************************************************************************/ 197 198 function friends_admin_setup() { 199 } 200 add_action( 'admin_menu', 'friends_admin_setup' ); 199 if ( $for_secondary_user ) { 200 return bp_core_get_userlink( $friendship->initiator_user_id ) . ' ' . __('and') . ' ' . bp_core_get_userlink($friendship->friend_user_id, false, false, true) . ' ' . __('are now friends') . '. <span class="time-since">%s</span>'; 201 } else { 202 return bp_core_get_userlink( $friendship->friend_user_id ) . ' ' . __('and') . ' ' . bp_core_get_userlink($friendship->initiator_user_id) . ' ' . __('are now friends') . '. <span class="time-since">%s</span>'; 203 } 204 205 break; 206 } 207 208 return false; 209 } 201 210 202 211 … … 239 248 for ( $i = 0; $i < count($friend_ids); $i++ ) { 240 249 if ( function_exists('bp_user_fullname') ) 241 $display_name = bp_ user_fullname($friend_ids[$i], false);250 $display_name = bp_fetch_user_fullname($friend_ids[$i], false); 242 251 243 252 if ( $display_name != ' ' ) { … … 262 271 } 263 272 273 274 function friends_get_friend_ids_for_user( $user_id ) { 275 return BP_Friends_Friendship::get_friend_ids( $user_id ); 276 } 277 264 278 /************************************************************************** 265 279 friends_search_users() … … 349 363 350 364 $friendship_id = BP_Friends_Friendship::get_friendship_ids( $initiator_userid, $only_confirmed, false, null, null, $friend_userid ); 351 352 365 $friendship = new BP_Friends_Friendship( $friendship_id[0]->id ); 353 366 … … 355 368 } 356 369 370 function friends_accept_friendship( $friendship_id ) { 371 $friendship = new BP_Friends_Friendship( $friendship_id, true, false ); 372 $secondary_user_homebase_id = get_usermeta( $friendship->friend_user_id, 'home_base' ); 373 374 if ( BP_Friends_Friendship::accept( $friendship_id ) ) { 375 do_action( 'bp_friends_friendship_accepted', array( 'item_id' => $friendship_id, 'component_name' => 'friends', 'component_action' => 'friendship_accepted', 'is_private' => 0, 'dual_record' => true, 'secondary_user_homebase_id' => $secondary_user_homebase_id ) ); 376 return true; 377 } 378 379 return false; 380 } 381 382 function friends_reject_friendship( $friendship_id ) { 383 if ( BP_Friends_Friendship::reject( $friendship_id ) ) { 384 do_action( 'bp_friends_friendship_rejected' ); 385 return true; 386 } 387 388 return false; 389 } 390 357 391 358 392 ?> -
trunk/bp-friends/bp-friends-classes.php
r349 r359 10 10 11 11 var $is_request; 12 var $populate_friend_details; 12 13 13 14 var $friend; 14 15 15 function bp_friends_friendship( $id = null, $is_request = false ) {16 function bp_friends_friendship( $id = null, $is_request = false, $populate_friend_details = true ) { 16 17 $this->is_request = $is_request; 17 18 18 19 if ( $id ) { 19 20 $this->id = $id; 21 $this->populate_friend_details = $populate_friend_details; 20 22 $this->populate( $this->id ); 21 23 } … … 45 47 if ( !$bp['current_userid'] ) 46 48 $bp['current_userid'] = $creds['current_userid']; 47 48 if ( $this->friend_user_id == $bp['current_userid'] ) { 49 $this->friend = new BP_Core_User( $this->initiator_user_id ); 50 } else { 51 $this->friend = new BP_Core_User( $this->friend_user_id ); 49 50 if ( $this->populate_friend_details ) { 51 if ( $this->friend_user_id == $bp['current_userid'] ) { 52 $this->friend = new BP_Core_User( $this->initiator_user_id ); 53 } else { 54 $this->friend = new BP_Core_User( $this->friend_user_id ); 55 } 52 56 } 53 57 } … … 175 179 } 176 180 177 function accept($friend_userid) { 178 global $wpdb, $bp; 179 return $wpdb->query( $wpdb->prepare( "UPDATE " . $bp['friends']['table_name'] . " SET is_confirmed = 1, date_created = FROM_UNIXTIME(%d) WHERE initiator_user_id = %d AND friend_user_id = %d", time(), $friend_userid, $bp['loggedin_userid'] ) ); 180 } 181 182 function reject($friend_userid) { 183 global $wpdb, $bp; 184 185 return $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['friends']['table_name'] . " WHERE initiator_user_id = %d AND friend_user_id = %d", $friend_userid, $bp['loggedin_userid'] ) ); 181 function accept($friendship_id) { 182 global $wpdb, $bp; 183 184 return $wpdb->query( $wpdb->prepare( "UPDATE " . $bp['friends']['table_name'] . " SET is_confirmed = 1, date_created = FROM_UNIXTIME(%d) WHERE id = %d AND friend_user_id = %d", time(), $friendship_id, $bp['loggedin_userid'] ) ); 185 } 186 187 function reject($friendship_id) { 188 global $wpdb, $bp; 189 190 return $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['friends']['table_name'] . " WHERE id = %d AND friend_user_id = %d", $friendship_id, $bp['loggedin_userid'] ) ); 186 191 } 187 192 … … 197 202 198 203 // filter the user_ids based on the search criteria. 199 if ( BP_XPROFILE_IS_INSTALLED) {204 if ( function_exists('xprofile_install') ) { 200 205 $sql = $wpdb->prepare( "SELECT DISTINCT d.user_id as id FROM " . $bp['profile']['table_name_data'] . " d, $users_table u WHERE d.user_id = u.id AND d.value LIKE '$filter%%' ORDER BY d.value DESC $pag_sql" ); 201 206 } else { … … 219 224 220 225 // filter the user_ids based on the search criteria. 221 if ( BP_XPROFILE_IS_INSTALLED) {226 if ( function_exists('xprofile_install') ) { 222 227 $sql = $wpdb->prepare( "SELECT DISTINCT count(d.user_id) FROM " . $bp['profile']['table_name_data'] . " d, $users_table u WHERE d.user_id = u.id AND d.value LIKE '$filter%%'" ); 223 228 } else { … … 264 269 return false; 265 270 } 271 272 function get_user_ids_for_friendship( $friendship_id ) { 273 global $wpdb, $bp; 274 275 return $wpdb->get_row( $wpdb->prepare( "SELECT friend_user_id, initiator_user_id FROM " . $bp['friends']['table_name'] . " WHERE id = %d", $friendship_id ) ); 276 } 266 277 } 267 278 -
trunk/bp-friends/bp-friends-templatetags.php
r349 r359 249 249 global $friends_template, $bp; 250 250 251 echo $bp['loggedin_domain'] . $bp['friends']['slug'] . '/requests/accept/' . $friends_template->friendship-> friend->id;251 echo $bp['loggedin_domain'] . $bp['friends']['slug'] . '/requests/accept/' . $friends_template->friendship->id; 252 252 } 253 253 … … 255 255 global $friends_template, $bp; 256 256 257 echo $bp['loggedin_domain'] . $bp['friends']['slug'] . '/requests/reject/' . $friends_template->friendship-> friend->id;257 echo $bp['loggedin_domain'] . $bp['friends']['slug'] . '/requests/reject/' . $friends_template->friendship->id; 258 258 } 259 259 -
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 ?> -
trunk/bp-groups/bp-groups-templatetags.php
r349 r359 20 20 $this->pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : 5; 21 21 22 if ( $bp['current_action'] == 'my-groups' ) {22 if ( $bp['current_action'] == 'my-groups' || !$bp['current_action'] ) { 23 23 24 24 $this->groups = groups_get_user_groups( $this->pag_page, $this->pag_num ); … … 100 100 function bp_has_groups() { 101 101 global $groups_template, $bp; 102 global $is_single_group ;102 global $is_single_group, $group_obj; 103 103 104 104 if ( !$is_single_group ) { 105 105 $groups_template = new BP_Groups_Template( $bp['current_userid'] ); 106 106 } else { 107 $groups_template = new BP_Groups_Template( $bp['current_userid'], $ bp['current_action']);107 $groups_template = new BP_Groups_Template( $bp['current_userid'], $group_obj->slug ); 108 108 } 109 109 -
trunk/bp-messages.php
r347 r359 94 94 95 95 $bp['messages'] = array( 96 'table_name' => $wpdb->base_prefix . 'bp_messages', 97 'table_name_threads' => $wpdb->base_prefix . 'bp_messages_threads', 98 'table_name_messages' => $wpdb->base_prefix . 'bp_messages_messages', 99 'table_name_recipients' => $wpdb->base_prefix . 'bp_messages_recipients', 100 'table_name_notices' => $wpdb->base_prefix . 'bp_messages_notices', 101 'image_base' => get_option('siteurl') . '/wp-content/mu-plugins/bp-messages/images', 102 'slug' => 'messages' 96 'table_name' => $wpdb->base_prefix . 'bp_messages', 97 'table_name_threads' => $wpdb->base_prefix . 'bp_messages_threads', 98 'table_name_messages' => $wpdb->base_prefix . 'bp_messages_messages', 99 'table_name_recipients' => $wpdb->base_prefix . 'bp_messages_recipients', 100 'table_name_notices' => $wpdb->base_prefix . 'bp_messages_notices', 101 'format_activity_function' => 'messages_format_activity', 102 'image_base' => get_option('siteurl') . '/wp-content/mu-plugins/bp-messages/images', 103 'slug' => 'messages' 103 104 ); 104 105 } … … 117 118 global $wpdb, $bp, $userdata; 118 119 119 if ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' )) {120 if ( $wpdb->blogid == $bp['current_homebase_id'] ) { 120 121 //Add the administration tab under the "Site Admin" tab for site administrators 121 122 //add_submenu_page ( 'wpmu-admin.php', __('Messages'), __('Messages'), 1, basename(__FILE__), "messages_settings" ); … … 136 137 function messages_setup_nav() { 137 138 global $bp; 138 139 $nav_key = count($bp['bp_nav']) + 1; 140 141 $bp['bp_nav'][$nav_key] = array( 142 'id' => $bp['messages']['slug'], 143 'name' => 'Messages', 144 'link' => $bp['loggedin_domain'] . $bp['messages']['slug'] . '/' 145 ); 146 147 $bp['bp_options_nav'][$bp['messages']['slug']] = array( 148 'inbox' => array( 149 'name' => __('Inbox') . $count_indicator, 150 'link' => $bp['loggedin_domain'] . $bp['messages']['slug'] . '/' ), 151 'sentbox' => array( 152 'name' => __('Sent Messages'), 153 'link' => $bp['loggedin_domain'] . $bp['messages']['slug'] . '/sentbox' ), 154 'compose' => array( 155 'name' => __('Compose'), 156 'link' => $bp['loggedin_domain'] . $bp['messages']['slug'] . '/compose' ) 157 ); 158 159 if ( is_site_admin() ) { 160 $bp['bp_options_nav'][$bp['messages']['slug']]['notices'] = array( 161 'name' => __('Sent Notices'), 162 'link' => $bp['loggedin_domain'] . $bp['messages']['slug'] . '/notices' 163 ); 164 } 165 139 166 140 $inbox_count = BP_Messages_Thread::get_inbox_count(); 167 141 $inbox_display = ( $inbox_count ) ? ' style="display:inline;"' : ' style="display:none;"'; 168 142 $count_indicator = ' <span' . $inbox_display . ' class="unread-count inbox-count">' . BP_Messages_Thread::get_inbox_count() . '</span>'; 143 144 /* Add 'Profile' to the main navigation */ 145 bp_core_add_nav_item( __('Messages'), $bp['messages']['slug'], false, false ); 146 bp_core_add_nav_default( $bp['messages']['slug'], 'messages_screen_inbox', 'inbox' ); 147 148 $messages_link = $bp['loggedin_domain'] . $bp['messages']['slug'] . '/'; 149 150 /* Add the subnav items to the profile */ 151 bp_core_add_subnav_item( $bp['messages']['slug'], 'inbox', __('Inbox') . $count_indicator, $messages_link, 'messages_screen_inbox' ); 152 bp_core_add_subnav_item( $bp['messages']['slug'], 'sentbox', __('Sent Messages'), $messages_link, 'messages_screen_sentbox' ); 153 bp_core_add_subnav_item( $bp['messages']['slug'], 'compose', __('Compose'), $messages_link, 'messages_screen_compose' ); 154 bp_core_add_subnav_item( $bp['messages']['slug'], 'notices', __('Notices'), $messages_link, 'messages_screen_notices', false, true, true ); 169 155 170 156 if ( $bp['current_component'] == $bp['messages']['slug'] ) { … … 173 159 } else { 174 160 $bp_options_avatar = bp_core_get_avatar( $bp['current_userid'], 1 ); 175 $bp['bp_options_title'] = bp_user_fullname( $bp['current_userid'], false );161 $bp['bp_options_title'] = $bp['current_fullname']; 176 162 } 177 163 } … … 179 165 add_action( 'wp', 'messages_setup_nav', 2 ); 180 166 181 182 /************************************************************************** 183 messages_catch_action() 167 /***** Screens **********/ 168 169 function messages_screen_inbox() { 170 bp_catch_uri( 'messages/index' ); 171 } 172 173 function messages_screen_sentbox() { 174 bp_catch_uri( 'messages/sentbox' ); 175 } 176 177 function messages_screen_compose() { 178 bp_catch_uri( 'messages/compose' ); 179 } 180 181 function messages_screen_notices() { 182 global $bp, $notice_id; 183 184 if ( !is_site_admin() ) 185 return false; 186 187 $notice_id = $bp['action_variables'][1]; 188 189 if ( !$notice_id || !is_numeric($notice_id) ) { 190 $bp['current_action'] = 'notices'; 191 bp_catch_uri( 'messages/notices' ); 192 } else { 193 $notice = new BP_Messages_Notice($notice_id); 194 195 if ( $bp['action_variables'][0] == 'deactivate' ) { 196 if ( !$notice->deactivate() ) { 197 $bp['message'] = __('There was a problem deactivating that notice.'); 198 } else { 199 $bp['message'] = __('Notice deactivated.'); 200 $bp['message_type'] = 'success'; 201 } 202 } else if ( $bp['action_variables'][0] == 'activate' ) { 203 if ( !$notice->activate() ) { 204 $bp['message'] = __('There was a problem activating that notice.'); 205 } else { 206 $bp['message'] = __('Notice activated.'); 207 $bp['message_type'] = 'success'; 208 } 209 } else if ( $bp['action_variables'][0] == 'delete' ) { 210 if ( !$notice->delete() ) { 211 $bp['message'] = __('There was a problem deleting that notice.'); 212 } else { 213 $bp['message'] = __('Notice deleted.'); 214 $bp['message_type'] = 'success'; 215 } 216 } 217 } 218 219 add_action( 'template_notices', 'bp_core_render_notice' ); 220 bp_catch_uri( 'messages/notices' ); 221 } 222 223 /***** Actions **********/ 224 225 function messages_action_view_message() { 226 global $bp, $thread_id; 227 228 if ( $bp['current_component'] != $bp['messages']['slug'] || $bp['current_action'] != 'view' ) 229 return false; 230 231 $thread_id = $bp['action_variables'][0]; 232 233 if ( !$thread_id || !is_numeric($thread_id) || !BP_Messages_Thread::check_access($thread_id) ) { 234 $bp['current_action'] = 'inbox'; 235 bp_catch_uri( 'messages/index' ); 236 } else { 237 $bp['bp_options_nav'][$bp['messages']['slug']]['view'] = array( 238 'name' => __('From: ' . BP_Messages_Thread::get_last_sender($thread_id)), 239 'link' => $bp['loggedin_domain'] . $bp['messages']['slug'] . '/' 240 ); 241 242 bp_catch_uri( 'messages/view' ); 243 } 244 } 245 add_action( 'wp', 'messages_action_view_message', 3 ); 246 247 248 function messages_action_delete_message() { 249 global $bp, $thread_id; 250 251 if ( $bp['current_component'] != $bp['messages']['slug'] || $bp['current_action'] != 'delete' ) 252 return false; 253 254 $thread_id = $bp['action_variables'][0]; 255 256 if ( !$thread_id || !is_numeric($thread_id) || !BP_Messages_Thread::check_access($thread_id) ) { 257 $bp['current_action'] = 'inbox'; 258 bp_catch_uri( 'messages/index' ); 259 } else { 260 // delete message 261 if ( !BP_Messages_Thread::delete($thread_id) ) { 262 $bp['message'] = __('There was an error deleting that message.'); 263 add_action( 'template_notices', 'bp_core_render_notice' ); 264 265 $bp['current_action'] = 'inbox'; 266 bp_catch_uri( 'messages/index' ); 267 } else { 268 $bp['message'] = __('Message deleted.'); 269 $bp['message_type'] = 'success'; 270 add_action( 'template_notices', 'bp_core_render_notice' ); 271 272 $bp['current_action'] = 'inbox'; 273 bp_catch_uri( 'messages/index' ); 274 } 275 } 276 } 277 add_action( 'wp', 'messages_action_delete_message', 3 ); 278 279 280 function messages_action_bulk_delete() { 281 global $bp, $thread_ids; 282 283 if ( $bp['current_component'] != $bp['messages']['slug'] || $bp['current_action'] != 'bulk-delete' ) 284 return false; 285 286 $thread_ids = $_POST['thread_ids']; 287 288 if ( !$thread_ids || !BP_Messages_Thread::check_access($thread_ids) ) { 289 $bp['current_action'] = 'inbox'; 290 bp_catch_uri( 'messages/index' ); 291 } else { 292 if ( !BP_Messages_Thread::delete( explode(',', $thread_ids ) ) ) { 293 $message = __('There was an error deleting messages.'); 294 add_action( 'template_notices', 'bp_core_render_notice' ); 295 296 $bp['current_action'] = 'inbox'; 297 bp_catch_uri( 'messages/index' ); 298 } else { 299 $bp['message'] = __('Messages deleted.'); 300 $bp['message_type'] = 'success'; 301 add_action( 'template_notices', 'bp_core_render_notice' ); 302 303 $bp['current_action'] = 'inbox'; 304 bp_catch_uri( 'messages/index' ); 305 } 306 } 307 } 308 add_action( 'wp', 'messages_action_bulk_delete', 3 ); 309 310 311 /************************************************************************** 312 messages_record_activity() 184 313 185 Catch actions via pretty urls. 186 **************************************************************************/ 187 188 function messages_catch_action() { 189 global $current_blog, $bp, $thread_id; 190 191 if ( $bp['current_component'] == $bp['messages']['slug'] && $current_blog->blog_id > 1 && $bp['loggedin_userid'] == $bp['current_userid'] ) { 192 switch ( $bp['current_action'] ) { 193 case 'inbox': 194 bp_catch_uri( 'messages/index' ); 195 break; 196 197 case 'sentbox': 198 bp_catch_uri( 'messages/sentbox' ); 199 break; 200 201 case 'compose': 202 bp_catch_uri( 'messages/compose' ); 203 break; 204 205 case 'view': 206 if ( !empty($bp['action_variables']) ) { 207 $thread_id = $bp['action_variables'][0]; 208 209 if ( !$thread_id || !is_numeric($thread_id) || !BP_Messages_Thread::check_access($thread_id) ) { 210 $bp['current_action'] = 'inbox'; 211 bp_catch_uri( 'messages/index' ); 212 } else { 213 $bp['bp_options_nav'][$bp['messages']['slug']]['view'] = array( 214 'name' => __('From: ' . BP_Messages_Thread::get_last_sender($thread_id)), 215 'link' => $bp['loggedin_domain'] . $bp['messages']['slug'] . '/' 216 ); 217 218 bp_catch_uri( 'messages/view' ); 219 } 220 } 221 break; 222 223 case 'delete': 224 if ( !empty($bp['action_variables']) ) { 225 $thread_id = $bp['action_variables'][0]; 226 227 if ( !$thread_id || !is_numeric($thread_id) || !BP_Messages_Thread::check_access($thread_id) ) { 228 $bp['current_action'] = 'inbox'; 229 bp_catch_uri( 'messages/index' ); 230 } else { 231 // delete message 232 if ( !BP_Messages_Thread::delete($thread_id) ) { 233 $bp['message'] = __('There was an error deleting that message.'); 234 add_action( 'template_notices', 'bp_core_render_notice' ); 235 236 $bp['current_action'] = 'inbox'; 237 bp_catch_uri( 'messages/index' ); 238 } else { 239 $bp['message'] = __('Message deleted.'); 240 $bp['message_type'] = 'success'; 241 add_action( 'template_notices', 'bp_core_render_notice' ); 242 243 $bp['current_action'] = 'inbox'; 244 bp_catch_uri( 'messages/index' ); 245 } 246 } 247 } 248 break; 249 250 case 'bulk-delete': 251 $thread_ids = $_POST['thread_ids']; 252 253 if ( !$thread_ids || !BP_Messages_Thread::check_access($thread_ids) ) { 254 $bp['current_action'] = 'inbox'; 255 bp_catch_uri( 'messages/index' ); 256 } else { 257 if ( !BP_Messages_Thread::delete( explode(',', $thread_ids ) ) ) { 258 $message = __('There was an error deleting messages.'); 259 add_action( 'template_notices', 'bp_core_render_notice' ); 260 261 $bp['current_action'] = 'inbox'; 262 bp_catch_uri( 'messages/index' ); 263 } else { 264 $bp['message'] = __('Messages deleted.'); 265 $bp['message_type'] = 'success'; 266 add_action( 'template_notices', 'bp_core_render_notice' ); 267 268 $bp['current_action'] = 'inbox'; 269 bp_catch_uri( 'messages/index' ); 270 } 271 } 272 break; 273 274 case 'notices': 275 if ( is_site_admin() ) { 276 if ( isset($bp['action_variables']) ) { 277 $notice_id = $bp['action_variables'][1]; 278 279 if ( !$notice_id || !is_numeric($notice_id) ) { 280 $bp['current_action'] = 'notices'; 281 bp_catch_uri( 'messages/notices' ); 282 } else { 283 $notice = new BP_Messages_Notice($notice_id); 284 285 if ( $bp['action_variables'][0] == 'deactivate' ) { 286 if ( !$notice->deactivate() ) { 287 $bp['message'] = __('There was a problem deactivating that notice.'); 288 } else { 289 $bp['message'] = __('Notice deactivated.'); 290 $bp['message_type'] = 'success'; 291 } 292 } else if ( $bp['action_variables'][0] == 'activate' ) { 293 if ( !$notice->activate() ) { 294 $bp['message'] = __('There was a problem activating that notice.'); 295 } else { 296 $bp['message'] = __('Notice activated.'); 297 $bp['message_type'] = 'success'; 298 } 299 } else if ( $bp['action_variables'][0] == 'delete' ) { 300 if ( !$notice->delete() ) { 301 $bp['message'] = __('There was a problem deleting that notice.'); 302 } else { 303 $bp['message'] = __('Notice deleted.'); 304 $bp['message_type'] = 'success'; 305 } 306 } 307 } 308 } 309 add_action( 'template_notices', 'bp_core_render_notice' ); 310 bp_catch_uri( 'messages/notices' ); 311 } 312 break; 313 314 default: 315 $bp['current_action'] = 'inbox'; 316 bp_catch_uri( 'messages/index' ); 317 break; 318 } 319 } 320 } 321 add_action( 'wp', 'messages_catch_action', 3 ); 314 Records activity for the logged in user within the friends component so that 315 it will show in the users activity stream (if installed) 316 **************************************************************************/ 317 318 function messages_record_activity( $args = true ) { 319 if ( function_exists('bp_activity_record') ) { 320 extract($args); 321 bp_activity_record( $item_id, $component_name, $component_action, $is_private ); 322 } 323 } 324 325 326 /************************************************************************** 327 messages_format_activity() 328 329 Selects and formats recorded messages component activity. 330 **************************************************************************/ 331 332 function messages_format_activity( $friendship_id, $action, $for_secondary_user = false ) { 333 global $bp; 334 335 switch( $action ) { 336 // no actions set yet. 337 } 338 339 return false; 340 } 322 341 323 342 /************************************************************************** … … 583 602 $message = __('Message sent successfully!') . ' <a href="' . $bp['loggedin_domain'] . $bp['messages']['slug'] . '/view/' . $pmessage->thread_id . '">' . __('View Message') . '</a> »'; 584 603 $type = 'success'; 604 605 do_action( 'bp_messages_message_sent', array( 'item_id' => $pmessage->id, 'component_name' => 'messages', 'component_action' => 'message_sent', 'is_private' => 1 ) ); 585 606 586 607 if ( $from_ajax ) { … … 677 698 $type = 'error'; 678 699 } 700 701 do_action( 'bp_messages_message_deleted' ); 702 679 703 } 680 704 … … 684 708 685 709 710 /************************************************************************** 711 messages_view_thread() 712 713 Displays a message thread. 714 **************************************************************************/ 715 686 716 function messages_view_thread( $thread_id ) { 687 global $ bp_messages_image_base, $userdata;717 global $userdata; 688 718 689 719 $thread = new BP_Messages_Thread( $thread_id, true ); -
trunk/bp-messages/bp-messages-templatetags.php
r309 r359 174 174 function bp_message_thread_avatar() { 175 175 global $messages_template; 176 if ( function_exists('bp_core_get_avatar') ) 177 echo bp_core_get_avatar($messages_template->thread->last_sender_id, 1); 176 echo bp_core_get_avatar($messages_template->thread->last_sender_id, 1); 178 177 } 179 178 180 179 function bp_message_thread_view() { 181 180 global $thread_id; 182 181 183 182 messages_view_thread($thread_id); 184 183 } -
trunk/bp-wire.php
r352 r359 58 58 global $bp; 59 59 60 $nav_key = count($bp['bp_nav']) + 1; 61 $user_nav_key = count($bp['bp_users_nav']) + 1; 60 /* Add 'Wire' to the main navigation */ 61 bp_core_add_nav_item( __('Wire'), $bp['wire']['slug'] ); 62 bp_core_add_nav_default( $bp['wire']['slug'], 'bp_wire_screen_latest', 'all-posts' ); 62 63 63 $bp['bp_nav'][$nav_key] = array( 64 'id' => $bp['wire']['slug'], 65 'name' => __('Wire'), 66 'link' => $bp['loggedin_domain'] . $bp['wire']['slug'] . '/' 67 ); 68 69 $bp['bp_users_nav'][$user_nav_key] = array( 70 'id' => $bp['wire']['slug'], 71 'name' => __('Wire'), 72 'link' => $bp['current_domain'] . $bp['wire']['slug'] . '/' 73 ); 74 75 $bp['bp_options_nav'][$bp['wire']['slug']] = array( 76 '' => array( 77 'name' => __('All Posts'), 78 'link' => $bp['loggedin_domain'] . $bp['wire']['slug'] . '/all-posts' ), 79 ); 64 /* Add the subnav items to the wire nav */ 65 bp_core_add_subnav_item( $bp['wire']['slug'], 'all-posts', __('All Posts'), $bp['loggedin_domain'] . $bp['wire']['slug'] . '/', 'bp_wire_screen_latest' ); 80 66 81 67 if ( $bp['current_component'] == $bp['wire']['slug'] ) { … … 84 70 } else { 85 71 $bp['bp_options_avatar'] = bp_core_get_avatar( $bp['current_userid'], 1 ); 86 $bp['bp_options_title'] = bp_user_fullname( $bp['current_userid'], false );72 $bp['bp_options_title'] = $bp['current_fullname']; 87 73 } 88 74 } 89 90 75 } 91 76 add_action( 'wp', 'bp_wire_setup_nav', 2 ); 92 77 78 /***** Screens **********/ 93 79 94 /************************************************************************** 95 bp_wire_catch_action() 96 97 Catch actions via pretty urls. 98 **************************************************************************/ 80 function bp_wire_screen_latest() { 81 bp_catch_uri( 'wire/latest' ); 82 } 99 83 100 function bp_wire_catch_action() { 101 global $bp, $current_blog; 84 /***** Actions **********/ 85 86 function bp_wire_action_post() { 87 global $bp; 102 88 103 if ( $bp['current_ component'] == $bp['wire']['slug'] && $current_blog->blog_id > 1 ) {104 switch ( $bp['current_action'] ) {105 case 'post':106 if (bp_wire_new_post( $bp['current_userid'], $_POST['wire-post-textarea'], $bp['profile']['table_name_wire'] ) ) {107 108 89 if ( $bp['current_action'] != 'post' ) 90 return false; 91 92 if ( $wire_post_id = bp_wire_new_post( $bp['current_userid'], $_POST['wire-post-textarea'], $bp['profile']['table_name_wire'] ) ) { 93 $bp['message'] = __('Wire message successfully posted.'); 94 $bp['message_type'] = 'success'; 109 95 110 add_action( 'template_notices', 'bp_core_render_notice' ); 111 } 112 113 if ( !strpos( $_SERVER['HTTP_REFERER'], $bp['wire']['slug'] ) ) { 114 $bp['current_component'] = $bp['profile']['slug']; 115 $bp['current_action'] = 'public'; 116 bp_catch_uri( 'profile/index' ); 117 } else { 118 bp_catch_uri( 'wire/latest' ); 119 } 120 121 break; 122 123 case 'delete': 124 if ( bp_wire_delete_post( $bp['action_variables'][0], $bp['profile']['table_name_wire'] ) ) { 125 $bp['message'] = __('Wire message successfully deleted.'); 126 $bp['message_type'] = 'success'; 96 do_action( 'bp_xprofile_new_wire_post', array( 'item_id' => $wire_post_id, 'component_name' => 'profile', 'component_action' => 'new_wire_post', 'is_private' => 0 ) ); 97 add_action( 'template_notices', 'bp_core_render_notice' ); 98 } 99 100 if ( !strpos( $_SERVER['HTTP_REFERER'], $bp['wire']['slug'] ) ) { 101 $bp['current_component'] = $bp['profile']['slug']; 102 $bp['current_action'] = 'public'; 103 bp_catch_uri( 'profile/index' ); 104 } else { 105 bp_catch_uri( 'wire/latest' ); 106 } 107 } 108 add_action( 'wp', 'bp_wire_action_post', 3 ); 127 109 128 add_action( 'template_notices', 'bp_core_render_notice' ); 129 } 130 131 if ( !strpos( $_SERVER['HTTP_REFERER'], $bp['wire']['slug'] ) ) { 132 $bp['current_component'] = $bp['profile']['slug']; 133 $bp['current_action'] = 'public'; 134 bp_catch_uri( 'profile/index' ); 135 } else { 136 bp_catch_uri( 'wire/latest' ); 137 } 138 break; 139 140 default: 141 bp_catch_uri( 'wire/latest' ); 142 break; 143 } 110 function bp_wire_action_delete() { 111 global $bp; 112 113 if ( $bp['current_action'] != 'delete' ) 114 return false; 115 116 if ( bp_wire_delete_post( $bp['action_variables'][0], $bp['profile']['table_name_wire'] ) ) { 117 $bp['message'] = __('Wire message successfully deleted.'); 118 $bp['message_type'] = 'success'; 119 120 do_action( 'bp_xprofile_delete_wire_post' ); 121 add_action( 'template_notices', 'bp_core_render_notice' ); 122 } 123 124 if ( !strpos( $_SERVER['HTTP_REFERER'], $bp['wire']['slug'] ) ) { 125 $bp['current_component'] = $bp['profile']['slug']; 126 $bp['current_action'] = 'public'; 127 bp_catch_uri( 'profile/index' ); 128 } else { 129 bp_catch_uri( 'wire/latest' ); 144 130 } 145 131 } 146 add_action( 'wp', 'bp_wire_ catch_action', 3 );132 add_action( 'wp', 'bp_wire_action_delete', 3 ); 147 133 148 134 … … 169 155 do_action( 'bp_wire_post_posted', $wire_post->id, $wire_post->item_id, $wire_post->user_id ); 170 156 171 return true;157 return $wire_post->id; 172 158 } 159 add_action( 'wp', 'bp_wire_action_delete', 3 ); 173 160 174 161 function bp_wire_delete_post( $wire_post_id, $table_name = null ) { -
trunk/bp-wire/bp-wire-templatetags.php
r352 r359 195 195 global $bp; 196 196 197 if ( $bp['current_item'] == '') 198 $uri = $bp['current_action']; 199 else 200 $uri = $bp['current_item']; 201 197 202 if ( $bp['current_component'] == 'wire' || $bp['current_component'] == 'profile' ) { 198 203 echo $bp['current_domain'] . $bp['wire']['slug'] . '/post/'; 199 204 } else { 200 echo $bp['current_domain'] . $bp[$bp['current_component']]['slug'] . '/' . $ bp['current_action']. '/wire/post/';205 echo $bp['current_domain'] . $bp[$bp['current_component']]['slug'] . '/' . $uri . '/wire/post/'; 201 206 } 202 207 } … … 224 229 global $wire_posts_template, $bp; 225 230 231 if ( $bp['current_item'] == '') 232 $uri = $bp['current_action']; 233 else 234 $uri = $bp['current_item']; 235 226 236 if ( ( $wire_posts_template->wire_post->user_id == $bp['loggedin_userid'] ) || $bp['is_item_admin'] ) { 227 237 if ( $bp['current_component'] == 'wire' || $bp['current_component'] == 'profile' ) { 228 238 echo '<a href="' . $bp['current_domain'] . $bp['wire']['slug'] . '/delete/' . $wire_posts_template->wire_post->id . '">[' . __('Delete') . ']</a>'; 229 239 } else { 230 echo '<a href="' . $bp['current_domain'] . $bp[$bp['current_component']]['slug'] . '/' . $ bp['current_action']. '/wire/delete/' . $wire_posts_template->wire_post->id . '">[' . __('Delete') . ']</a>';240 echo '<a href="' . $bp['current_domain'] . $bp[$bp['current_component']]['slug'] . '/' . $uri . '/wire/delete/' . $wire_posts_template->wire_post->id . '">[' . __('Delete') . ']</a>'; 231 241 } 232 242 } … … 235 245 function bp_wire_see_all_link() { 236 246 global $bp; 247 248 if ( $bp['current_item'] == '') 249 $uri = $bp['current_action']; 250 else 251 $uri = $bp['current_item']; 237 252 238 253 if ( $bp['current_component'] == 'wire' || $bp['current_component'] == 'profile') { 239 254 echo $bp['current_domain'] . $bp['wire']['slug']; 240 255 } else if ( $bp['current_component'] == 'groups' ) { 241 echo $bp['current_domain'] . $bp['groups']['slug'] . '/' . $ bp['current_action']. '/wire';256 echo $bp['current_domain'] . $bp['groups']['slug'] . '/' . $uri . '/wire'; 242 257 } else { 243 258 echo $bp['current_domain'] . $bp[$bp['current_component']]['slug'] . '/wire'; -
trunk/bp-xprofile.php
r352 r359 113 113 'table_name_fields' => $wpdb->base_prefix . 'bp_xprofile_fields', 114 114 'table_name_data' => $wpdb->base_prefix . 'bp_xprofile_data', 115 'format_activity_function' => 'xprofile_format_activity', 115 116 'image_base' => get_option('siteurl') . '/wp-content/mu-plugins/bp-xprofile/images', 116 117 'slug' => 'profile' … … 119 120 if ( function_exists('bp_wire_install') ) 120 121 $bp['profile']['table_name_wire'] = $wpdb->base_prefix . 'bp_xprofile_wire'; 122 123 121 124 } 122 125 add_action( 'wp', 'xprofile_setup_globals', 1 ); … … 134 137 global $wpdb, $bp, $groups, $userdata; 135 138 136 if ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' )) {139 if ( $wpdb->blogid == $bp['current_homebase_id'] ) { 137 140 add_menu_page( __('Profile'), __('Profile'), 1, basename(__FILE__), 'bp_core_avatar_admin' ); 138 141 add_submenu_page( basename(__FILE__), __('Profile › Avatar'), __('Avatar'), 1, basename(__FILE__), 'xprofile_avatar_admin' ); 139 add_options_page( __('Profile'), __('Profile'), 1, basename(__FILE__), 'xprofile_add_settings' );140 142 141 143 $groups = BP_XProfile_Group::get_all(); … … 172 174 global $bp; 173 175 174 $nav_key = count($bp['bp_nav']) + 1; 175 $user_nav_key = count($bp['bp_users_nav']) + 1; 176 177 $bp['bp_nav'][$nav_key] = array( 178 'id' => $bp['profile']['slug'], 179 'name' => 'Profile', 180 'link' => $bp['loggedin_domain'] . $bp['profile']['slug'] 181 ); 182 183 $bp['bp_users_nav'][$user_nav_key] = array( 184 'id' => $bp['profile']['slug'], 185 'name' => 'Profile', 186 'link' => $bp['current_domain'] . $bp['profile']['slug'] 187 ); 188 189 $bp['bp_options_nav'][$bp['profile']['slug']] = array( 190 'public' => array( 191 'name' => __('Public'), 192 'link' => $bp['loggedin_domain'] . $bp['profile']['slug'] . '/' ), 193 'edit' => array( 194 'name' => __('Edit Profile'), 195 'link' => $bp['loggedin_domain'] . $bp['profile']['slug'] . '/edit' ), 196 'change-avatar' => array( 197 'name' => __('Change Avatar'), 198 'link' => $bp['loggedin_domain'] . $bp['profile']['slug'] . '/change-avatar' ) 199 ); 200 176 /* Add 'Profile' to the main navigation */ 177 bp_core_add_nav_item( __('Profile'), $bp['profile']['slug'] ); 178 bp_core_add_nav_default( $bp['profile']['slug'], 'xprofile_screen_display_profile', 'public' ); 179 180 $profile_link = $bp['loggedin_domain'] . $bp['profile']['slug'] . '/'; 181 182 /* Add the subnav items to the profile */ 183 bp_core_add_subnav_item( $bp['profile']['slug'], 'public', __('Public'), $profile_link, 'xprofile_screen_display_profile' ); 184 bp_core_add_subnav_item( $bp['profile']['slug'], 'edit', __('Edit Profile'), $profile_link, 'xprofile_screen_edit_profile' ); 185 bp_core_add_subnav_item( $bp['profile']['slug'], 'change-avatar', __('Change Avatar'), $profile_link, 'xprofile_screen_change_avatar' ); 186 201 187 if ( $bp['current_component'] == $bp['profile']['slug'] ) { 202 188 if ( bp_is_home() ) { … … 204 190 } else { 205 191 $bp['bp_options_avatar'] = bp_core_get_avatar( $bp['current_userid'], 1 ); 206 $bp['bp_options_title'] = bp_user_fullname( $bp['current_userid'], false );192 $bp['bp_options_title'] = $bp['current_fullname']; 207 193 } 208 194 } 209 210 195 } 211 196 add_action( 'wp', 'xprofile_setup_nav', 2 ); 212 197 213 214 /************************************************************************** 215 xprofile_catch_action() 216 217 Catch actions via pretty urls. 218 **************************************************************************/ 219 220 function xprofile_catch_action() { 221 global $current_blog, $bp; 222 223 if ( $bp['current_component'] == $bp['profile']['slug'] && $current_blog->blog_id > 1 ) { 224 225 if ( $bp['current_action'] == 'public' ) { 226 bp_catch_uri( 'profile/index' ); 227 } else if ( $bp['current_action'] == 'edit' && $bp['loggedin_userid'] == $bp['current_userid'] ) { 228 bp_catch_uri( 'profile/edit' ); 229 } else if ( $bp['current_action'] == 'change-avatar' && $bp['loggedin_userid'] == $bp['current_userid'] ) { 230 add_action( 'wp_head', 'bp_core_add_cropper_js' ); 231 bp_catch_uri( 'profile/change-avatar' ); 232 } else if ( $bp['current_action'] == 'delete-avatar' && $bp['loggedin_userid'] == $bp['current_userid'] ) { 233 bp_core_delete_avatar(); 234 add_action( 'wp_head', 'bp_core_add_cropper_js' ); 235 bp_catch_uri( 'profile/change-avatar' ); 236 } else { 237 $bp['current_action'] = 'public'; 238 bp_catch_uri( 'profile/index' ); 239 } 240 } 241 } 242 add_action( 'wp', 'xprofile_catch_action', 3 ); 198 /***** Screens **********/ 199 200 function xprofile_screen_display_profile() { 201 bp_catch_uri( 'profile/index' ); 202 } 203 204 function xprofile_screen_edit_profile() { 205 if ( bp_is_home() ) 206 bp_catch_uri( 'profile/edit' ); 207 } 208 209 function xprofile_screen_change_avatar() { 210 if ( bp_is_home() ) { 211 add_action( 'wp_head', 'bp_core_add_cropper_js' ); 212 bp_catch_uri( 'profile/change-avatar' ); 213 } 214 } 215 216 /***** Actions **********/ 217 218 function xprofile_action_delete_avatar() { 219 global $bp; 220 221 if ( $bp['current_action'] != 'delete-avatar' ) 222 return false; 223 224 if ( bp_is_home() ) { 225 bp_core_delete_avatar(); 226 add_action( 'wp_head', 'bp_core_add_cropper_js' ); 227 bp_catch_uri( 'profile/change-avatar' ); 228 } 229 } 230 add_action( 'wp', 'xprofile_action_delete_avatar', 3 ); 231 232 233 /************************************************************************** 234 xprofile_record_activity() 235 236 Records activity for the logged in user within the profile component so that 237 it will show in the users activity stream (if installed) 238 **************************************************************************/ 239 240 function xprofile_record_activity( $args = true ) { 241 global $bp; 242 243 if ( function_exists('bp_activity_record') ) { 244 extract($args); 245 bp_activity_record( $item_id, $component_name, $component_action, $is_private ); 246 } 247 } 248 add_action( 'bp_xprofile_new_wire_post', 'xprofile_record_activity' ); 249 add_action( 'bp_xprofile_updated_profile', 'xprofile_record_activity' ); 250 251 252 /************************************************************************** 253 xprofile_format_activity() 254 255 Selects and formats recorded xprofile component activity. 256 **************************************************************************/ 257 258 function xprofile_format_activity( $item_id, $action, $for_secondary_user = false ) { 259 global $bp; 260 261 switch( $action ) { 262 case 'new_wire_post': 263 $wire_post = new BP_Wire_Post( $bp['profile']['table_name_wire'], $item_id ); 264 265 if ( !$wire_post ) 266 return false; 267 268 if ( $wire_post->item_id == $bp['loggedin_userid'] && $wire_post->user_id == $bp['loggedin_userid'] ) { 269 $content = bp_core_get_userlink($wire_post->user_id) . ' ' . __('wrote on') . ' ' . bp_your_or_their() . ' ' . __('own wire') . ': <span class="time-since">%s</span>'; 270 } else if ( $wire_post->item_id != $bp['loggedin_userid'] && $wire_post->user_id == $bp['loggedin_userid'] ) { 271 $content = bp_core_get_userlink($wire_post->user_id) . ' ' . __('wrote on ') . bp_core_get_userlink( $wire_post->item_id, false, false, true, true ) . ' wire: <span class="time-since">%s</span>'; 272 } 273 274 $content .= '<blockquote>' . bp_create_excerpt($wire_post->content) . '</blockquote>'; 275 return $content; 276 break; 277 case 'updated_profile': 278 $profile_group = new BP_XProfile_Group( $item_id ); 279 280 if ( !$profile_group ) 281 return false; 282 283 return bp_core_get_userlink($bp['current_userid']) . ' ' . __('updated the') . ' "<a href="' . $bp['current_domain'] . $bp['profile']['slug'] . '">' . $profile_group->name . '</a>" ' . __('information on') . ' ' . bp_your_or_their() . ' ' . __('profile') . '. <span class="time-since">%s</span>'; 284 break; 285 } 286 287 return false; 288 } 243 289 244 290 /************************************************************************** … … 289 335 $field->message = sprintf( __('%s cannot be left blank.'), $field->name ); 290 336 $errors[] = $field->message . "<br />"; 291 } 292 else if ( !$field->is_required && ( $current_field == '' || is_null($current_field) ) ) { 337 } else if ( !$field->is_required && ( $current_field == '' || is_null($current_field) ) ) { 293 338 // data removed, so delete the field data from the DB. 294 339 $profile_data = new BP_Xprofile_ProfileData( $group->fields[$j]->id ); 295 340 $profile_data->delete(); 296 341 $field->data->value = null; 297 } 298 else { 342 } else { 299 343 // Field validates, save. 300 344 $profile_data = new BP_Xprofile_ProfileData; … … 303 347 $profile_data->last_updated = time(); 304 348 305 if ($post_field_string != null) {349 if ( $post_field_string != null ) { 306 350 $date_value = $_POST['field_' . $group->fields[$j]->id . '_day'] . 307 351 $_POST['field_' . $group->fields[$j]->id . '_month'] . … … 309 353 310 354 $profile_data->value = strtotime($date_value); 311 } 312 else { 355 } else { 313 356 if ( is_array($current_field) ) 314 357 $current_field = serialize($current_field); … … 317 360 } 318 361 319 if( !$profile_data->save()) {362 if( !$profile_data->save() ) { 320 363 $field->message = __('There was a problem saving changes to this field, please try again.'); 321 } 322 else { 364 } else { 323 365 $field->data->value = $profile_data->value; 324 366 } … … 342 384 $message .= $errors[$i]; 343 385 } 344 } 345 else if ( !$errors && isset($_POST['save'] ) ) { 386 } else if ( !$errors && isset($_POST['save'] ) ) { 346 387 $type = 'success'; 347 388 $message = __('Changes saved.'); 348 389 390 do_action( 'bp_xprofile_updated_profile', array( 'item_id' => $group->id, 'component_name' => 'profile', 'component_action' => 'updated_profile', 'is_private' => 0 ) ); 349 391 update_usermeta( $bp['loggedin_userid'], 'profile_last_updated', date("Y-m-d H:i:s") ); 350 392 } -
trunk/bp-xprofile/bp-xprofile-classes.php
r343 r359 1084 1084 $user_id = $bp['current_userid']; 1085 1085 1086 if ( !$bp['profile'] ) 1087 xprofile_setup_globals(); 1088 1086 1089 $field_sql = ''; 1087 1090 … … 1100 1103 1101 1104 $sql = $wpdb->prepare( "SELECT d.value, f.name FROM " . $bp['profile']['table_name_data'] . " d, " . $bp['profile']['table_name_fields'] . " f WHERE d.field_id = f.id AND d.user_id = %d AND f.parent_id = 0 $field_sql", $user_id ); 1102 1105 1103 1106 if ( !$values = $wpdb->get_results($sql) ) 1104 1107 return false; … … 1145 1148 global $wpdb, $bp; 1146 1149 1147 return $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['profile']['table_name_data'] . " WHERE user_id = %d", $user_id ) ); 1148 1150 return $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['profile']['table_name_data'] . " WHERE user_id = %d", $user_id ) ); 1151 } 1152 1153 function get_fullname( $user_id = false ) { 1154 global $bp; 1155 1156 if ( !$user_id ) 1157 $user_id = $bp['current_userid']; 1158 1159 $data = bp_get_field_data( array( 'First Name', 'Last Name' ), $user_id ); 1160 1161 return ucfirst($data['First Name']) . ' ' . ucfirst($data['Last Name']); 1149 1162 } 1150 1163 } -
trunk/bp-xprofile/bp-xprofile-templatetags.php
r343 r359 157 157 } 158 158 159 function bp_field_css_class() { 160 global $profile_template; 161 162 if ( $profile_template->current_field % 2 ) 163 echo ' class="alt"'; 164 } 165 159 166 function bp_field_has_data() { 160 167 global $profile_template; … … 230 237 } 231 238 232 function bp_ user_fullname($user_id = false, $echo = true) {239 function bp_fetch_user_fullname( $user_id = false, $echo = true ) { 233 240 global $bp; 234 241 … … 239 246 240 247 if ( $echo ) 241 echo ucfirst($data['First Name']) . ' ' . ucfirst($data['Last Name']); 248 echo ucfirst($data['First Name']) . ' ' . ucfirst($data['Last Name']); 242 249 else 243 return ucfirst($data['First Name']) . ' ' . ucfirst($data['Last Name']); 250 return ucfirst($data['First Name']) . ' ' . ucfirst($data['Last Name']); 244 251 } 245 252
Note: See TracChangeset
for help on using the changeset viewer.