Skip to:
Content

BuddyPress.org

Changeset 359


Ignore:
Timestamp:
09/24/2008 05:31:27 AM (18 years ago)
Author:
apeatling
Message:

Introduced new functions for handling navigation items. bp_core_add_nav_item() bp_core_add_nav_default() bp_core_add_subnav_item() can now be used.

Location:
trunk
Files:
3 deleted
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-blogs.php

    r348 r359  
    7676        global $wpdb, $bp, $userdata;
    7777
    78         if ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' ) ) {
     78        if ( $wpdb->blogid == $bp['current_homebase_id'] ) {
    7979                add_menu_page( __("Blogs"), __("Blogs"), 10, 'bp-blogs/admin-tabs/bp-blogs-tab.php' );
    8080                add_submenu_page( 'bp-blogs/admin-tabs/bp-blogs-tab.php', __("My Blogs"), __("My Blogs"), 10, 'bp-blogs/admin-tabs/bp-blogs-tab.php' );
    … …  
    104104                'table_name_blog_posts' => $wpdb->base_prefix . 'bp_user_blogs_posts',
    105105                'table_name_blog_comments' => $wpdb->base_prefix . 'bp_user_blogs_comments',
     106                'format_activity_function' => 'bp_blogs_format_activity',
    106107                'image_base' => get_option('siteurl') . '/wp-content/mu-plugins/bp-groups/images',
    107108                'slug'           => 'blogs'
    … …  
    127128        global $bp;
    128129       
    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' );
    161141       
    162142        /* Set up the component options navigation for Blog */
    … …  
    169149                        /* If we are not viewing the logged in user, set up the current users avatar and name */
    170150                        $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'];
    172152                }
    173153        }
    … …  
    175155add_action( 'wp', 'bp_blogs_setup_nav', 2 );
    176156
     157/***** Screens **********/
     158
     159function bp_blogs_screen_my_blogs() {
     160        bp_catch_uri( 'blogs/my-blogs' );       
     161}
     162
     163function bp_blogs_screen_recent_posts() {
     164        bp_catch_uri( 'blogs/recent-posts' );
     165}
     166
     167function bp_blogs_screen_recent_comments() {
     168        bp_catch_uri( 'blogs/recent-comments' );
     169}
     170
     171function bp_blogs_screen_create_a_blog() {
     172        bp_catch_uri( 'blogs/create' );
     173}
     174
    177175
    178176/**************************************************************************
    179  bp_blogs_catch_action()
     177 bp_blogs_record_activity()
    180178 
    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)
    182181 **************************************************************************/
    183182
    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;
     183function 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}
     196add_action( 'bp_blogs_new_blog', 'bp_blogs_record_activity' );
     197add_action( 'bp_blogs_new_blog_post', 'bp_blogs_record_activity' );
     198add_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
     206function 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':
    192231               
    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
    213250
    214251function bp_blogs_record_blog( $blog_id = '', $user_id = '' ) {
    … …  
    226263                $recorded_blog->blog_id = $blog_id;
    227264
    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 ) );
    229268        }
    230269}
    … …  
    255294                        $recorded_post->date_created = strtotime( $post->post_date );
    256295                       
    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 ) );
    258299                }
    259300        } else {
    … …  
    305346                                $recorded_comment->date_created = strtotime( $comment->comment_date );
    306347                                       
    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 ) );
    308351                        }
    309352                } else {
    … …  
    376419add_action( 'delete_comment', 'bp_blogs_remove_comment' );
    377420
    378 function bp_blogs_remove_all_data_for_user( $blog_id ) {
    379         /* Only delete profile data if we are removing a home base */
     421function bp_blogs_remove_data( $blog_id ) {
     422
    380423        if ( $user_id = bp_core_get_homebase_userid( $blog_id ) ) {
     424                /* If this is a home base, delete everything for that user. */
    381425                BP_Blogs_Blog::delete_blogs_for_user( $user_id );
    382426                BP_Blogs_Post::delete_posts_for_user( $user_id );
    383427                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}
     436add_action( 'delete_blog', 'bp_blogs_remove_data', 1 );
    387437
    388438function bp_blogs_register_existing_content( $blog_id ) {
  • trunk/bp-blogs/bp-blogs-classes.php

    r308 r359  
    66        var $blog_id;
    77       
    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
    2525                $this->user_id = $blog->user_id;
    2626                $this->blog_id = $blog->blog_id;
    … …  
    4141                }
    4242               
    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;
    4450        }
    4551       
    … …  
    99105        var $date_created;
    100106       
    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
    118124                $this->user_id = $post->user_id;
    119125                $this->blog_id = $post->blog_id;
    … …  
    133139                }
    134140               
    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;       
    136148        }
    137149       
    … …  
    163175
    164176                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 ) );
    165183        }
    166184       
    … …  
    175193               
    176194                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]);
    180196                }
    181197
    182198                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;
    183207        }
    184208       
    … …  
    210234        var $date_created;
    211235       
    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
    229253                $this->comment_id = $comment->comment_id;
    230254                $this->user_id = $comment->user_id;
    … …  
    245269                }
    246270
    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;       
    248278        }
    249279
    … …  
    277307        }
    278308       
     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       
    279315        function get_comments_for_user( $user_id = null ) {
    280316                global $bp, $wpdb;
    … …  
    287323               
    288324                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]);
    293326                }
    294327
    295328                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;
    296338        }
    297339       
  • trunk/bp-blogs/bp-blogs-cssjs.php

    r308 r359  
    44        global $bp, $wpdb;
    55
    6         if ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' ) ) {
     6        if ( $wpdb->blogid == $bp['current_homebase_id'] ) {
    77                if ( strpos( $_GET['page'], 'bp-blogs' ) !== false ) {
    88                        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  
    312312function bp_post_category( $separator = '', $parents='', $post_id = false ) {
    313313        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 );   
    315315}
    316316
  • trunk/bp-core.php

    r352 r359  
    4040        global $action_variables;
    4141
    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
    95104        if ( !$bp['current_component'] )
    96105                $bp['current_component'] = $bp['default_component'];
     106
    97107}
    98108add_action( 'wp', 'bp_core_setup_globals', 1 );
    … …  
    112122        global $bp, $wpdb;
    113123
    114         if ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' ) ) {
     124        if ( $wpdb->blogid == $bp['current_homebase_id'] ) {
    115125                $component_check = $bp['current_component'];
    116126
    … …  
    265275        global $bp;
    266276
    267         if ( get_usermeta( $bp['loggedin_userid'], 'home_base' ) == '' )
     277        if ( $bp['loggedin_homebase_id'] == '' )
    268278                return false;
    269279       
    … …  
    426436}
    427437
     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 */
    428448function bp_core_replace_home_base_dashboard() {
    429449        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'] ) {
    432452                add_action( 'admin_head', 'bp_core_start_dash_replacement' );
    433453        }       
    … …  
    435455add_action( 'admin_menu', 'bp_core_replace_home_base_dashboard' );
    436456
     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 */
    437465function bp_core_start_dash_replacement( $dash_contents ) {     
    438466        ob_start();
    … …  
    440468}
    441469
     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 */
    442478function bp_core_insert_new_dashboard( $dash_contents ) {
    443479        global $bp;
    444480       
    445481        $filter = preg_split( '/\<div class=\"wrap\"\>[\S\s]*\<div id=\"footer\"\>/', $dash_contents );
     482
    446483        $filter[0] .= '<div class="wrap">';
    447484        $filter[1] .= '</div>';
    448485       
    449486        echo $filter[0];
    450        
     487        //echo ABSPATH . 'wp-content/mu-plugins/bp-core/admin-mods/bp-core-homebase-dashboard.php';
    451488        require_once( ABSPATH . '/wp-content/mu-plugins/bp-core/admin-mods/bp-core-homebase-dashboard.php' );
    452489       
    … …  
    455492}
    456493
     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 */
    457502function bp_core_end_dash_replacement() {
    458503        $dash_contents = ob_get_contents();
    459504        ob_end_clean();
    460505        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 */
     522function 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 */
     562function 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 */
     594function 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 */
     611function 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        }
    461622}
    462623
    … …  
    559720 * @return str The link text based on passed parameters.
    560721 */
    561 function bp_core_get_userlink( $uid, $no_anchor = false, $just_link = false, $no_you = false ) {
     722function bp_core_get_userlink( $user_id, $no_anchor = false, $just_link = false, $no_you = false, $with_s = false ) {
    562723        global $userdata;
    563724       
    564         $ud = get_userdata($uid);
     725        $ud = get_userdata($user_id);
    565726       
    566727        if ( !$ud )
    567728                return false;
    568729
    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 {
    572737                $display_name = $ud->display_name;
    573        
    574         if ( $uid == $userdata->ID && !$no_you )
     738        }
     739       
     740        if ( $user_id == $userdata->ID && !$no_you )
    575741                $display_name = 'You';
    576 
     742       
    577743        if ( $no_anchor )
    578744                return $display_name;
    579745
    580         $home_base_id = get_usermeta( $uid, 'home_base' );
     746        $home_base_id = get_usermeta( $user_id, 'home_base' );
    581747       
    582748        if ( !$home_base_id )
    … …  
    584750               
    585751        $home_base_url = get_blog_option( $home_base_id, 'siteurl' ) . '/';
    586        
     752
    587753        if ( $just_link )
    588754                return $home_base_url;
    589755
    590756        return '<a href="' . $home_base_url . '">' . $display_name . '</a>';   
     757}
     758
     759function 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        }
    591766}
    592767
    … …  
    9101085        global $bp;
    9111086       
    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;
    9141093                        case $bp['profile']['slug']:
    915                                 $new_nav[0] = $nav_item;
     1094                                $new_nav[1] = $nav_array[$key];
     1095                                unset($nav_array[$key]);
    9161096                        break;
    9171097                        case $bp['blogs']['slug']:
    918                                 $new_nav[1] = $nav_item;
     1098                                $new_nav[2] = $nav_array[$key];
     1099                                unset($nav_array[$key]);
    9191100                        break;
    9201101                        case $bp['wire']['slug']:
    921                                 $new_nav[2] = $nav_item;
     1102                                $new_nav[3] = $nav_array[$key];
     1103                                unset($nav_array[$key]);
    9221104                        break;
    9231105                        case $bp['messages']['slug']:
    924                                 $new_nav[3] = $nav_item;
     1106                                $new_nav[4] = $nav_array[$key];
     1107                                unset($nav_array[$key]);
    9251108                        break;
    9261109                        case $bp['friends']['slug']:
    927                                 $new_nav[4] = $nav_item;
     1110                                $new_nav[5] = $nav_array[$key];
     1111                                unset($nav_array[$key]);
    9281112                        break;
    9291113                        case $bp['groups']['slug']:
    930                                 $new_nav[5] = $nav_item;
     1114                                $new_nav[6] = $nav_array[$key];
     1115                                unset($nav_array[$key]);
    9311116                        break;
    9321117                        case $bp['gallery']['slug']:
    933                                 $new_nav[6] = $nav_item;
     1118                                $new_nav[7] = $nav_array[$key];
     1119                                unset($nav_array[$key]);
    9341120                        break;
    9351121                        case $bp['account']['slug']:
    936                                 $new_nav[7] = $nav_item;
     1122                                $new_nav[8] = $nav_array[$key];
     1123                                unset($nav_array[$key]);
    9371124                        break;
    9381125                }
    … …  
    9401127       
    9411128        ksort($new_nav);
     1129       
     1130        array_merge( $new_nav, $nav_array );
    9421131        return $new_nav;
    9431132}
  • trunk/bp-core/admin-mods/bp-core-admin-styles.php

    r309 r359  
    33        global $bp, $wpdb;
    44       
    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'] ) {
    66                $avatar_href = bp_core_get_avatar( $bp['loggedin_userid'], 1, true );
    77               
  • 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>
    92
    103<div id="rightnow">
  • trunk/bp-core/admin-mods/bp-core-remove-blogtabs.php

    r309 r359  
    66       
    77        /* 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'] ) {
    99                unset($menu[5]);
    1010                unset($menu[10]);
    … …  
    3333       
    3434        /* 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'] ) {
    3636                $menu[27] = $menu[41];
    3737                unset($menu[41]);
  • trunk/bp-core/bp-core-avatars.php

    r339 r359  
    467467                #avatar_v2 { display: none; }
    468468                .crop-img { float: left; margin: 0 20px 15px 0; }
    469                 .submit { clear: left; }
    470469        </style>
    471470
  • trunk/bp-core/bp-core-catchuri.php

    r309 r359  
    7575        /* Reset the keys by merging with an empty array */
    7676        $action_variables = array_merge( array(), $action_variables );
    77 
    7877}
    79 add_action( 'wp', 'bp_core_set_uri_globals', 0 );
     78add_action( 'wp', 'bp_core_set_uri_globals', 1 );
    8079
    8180/**
    … …  
    111110        $pages = $bp_path;
    112111       
    113         if ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' ) ) {
     112        if ( $wpdb->blogid == $bp['current_homebase_id'] ) {
    114113                if ( !file_exists( TEMPLATEPATH . "/header.php" ) || !file_exists( TEMPLATEPATH . "/footer.php" ) )
    115114                        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  
    2828
    2929        /* Loop through each navigation item */
    30         foreach( $bp['bp_nav'] as $nav_item ) {
     30        foreach( (array) $bp['bp_nav'] as $nav_item ) {
    3131                /* 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'] ) {
    3333                        $selected = ' class="current"';
    3434                } else {
    … …  
    4141                if ( $bp['current_userid'] != $bp['loggedin_userid'] ) {
    4242                        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'] ) {
    4444                                        $selected = ' class="current"';
    4545                                } else {
    … …  
    5050               
    5151                /* 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>';
    5353        }
    5454       
    … …  
    7575 */
    7676function bp_get_options_nav() {
    77         global $bp;
     77        global $bp, $is_single_group;
    7878
    7979        /* 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 ) {
    8181                if ( count( $bp['bp_options_nav'][$bp['current_component']] ) < 1 )
    8282                        return false;
    … …  
    8686                        $title = $values['name'];
    8787                        $link = $values['link'];
    88                         $id = $values['id'];
     88                        $css_id = $values['css_id'];
    8989                       
    9090                        /* 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'] ) ) {
    9292                                $selected = ' class="current"';
    9393                        } else {
    … …  
    9696                       
    9797                        /* 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>';               
    9999                }
    100100        } else {
    101                 if ( count( $bp['bp_users_nav'] ) < 1 )
     101                if ( !$bp['bp_users_nav'] )
    102102                        return false;
    103103
    … …  
    123123
    124124        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'] ) {
    126126                        $selected = ' class="current"';
    127127                } else {
    … …  
    129129                }
    130130               
    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>';
    132132        }       
    133133}
    … …  
    180180        global $bp;
    181181       
    182         if ( !is_user_logged_in() )
     182        if ( !is_user_logged_in() || is_null($bp['loggedin_userid']) || is_null($bp['current_userid']) )
    183183                return false;
    184184       
    185185        if ( $bp['loggedin_userid'] == $bp['current_userid'] )
    186186                return true;
    187        
     187
    188188        return false;
    189189}
    … …  
    231231        } else {
    232232                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";
    236236        }
    237237}
    … …  
    252252        } else {
    253253                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";
    257257        }
    258258}
    … …  
    273273        } else {
    274274                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
     281function 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
     306function bp_current_user_id() {
     307        global $bp;
     308        return $bp['current_userid'];
     309}
     310
     311function bp_user_fullname() {
     312        global $bp;
     313        echo $bp['current_fullname'];
    279314}
    280315
  • trunk/bp-core/homebase-creation/bp-core-homebase-functions.php

    r309 r359  
    2525        global $wpdb, $bp;
    2626       
    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'] ) ) { ?>
    2828                <div id="update-nag">
    2929                        <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  
    11<?php
    22
    3 if ( get_usermeta( $bp['loggedin_userid'], 'home_base' ) && !wp_verify_nonce($_POST['nonce'], 'slick_avatars') )
     3if ( $bp['loggedin_homebase_id'] && !wp_verify_nonce($_POST['nonce'], 'slick_avatars') )
    44        wp_die('Home Base already created.');
    55       
  • trunk/bp-friends.php

    r347 r359  
    5454                'table_name' => $wpdb->base_prefix . 'bp_friends',
    5555                'image_base' => get_option('siteurl') . '/wp-content/mu-plugins/bp-friends/images',
     56                'format_activity_function' => 'friends_format_activity',
    5657                'slug'           => 'friends'
    5758        );
    … …  
    7172        global $wpdb, $bp, $userdata;
    7273
    73         if ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' ) ) {
     74        if ( $wpdb->blogid == $bp['current_homebase_id'] ) {
    7475                /* Add the administration tab under the "Site Admin" tab for site administrators */
    7576                //add_submenu_page( 'wpmu-admin.php', __("Friends"), __("Friends"), 1, basename(__FILE__), "friends_settings" );
    … …  
    9192        global $bp;
    9293       
    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' );
    122105       
    123106        if ( $bp['current_component'] == $bp['friends']['slug'] ) {
    … …  
    126109                } else {
    127110                        $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'];
    129112                }
    130113        }
    131 
    132114}
    133115add_action( 'wp', 'friends_setup_nav', 2 );
    134116
    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
     119function friends_screen_my_friends() {
     120        bp_catch_uri( 'friends/index' );       
     121}
     122
     123function 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
     152function friends_screen_friend_finder() {
     153        bp_catch_uri( 'friends/friend-finder' );
     154}
     155
     156function 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
     172function 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}
     178add_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
     189function 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;
    154198                       
    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}
    201210
    202211
    … …  
    239248        for ( $i = 0; $i < count($friend_ids); $i++ ) {
    240249                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);
    242251               
    243252                if ( $display_name != ' ' ) {
    … …  
    262271        }
    263272
     273
     274function friends_get_friend_ids_for_user( $user_id ) {
     275        return BP_Friends_Friendship::get_friend_ids( $user_id );
     276}
     277
    264278/**************************************************************************
    265279 friends_search_users()
    … …  
    349363               
    350364        $friendship_id = BP_Friends_Friendship::get_friendship_ids( $initiator_userid, $only_confirmed, false, null, null, $friend_userid );
    351 
    352365        $friendship = new BP_Friends_Friendship( $friendship_id[0]->id );
    353366       
    … …  
    355368}
    356369
     370function 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
     382function 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
    357391
    358392?>
  • trunk/bp-friends/bp-friends-classes.php

    r349 r359  
    1010       
    1111        var $is_request;
     12        var $populate_friend_details;
    1213       
    1314        var $friend;
    1415       
    15         function bp_friends_friendship( $id = null, $is_request = false ) {
     16        function bp_friends_friendship( $id = null, $is_request = false, $populate_friend_details = true ) {
    1617                $this->is_request = $is_request;
    1718               
    1819                if ( $id ) {
    1920                        $this->id = $id;
     21                        $this->populate_friend_details = $populate_friend_details;
    2022                        $this->populate( $this->id );
    2123                }
    … …  
    4547                if ( !$bp['current_userid'] )
    4648                        $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                        }
    5256                }
    5357        }
    … …  
    175179        }
    176180       
    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'] ) );
    186191        }
    187192       
    … …  
    197202               
    198203                // filter the user_ids based on the search criteria.
    199                 if ( BP_XPROFILE_IS_INSTALLED ) {
     204                if ( function_exists('xprofile_install') ) {
    200205                        $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" );
    201206                } else {
    … …  
    219224               
    220225                // filter the user_ids based on the search criteria.
    221                 if ( BP_XPROFILE_IS_INSTALLED ) {
     226                if ( function_exists('xprofile_install') ) {
    222227                        $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%%'" );
    223228                } else {
    … …  
    264269                        return false;
    265270        }
     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        }
    266277}
    267278       
  • trunk/bp-friends/bp-friends-templatetags.php

    r349 r359  
    249249        global $friends_template, $bp;
    250250       
    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;
    252252}
    253253
    … …  
    255255        global $friends_template, $bp;
    256256       
    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;
    258258}
    259259
  • trunk/bp-groups.php

    r352 r359  
    9393                'table_name_members' => $wpdb->base_prefix . 'bp_groups_members',
    9494                'image_base' => get_option('siteurl') . '/wp-content/mu-plugins/bp-groups/images',
     95                'format_activity_function' => 'groups_format_activity',
    9596                'slug'           => 'groups'
    9697        );
    … …  
    115116        global $wpdb, $bp, $userdata;
    116117       
    117         if ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' ) ) {
     118        if ( $wpdb->blogid == $bp['current_homebase_id'] ) {
    118119                /* Add the administration tab under the "Site Admin" tab for site administrators */
    119120                //add_submenu_page( 'wpmu-admin.php', __("Friends"), __("Friends"), 1, basename(__FILE__), "friends_settings" );
    … …  
    137138        global $group_obj, $is_single_group;
    138139       
    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' );
    168160       
    169161        if ( $bp['current_component'] == $bp['groups']['slug'] ) {
    … …  
    174166                       
    175167                } else if ( !bp_is_home() && !$is_single_group ) {
    176                        
     168
    177169                        $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'];
    179171                       
    180172                } else if ( $is_single_group ) {
    181                        
    182173                        // We are viewing a single group, so set up the
    183174                        // group navigation menu using the $group_obj global.
    184175                       
     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                                                                       
    185182                        $bp['bp_options_title'] = bp_create_excerpt( $group_obj->name, 1 );
    186183                        $bp['bp_options_avatar'] = '<img src="' . $group_obj->avatar_thumb . '" alt="Group Avatar Thumbnail" />';
    187184                       
    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');
    198194                       
    199195                        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' );
    207197                        }
    208198                       
    209199                        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' );
    217201                        }
    218202                       
    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' );
    230205                       
    231206                        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' );
    239208                        }
    240209                }
    241210        }
    242211}
    243 add_action( 'wp', 'groups_setup_nav', 4 );
    244 
    245 
    246 /**************************************************************************
    247  groups_catch_action()
    248  
    249  Catch actions via pretty urls.
     212add_action( 'wp', 'groups_setup_nav', 2 );
     213
     214/***** Screens **********/
     215
     216function groups_screen_my_groups() {
     217        bp_catch_uri( 'groups/index' );
     218}
     219
     220function groups_screen_group_finder() {
     221        bp_catch_uri( 'groups/group-finder' ); 
     222}
     223
     224function 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
     252function 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
     299function 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
     307function 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
     316function 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
     362function 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
     371function 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
     381function 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
     402function 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
     433function 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}
     455add_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)
    250463 **************************************************************************/
    251464
    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';
     465function 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}
     471add_action( 'bp_groups_joined_group', 'groups_record_activity' );
     472add_action( 'bp_groups_created_group', 'groups_record_activity' );
     473add_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
     483function 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;           
    325509                                       
    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}
    504518
    505519/**************************************************************************
    … …  
    707721                        case '4':
    708722                                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                               
    710726                                header( "Location: " . $bp['loggedin_domain'] . $bp['groups']['slug'] . "/" . $group->slug );
    711727                               
    … …  
    731747        return $slug;
    732748}
    733 
    734 /**************************************************************************
    735  groups_is_user_admin()
    736  
    737  Check if a user is an administrator of a group.
    738 **************************************************************************/
    739749
    740750function groups_is_user_admin( $user_id, $group_id ) {
    … …  
    786796}
    787797
    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 }
    797798
    798799function groups_send_invites( $group_obj ) {
    … …  
    818819                wp_mail( $invited_user->email, __("New Group Invitation:") . $group_obj->name, $message, "From: noreply@" . $_SERVER[ 'HTTP_HOST' ]  );
    819820        }
     821}
     822
     823function 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;
    820831}
    821832
    … …  
    835846                return false;
    836847       
     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       
    837850        return true;
    838851}
     852
     853function 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
     862function 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
    839872?>
  • trunk/bp-groups/bp-groups-templatetags.php

    r349 r359  
    2020                $this->pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : 5;
    2121
    22                 if ( $bp['current_action'] == 'my-groups') {
     22                if ( $bp['current_action'] == 'my-groups' || !$bp['current_action'] ) {
    2323               
    2424                        $this->groups = groups_get_user_groups( $this->pag_page, $this->pag_num );
    … …  
    100100function bp_has_groups() {
    101101        global $groups_template, $bp;
    102         global $is_single_group;
     102        global $is_single_group, $group_obj;
    103103               
    104104        if ( !$is_single_group ) {
    105105                $groups_template = new BP_Groups_Template( $bp['current_userid'] );
    106106        } 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 );           
    108108        }
    109109       
  • trunk/bp-messages.php

    r347 r359  
    9494       
    9595        $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'
    103104        );
    104105}
    … …  
    117118        global $wpdb, $bp, $userdata;
    118119
    119         if ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' ) ) {   
     120        if ( $wpdb->blogid == $bp['current_homebase_id'] ) {   
    120121                //Add the administration tab under the "Site Admin" tab for site administrators
    121122                //add_submenu_page ( 'wpmu-admin.php', __('Messages'), __('Messages'), 1, basename(__FILE__), "messages_settings" );
    … …  
    136137function messages_setup_nav() {
    137138        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
    166140        $inbox_count = BP_Messages_Thread::get_inbox_count();
    167141        $inbox_display = ( $inbox_count ) ? ' style="display:inline;"' : ' style="display:none;"';
    168142        $count_indicator = '&nbsp; <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 );
    169155
    170156        if ( $bp['current_component'] == $bp['messages']['slug'] ) {
    … …  
    173159                } else {
    174160                        $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'];
    176162                }
    177163        }
    … …  
    179165add_action( 'wp', 'messages_setup_nav', 2 );
    180166
    181 
    182 /**************************************************************************
    183  messages_catch_action()
     167/***** Screens **********/
     168
     169function messages_screen_inbox() {
     170        bp_catch_uri( 'messages/index' );       
     171}
     172
     173function messages_screen_sentbox() {
     174        bp_catch_uri( 'messages/sentbox' );
     175}
     176
     177function messages_screen_compose() {
     178        bp_catch_uri( 'messages/compose' );
     179}
     180
     181function 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
     225function 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}
     245add_action( 'wp', 'messages_action_view_message', 3 );
     246
     247
     248function 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}
     277add_action( 'wp', 'messages_action_delete_message', 3 );
     278
     279
     280function 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}
     308add_action( 'wp', 'messages_action_bulk_delete', 3 );
     309
     310
     311/**************************************************************************
     312 messages_record_activity()
    184313 
    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
     318function 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
     332function 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}
    322341
    323342/**************************************************************************
    … …  
    583602                                        $message = __('Message sent successfully!') . ' <a href="' . $bp['loggedin_domain'] . $bp['messages']['slug'] . '/view/' . $pmessage->thread_id . '">' . __('View Message') . '</a> &raquo;';
    584603                                        $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 ) );
    585606                       
    586607                                        if ( $from_ajax ) {
    … …  
    677698                        $type = 'error';
    678699                }
     700               
     701                do_action( 'bp_messages_message_deleted' );
     702               
    679703        }
    680704       
    … …  
    684708
    685709
     710/**************************************************************************
     711 messages_view_thread()
     712 
     713 Displays a message thread.
     714 **************************************************************************/
     715
    686716function messages_view_thread( $thread_id ) {
    687         global $bp_messages_image_base, $userdata;
     717        global $userdata;
    688718
    689719        $thread = new BP_Messages_Thread( $thread_id, true );
  • trunk/bp-messages/bp-messages-templatetags.php

    r309 r359  
    174174function bp_message_thread_avatar() {
    175175        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);
    178177}
    179178
    180179function bp_message_thread_view() {
    181180        global $thread_id;
    182        
     181
    183182        messages_view_thread($thread_id);
    184183}
  • trunk/bp-wire.php

    r352 r359  
    5858        global $bp;
    5959
    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' );
    6263
    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' );
    8066       
    8167        if ( $bp['current_component'] == $bp['wire']['slug'] ) {
    … …  
    8470                } else {
    8571                        $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'];
    8773                }
    8874        }
    89 
    9075}
    9176add_action( 'wp', 'bp_wire_setup_nav', 2 );
    9277
     78/***** Screens **********/
    9379
    94 /**************************************************************************
    95  bp_wire_catch_action()
    96  
    97  Catch actions via pretty urls.
    98  **************************************************************************/
     80function bp_wire_screen_latest() {
     81        bp_catch_uri( 'wire/latest' ); 
     82}
    9983
    100 function bp_wire_catch_action() {
    101         global $bp, $current_blog;
     84/***** Actions **********/
     85
     86function bp_wire_action_post() {
     87        global $bp;
    10288       
    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                                         $bp['message'] = __('Wire message successfully posted.');
    108                                         $bp['message_type'] = 'success';
     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';
    10995
    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}
     108add_action( 'wp', 'bp_wire_action_post', 3 );
    127109
    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                 }
     110function 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' );
    144130        }
    145131}
    146 add_action( 'wp', 'bp_wire_catch_action', 3 );
     132add_action( 'wp', 'bp_wire_action_delete', 3 );
    147133
    148134
    … …  
    169155        do_action( 'bp_wire_post_posted', $wire_post->id, $wire_post->item_id, $wire_post->user_id );
    170156       
    171         return true;
     157        return $wire_post->id;
    172158}
     159add_action( 'wp', 'bp_wire_action_delete', 3 );
    173160
    174161function bp_wire_delete_post( $wire_post_id, $table_name = null ) {
  • trunk/bp-wire/bp-wire-templatetags.php

    r352 r359  
    195195        global $bp;
    196196       
     197        if ( $bp['current_item'] == '')
     198                $uri = $bp['current_action'];
     199        else
     200                $uri = $bp['current_item'];
     201       
    197202        if ( $bp['current_component'] == 'wire' || $bp['current_component'] == 'profile' ) {
    198203                echo $bp['current_domain'] . $bp['wire']['slug'] . '/post/';
    199204        } 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/';
    201206        }
    202207}
    … …  
    224229        global $wire_posts_template, $bp;
    225230
     231        if ( $bp['current_item'] == '')
     232                $uri = $bp['current_action'];
     233        else
     234                $uri = $bp['current_item'];
     235               
    226236        if ( ( $wire_posts_template->wire_post->user_id == $bp['loggedin_userid'] ) || $bp['is_item_admin'] ) {
    227237                if ( $bp['current_component'] == 'wire' || $bp['current_component'] == 'profile' ) {
    228238                        echo '<a href="' . $bp['current_domain'] . $bp['wire']['slug'] . '/delete/' . $wire_posts_template->wire_post->id . '">[' . __('Delete') . ']</a>';
    229239                } 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>';
    231241                }
    232242        }
    … …  
    235245function bp_wire_see_all_link() {
    236246        global $bp;
     247       
     248        if ( $bp['current_item'] == '')
     249                $uri = $bp['current_action'];
     250        else
     251                $uri = $bp['current_item'];
    237252       
    238253        if ( $bp['current_component'] == 'wire' || $bp['current_component'] == 'profile') {
    239254                echo $bp['current_domain'] . $bp['wire']['slug'];
    240255        } 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';
    242257        } else {
    243258                echo $bp['current_domain'] . $bp[$bp['current_component']]['slug'] . '/wire';
  • trunk/bp-xprofile.php

    r352 r359  
    113113                'table_name_fields' => $wpdb->base_prefix . 'bp_xprofile_fields',
    114114                'table_name_data'       => $wpdb->base_prefix . 'bp_xprofile_data',
     115                'format_activity_function' => 'xprofile_format_activity',
    115116                'image_base'            => get_option('siteurl') . '/wp-content/mu-plugins/bp-xprofile/images',
    116117                'slug'                          => 'profile'
    … …  
    119120        if ( function_exists('bp_wire_install') )
    120121                $bp['profile']['table_name_wire'] = $wpdb->base_prefix . 'bp_xprofile_wire';
     122       
     123       
    121124}
    122125add_action( 'wp', 'xprofile_setup_globals', 1 );       
    … …  
    134137        global $wpdb, $bp, $groups, $userdata;
    135138       
    136         if ( $wpdb->blogid == get_usermeta( $bp['current_userid'], 'home_base' ) ) {
     139        if ( $wpdb->blogid == $bp['current_homebase_id'] ) {
    137140                add_menu_page( __('Profile'), __('Profile'), 1, basename(__FILE__), 'bp_core_avatar_admin' );
    138141                add_submenu_page( basename(__FILE__), __('Profile &rsaquo; Avatar'), __('Avatar'), 1, basename(__FILE__), 'xprofile_avatar_admin' );           
    139                 add_options_page( __('Profile'), __('Profile'), 1, basename(__FILE__), 'xprofile_add_settings' );               
    140142               
    141143                $groups = BP_XProfile_Group::get_all();
    … …  
    172174        global $bp;
    173175       
    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
    201187        if ( $bp['current_component'] == $bp['profile']['slug'] ) {
    202188                if ( bp_is_home() ) {
    … …  
    204190                } else {
    205191                        $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'];
    207193                }
    208194        }
    209        
    210195}
    211196add_action( 'wp', 'xprofile_setup_nav', 2 );
    212197
    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
     200function xprofile_screen_display_profile() {
     201        bp_catch_uri( 'profile/index' );
     202}
     203
     204function xprofile_screen_edit_profile() {
     205        if ( bp_is_home() )
     206                bp_catch_uri( 'profile/edit' );
     207}
     208
     209function 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
     218function 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}
     230add_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
     240function 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}
     248add_action( 'bp_xprofile_new_wire_post', 'xprofile_record_activity' );
     249add_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
     258function 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}
    243289
    244290/**************************************************************************
    … …  
    289335                                                        $field->message = sprintf( __('%s cannot be left blank.'), $field->name );
    290336                                                        $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) ) ) {
    293338                                                        // data removed, so delete the field data from the DB.                                                         
    294339                                                        $profile_data = new BP_Xprofile_ProfileData( $group->fields[$j]->id );
    295340                                                        $profile_data->delete();
    296341                                                        $field->data->value = null;
    297                                                 }
    298                                                 else {
     342                                                } else {
    299343                                                        // Field validates, save.
    300344                                                        $profile_data = new BP_Xprofile_ProfileData;
    … …  
    303347                                                        $profile_data->last_updated = time();
    304348
    305                                                         if($post_field_string != null) {
     349                                                        if ( $post_field_string != null ) {
    306350                                                                $date_value = $_POST['field_' . $group->fields[$j]->id . '_day'] .
    307351                                                                                      $_POST['field_' . $group->fields[$j]->id . '_month'] .
    … …  
    309353
    310354                                                                $profile_data->value = strtotime($date_value);
    311                                                         }
    312                                                         else {
     355                                                        } else {
    313356                                                                if ( is_array($current_field) )
    314357                                                                        $current_field = serialize($current_field);
    … …  
    317360                                                        }
    318361
    319                                                         if(!$profile_data->save()) {
     362                                                        if( !$profile_data->save() ) {
    320363                                                                $field->message = __('There was a problem saving changes to this field, please try again.');
    321                                                         }
    322                                                         else {
     364                                                        } else {
    323365                                                                $field->data->value = $profile_data->value;
    324366                                                        }
    … …  
    342384                                                $message .= $errors[$i];
    343385                                        }
    344                                 }
    345                                 else if ( !$errors && isset($_POST['save'] ) ) {
     386                                } else if ( !$errors && isset($_POST['save'] ) ) {
    346387                                        $type = 'success';
    347388                                        $message = __('Changes saved.');
    348389                                       
     390                                        do_action( 'bp_xprofile_updated_profile', array( 'item_id' => $group->id, 'component_name' => 'profile', 'component_action' => 'updated_profile', 'is_private' => 0 ) );
    349391                                        update_usermeta( $bp['loggedin_userid'], 'profile_last_updated', date("Y-m-d H:i:s") );
    350392                                }
  • trunk/bp-xprofile/bp-xprofile-classes.php

    r343 r359  
    10841084                        $user_id = $bp['current_userid'];
    10851085               
     1086                if ( !$bp['profile'] )
     1087                        xprofile_setup_globals();
     1088               
    10861089                $field_sql = '';
    10871090
    … …  
    11001103
    11011104                $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
    11031106                if ( !$values = $wpdb->get_results($sql) )
    11041107                        return false;
    … …  
    11451148                global $wpdb, $bp;
    11461149               
    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']);               
    11491162        }
    11501163}
  • trunk/bp-xprofile/bp-xprofile-templatetags.php

    r343 r359  
    157157}
    158158
     159function bp_field_css_class() {
     160        global $profile_template;
     161       
     162        if ( $profile_template->current_field % 2 )
     163                echo ' class="alt"';
     164}
     165
    159166function bp_field_has_data() {
    160167        global $profile_template;
    … …  
    230237}
    231238
    232 function bp_user_fullname($user_id = false, $echo = true) {
     239function bp_fetch_user_fullname( $user_id = false, $echo = true ) {
    233240        global $bp;
    234241       
    … …  
    239246       
    240247        if ( $echo )
    241                 echo ucfirst($data['First Name']) . ' ' . ucfirst($data['Last Name']); 
     248                echo ucfirst($data['First Name']) . ' ' . ucfirst($data['Last Name']);
    242249        else
    243                 return ucfirst($data['First Name']) . ' ' . ucfirst($data['Last Name']);
     250                return ucfirst($data['First Name']) . ' ' . ucfirst($data['Last Name']);               
    244251}
    245252
Note: See TracChangeset for help on using the changeset viewer.