Skip to:
Content

BuddyPress.org

Changeset 439


Ignore:
Timestamp:
10/28/2008 02:49:35 PM (17 years ago)
Author:
apeatling
Message:

Added global notification system for BuddyPress components and added a "Notifications" menu to the logged in admin bar.

Cleaned up the design of the admin bar menus.

Location:
trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r398 r439  
    118118add_action( '_admin_menu', 'bp_activity_setup_globals', 1 );
    119119
    120 /**************************************************************************
    121  bp_activity_add_admin_menu()
    122  
    123  Creates the administration interface menus and checks to see if the DB
    124  tables are set up.
    125  **************************************************************************/
    126 
    127 function bp_activity_add_admin_menu() {
    128     global $wpdb, $bp, $userdata;
    129 
    130     if ( $wpdb->blogid == $bp['current_homebase_id'] ) {
    131         /* Add the administration tab under the "Site Admin" tab for site administrators */
    132         //add_submenu_page( 'wpmu-admin.php', __("Activity"), __("Activity"), 1, basename(__FILE__), "bp_activity_settings" );
    133     }
    134 }
    135 add_action( 'admin_menu', 'bp_activity_add_admin_menu' );
    136120
    137121/**************************************************************************
  • trunk/bp-blogs.php

    r429 r439  
    6666}
    6767
    68 /**************************************************************************
    69  bp_blogs_add_admin_menu()
    70  
    71  Creates the administration interface menus and checks to see if the DB
    72  tables are set up.
    73  **************************************************************************/
    74 
    75 function bp_blogs_add_admin_menu() {   
     68
     69function bp_blogs_check_installed() {   
    7670    global $wpdb, $bp, $userdata;
    77 
    78     if ( $wpdb->blogid == $bp['current_homebase_id'] ) {
    79         add_menu_page( __("Blogs", 'buddypress'), __("Blogs", 'buddypress'), 10, 'bp-blogs/admin-tabs/bp-blogs-tab.php' );
    80         add_submenu_page( 'bp-blogs/admin-tabs/bp-blogs-tab.php', __("My Blogs", 'buddypress'), __("My Blogs", 'buddypress'), 10, 'bp-blogs/admin-tabs/bp-blogs-tab.php' );
    81         add_submenu_page( 'bp-blogs/admin-tabs/bp-blogs-tab.php', __('Recent Posts', 'buddypress'), __('Recent Posts', 'buddypress'), 10, 'bp-blogs/admin-tabs/bp-blogs-posts-tab.php' );       
    82         add_submenu_page( 'bp-blogs/admin-tabs/bp-blogs-tab.php', __('Recent Comments', 'buddypress'), __('Recent Comments', 'buddypress'), 10, 'bp-blogs/admin-tabs/bp-blogs-comments-tab.php' );     
    83     }
    84 
    85     /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
    86     if ( ( $wpdb->get_var("show tables like '%" . $bp['blogs']['table_name'] . "%'") == false ) || ( get_site_option('bp-blogs-version') < BP_BLOGS_VERSION )  )
    87         bp_blogs_install(BP_BLOGS_VERSION);
    88 }
    89 add_action( 'admin_menu', 'bp_blogs_add_admin_menu' );
     71   
     72    if ( is_site_admin() ) {
     73        /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
     74        if ( ( $wpdb->get_var("show tables like '%" . $bp['blogs']['table_name'] . "%'") == false ) || ( get_site_option('bp-blogs-version') < BP_BLOGS_VERSION )  )
     75            bp_blogs_install(BP_BLOGS_VERSION);
     76    }
     77}
     78add_action( 'admin_menu', 'bp_blogs_check_installed' );
    9079
    9180
  • trunk/bp-core.php

    r436 r439  
    22
    33/* Define the current version number for checking if DB tables are up to date. */
    4 define( 'BP_CORE_VERSION', '0.2.6.1' );
     4define( 'BP_CORE_VERSION', '0.2.7' );
    55
    66/* Define the slug for member pages and the members directory (e.g. domain.com/[members] ) */
     
    3838/* AJAX functionality */
    3939require_once( 'bp-core/bp-core-ajax.php' );
     40
     41/* Functions to handle the calculations and display of notifications for a user */
     42require_once( 'bp-core/bp-core-notifications.php' );
    4043
    4144/* Functions to handle and display the member and blog directory pages */
     
    6467 */
    6568function bp_core_setup_globals() {
    66     global $bp;
     69    global $bp, $wpdb;
    6770    global $current_user, $current_component, $current_action, $current_blog;
    6871    global $current_userid;
     
    132135    $bp['core'] = array(
    133136        'image_base' => site_url() . '/wp-content/mu-plugins/bp-core/images',
     137        'table_name_notifications' => $wpdb->base_prefix . 'bp_notifications'
    134138    );
    135139   
     
    139143add_action( 'wp', 'bp_core_setup_globals', 1 );
    140144add_action( '_admin_menu', 'bp_core_setup_globals', 1 ); // must be _admin_menu hook.
     145
     146
     147function bp_core_install() {
     148    global $wpdb, $bp;
     149   
     150    $sql[] = "CREATE TABLE ". $bp['core']['table_name_notifications'] ." (
     151                id int(11) NOT NULL AUTO_INCREMENT,
     152                user_id int(11) NOT NULL,
     153                item_id int(11) NOT NULL,
     154                component_name varchar(75) NOT NULL,
     155                component_action varchar(75) NOT NULL,
     156                date_notified datetime NOT NULL,
     157                is_new tinyint(1) NOT NULL,
     158                PRIMARY KEY id (id),
     159                KEY item_id (item_id),
     160                KEY user_id (user_id),
     161                KEY is_new (is_new),
     162                KEY component_name (component_name),
     163                KEY component_action (component_action)
     164               );";
     165
     166    require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
     167    dbDelta($sql);
     168   
     169    add_site_option( 'bp-core-version', BP_CORE_VERSION );
     170}
     171
     172
     173function bp_core_check_installed() {
     174    global $wpdb, $bp;
     175
     176    if ( is_site_admin() ) {
     177        /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
     178        if ( ( $wpdb->get_var("show tables like '%" . $bp['core']['table_name_notifications'] . "%'") == false ) || ( get_site_option('bp-core-version') < BP_CORE_VERSION )  )
     179            bp_core_install();
     180    }
     181}
     182add_action( 'admin_menu', 'bp_core_check_installed' );
     183
    141184
    142185function bp_core_setup_nav() {
  • trunk/bp-core/bp-core-adminbar.php

    r394 r439  
    1818       
    1919        /* Loop through each navigation item */
     20        $counter = 0;
    2021        foreach( $bp['bp_nav'] as $nav_item ) {
    21             echo '<li>';
    22             echo '<a id="' . $nav_item['id'] . '" href="' . $nav_item['link'] . '">' . $nav_item['name'] . '</a>';
     22            $alt = ( $counter % 2 == 0 ) ? ' class="alt"' : '';
     23            echo '<li' . $alt . '>';
     24            echo '<a id="' . $nav_item['css_id'] . '" href="' . $nav_item['link'] . '">' . $nav_item['name'] . '</a>';
    2325
    24             if ( is_array( $bp['bp_options_nav'][$nav_item['id']] ) ) {
     26            if ( is_array( $bp['bp_options_nav'][$nav_item['css_id']] ) ) {
    2527                echo '<ul>';
    26                 foreach( $bp['bp_options_nav'][$nav_item['id']] as $subnav_item ) {
    27                     echo '<li><a id="' . $subnav_item['id'] . '" href="' . $subnav_item['link'] . '">' . $subnav_item['name'] . '</a></li>';               
     28                $sub_counter = 0;
     29                foreach( $bp['bp_options_nav'][$nav_item['css_id']] as $subnav_item ) {
     30                    $alt = ( $sub_counter % 2 == 0 ) ? ' class="alt"' : '';
     31                    echo '<li' . $alt . '><a id="' . $subnav_item['css_id'] . '" href="' . $subnav_item['link'] . '">' . $subnav_item['name'] . '</a></li>';               
     32                    $sub_counter++;
    2833                }
    2934                echo '</ul>';
     
    3136           
    3237            echo '</li>';
     38            $counter++;
    3339        }
    3440        echo '<li><a id="logout" href="' . site_url() . '/wp-login.php?action=logout">' . __('Log Out', 'buddypress') . '</a></li>';
     
    4450            _e('My Blogs', 'buddypress');
    4551            echo '</a>';
    46 
     52           
    4753            echo '<ul>';           
    4854            if ( is_array( $blogs['blogs'] ) ) {
    49 
     55               
     56                $counter = 0;
    5057                foreach( $blogs['blogs'] as $blog ) {
    51                     echo '<li>';
     58                    $alt = ( $counter % 2 == 0 ) ? ' class="alt"' : '';
     59                    echo '<li' . $alt . '>';
    5260                    echo '<div class="admin-bar-clear"><a href="' . $blog['siteurl'] . '">' . $blog['title'] . '</a>';
    5361                    echo '</div>';
    5462                   
    5563                    echo '<ul>';
    56                     echo '<li><a href="' . $blog['siteurl']  . '/wp-admin/">' . __('Dashboard', 'buddypress') . '</a></li>';
     64                    echo '<li class="alt"><a href="' . $blog['siteurl']  . '/wp-admin/">' . __('Dashboard', 'buddypress') . '</a></li>';
    5765                    echo '<li><a href="' . $blog['siteurl']  . '/wp-admin/post-new.php">' . __('New Post', 'buddypress') . '</a></li>';
    58                     echo '<li><a href="' . $blog['siteurl']  . '/wp-admin/post-new.php">' . __('Manage Posts', 'buddypress') . '</a></li>';
     66                    echo '<li class="alt"><a href="' . $blog['siteurl']  . '/wp-admin/post-new.php">' . __('Manage Posts', 'buddypress') . '</a></li>';
    5967                    echo '<li><a href="' . $blog['siteurl']  . '/wp-admin/themes.php">' . __('Switch Theme', 'buddypress') . '</a></li>';                   
    60                     echo '<li><a href="' . $blog['siteurl']  . '/wp-admin/edit-comments.php">' . __('Manage Comments', 'buddypress') . '</a></li>';                 
     68                    echo '<li class="alt"><a href="' . $blog['siteurl']  . '/wp-admin/edit-comments.php">' . __('Manage Comments', 'buddypress') . '</a></li>';                 
    6169                    echo '</ul>';
    6270                   
    6371                    echo '</li>';
     72                    $counter++;
    6473                }
    6574            } else {
     
    7180            echo '</li>';
    7281        }
     82       
     83        /* Show notifications for this user */
     84        echo '<li id="notifications_menu"><a href="' . $bp['loggedin_domain'] . '">';
     85        _e('Notifications', 'buddypress');
     86       
     87        if ( $notifications = bp_core_get_notifications_for_user( $bp['loggedin_userid']) ) { ?>
     88            <span><?php echo count($notifications) ?></span>
     89        <?php
     90        }
     91        echo '</a>';
     92        echo '<ul>';
     93        if ( $notifications ) { ?>
     94            <?php $counter = 0; ?>
     95            <?php for ( $i = 0; $i < count($notifications); $i++ ) { ?>
     96                <?php $alt = ( $counter % 2 == 0 ) ? ' class="alt"' : ''; ?>
     97                <li<?php echo $alt ?>><?php echo $notifications[$i] ?></li>
     98                <?php $counter++; ?>
     99            <?php } ?>
     100        <?php } else { ?>
     101            <li><a href="<?php echo $bp['loggedin_domain'] ?>"><?php _e( 'No new notifications.', 'buddypress' ); ?></a></li>
     102        <?php
     103        }
     104        echo '</ul>';
     105        echo '</li>';
    73106       
    74107        if ( $current_blog->blog_id > 1 ) {
  • trunk/bp-core/bp-core-catchuri.php

    r436 r439  
    154154
    155155    if ( !file_exists( TEMPLATEPATH . "/header.php" ) || !file_exists( TEMPLATEPATH . "/footer.php" ) )
    156         wp_die( 'Please make sure your BuddyPress enabled theme includes a header.php and footer.php file.');
    157 
     156        wp_redirect( $bp['root_domain'] );
     157       
    158158    do_action( 'get_header' );
    159159    load_template( TEMPLATEPATH . "/header.php" );
     
    196196}
    197197
     198// This function will remove home bases and redirect users to their new member page.
     199function bp_core_homebase_redirect() {
     200    global $current_user, $current_blog;
     201   
     202    if ( get_usermeta( $current_user->id, 'home_base' ) == $current_blog->blog_id ) {
     203        if ( delete_blog( $current_blog->blog_id ) ) {
     204            delete_usermeta( $current_user->id, 'home_base' );
     205            header('Location: ' . site_url() . MEMBERS_SLUG . '/' . $current_user->user_login . '/' );
     206        }
     207    }
     208}
     209add_action( 'wp', 'bp_core_set_uri_globals', 0 );
     210
     211
    198212function bp_core_force_buddypress_theme() {
    199213    global $current_component, $current_action;
  • trunk/bp-core/bp-core-classes.php

    r436 r439  
    180180}
    181181
     182
     183/**
     184 * BP_Core_Notification class can be used by any component.
     185 * It will handle the fetching, saving and deleting of a user notification.
     186 *
     187 * @package BuddyPress Core
     188 */
     189
     190class BP_Core_Notification {
     191    var $id;
     192    var $user_id;
     193    var $component_name;
     194    var $component_action;
     195    var $date_notified;
     196    var $is_new;
     197   
     198    function bp_core_notification( $id = false ) {
     199        if ( $id ) {
     200            $this->id = $id;
     201            $this->populate();
     202        }
     203    }
     204   
     205    function populate() {
     206        global $wpdb, $bp;
     207       
     208        if ( $notification = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $bp['core']['table_name_notifications'] . " WHERE id = %d", $this->id ) ) ) {
     209            $this->user_id = $notification->user_id;
     210            $this->component_name = $notification->component_name;
     211            $this->component_action = $notification->component_action;
     212            $this->date_notified = $notification->date_notified;
     213            $this->is_new = $notification->is_new;
     214        }
     215    }   
     216   
     217    function save() {
     218        global $wpdb, $bp;
     219       
     220        if ( $this->id ) {
     221            // Update
     222            $sql = $wpdb->prepare( "UPDATE " . $bp['core']['table_name_notifications'] . " SET item_id = %d, user_id = %d, component_name = %s, component_action = %d, date_notified = FROM_UNIXTIME(%d), is_new = %d ) WHERE id = %d", $this->item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new, $this->id );
     223        } else {
     224            // Save
     225            $sql = $wpdb->prepare( "INSERT INTO " . $bp['core']['table_name_notifications'] . " ( item_id, user_id, component_name, component_action, date_notified, is_new ) VALUES ( %d, %d, %s, %s, FROM_UNIXTIME(%d), %d )", $this->item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new );
     226        }
     227
     228        return $wpdb->query( $sql );
     229    }
     230
     231    /* Static functions */
     232   
     233    function delete( $id ) {
     234        global $wpdb, $bp;
     235       
     236       
     237    }
     238   
     239    function check_access( $user_id, $notification_id ) {
     240        global $wpdb, $bp;
     241       
     242        return $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM " . $bp['core']['table_name_notifications'] . " WHERE id = %d AND user_id = %d", $notification_id, $user_id ) );
     243    }
     244   
     245    function total_notification_count( $user_id ) {
     246       
     247    }
     248   
     249    function get_all_for_user( $user_id ) {
     250        global $wpdb, $bp;
     251       
     252        return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $bp['core']['table_name_notifications'] . " WHERE user_id = %d AND is_new = 1", $user_id ) );
     253    }
     254   
     255    function delete_for_user_by_type( $user_id, $component_name, $component_action ) {
     256        global $wpdb, $bp;
     257       
     258        return $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['core']['table_name_notifications'] . " WHERE user_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) );
     259    }
     260   
     261   
     262}   
     263
     264
    182265?>
  • trunk/bp-core/css/admin-bar.css

    r309 r439  
    4848        #wp-admin-bar ul li { /* all list items */
    4949            padding: 0;
    50             height: 30px;
     50            /*height: 30px;*/
    5151            float: left;
    5252        }
     
    7676        margin: 0;
    7777        border: none;
    78         background: #eee !important;
     78        background: #f4f4f4 !important;
     79        border-left: 1px solid #ccc;
     80        border-right: 1px solid #ccc;
    7981    }
    80    
     82        #wp-admin-bar ul li ul li.alt {
     83            background: #fafafa !important;
     84        }
     85       
     86        #wp-admin-bar ul li ul li:last-child {
     87            border-bottom: 1px solid #ccc;
     88            -moz-border-radius-bottomleft: 4px;
     89            -khtml-border-bottom-left-radius: 4px;
     90            -webkit-border-bottom-left-radius: 4px;
     91            border-bottom-left-radius: 4px;
     92            -moz-border-radius-bottomright: 4px;
     93            -khtml-border-bottom-right-radius: 4px;
     94            -webkit-border-bottom-right-radius: 4px;
     95            border-bottom-right-radius: 4px;
     96        }
     97       
    8198    #wp-admin-bar ul li ul a {
    8299        color: #666 !important;
     
    96113
    97114#wp-admin-bar ul li ul ul {
    98     margin: -28px 0 0 185px;
     115    margin: -28px 0 0 183px;
    99116}
    100117
     
    109126#wp-admin-bar ul.main-nav li ul li:hover {
    110127    background: #555;
     128}
     129
     130#wp-admin-bar ul li ul li ul li:first-child {
     131    border-top: 1px solid #ccc;
     132    -moz-border-radius-topright: 4px;
     133    -khtml-border-top-right-radius: 4px;
     134    -webkit-border-top-right-radius: 4px;
     135    border-top-right-radius: 4px;
    111136}
    112137
     
    137162}
    138163
    139 
     164#wp-admin-bar ul li#notifications_menu a span {
     165    background: #fff;
     166    padding: 0 6px;
     167    color: #555;
     168    font-weight: bold !important;
     169    font-size: 0.8em !important;
     170    -moz-border-radius: 2px;
     171    -khtml-border-radius: 2px;
     172    -webkit-border-radius: 2px;
     173    margin-left: 2px;
     174}
  • trunk/bp-friends.php

    r398 r439  
    1919 **************************************************************************/
    2020
    21 function friends_install( $version ) {
     21function friends_install() {
    2222    global $wpdb, $bp;
    2323   
     
    3737    dbDelta($sql);
    3838   
    39     add_site_option( 'bp-friends-version', $version );
     39    add_site_option( 'bp-friends-version', BP_FRIENDS_VERSION );
    4040}
    4141   
     
    6161add_action( '_admin_menu', 'friends_setup_globals', 1 );
    6262
    63 
    64 /**************************************************************************
    65  friends_add_admin_menu()
    66  
    67  Creates the administration interface menus and checks to see if the DB
    68  tables are set up.
    69  **************************************************************************/
    70 
    71 function friends_add_admin_menu() {
    72     global $wpdb, $bp, $userdata;
    73 
    74     if ( $wpdb->blogid == $bp['current_homebase_id'] ) {
    75         /* Add the administration tab under the "Site Admin" tab for site administrators */
    76         //add_submenu_page( 'wpmu-admin.php', __("Friends"), __("Friends"), 1, basename(__FILE__), "friends_settings" );
    77     }
    78 
    79     /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
    80     if ( ( $wpdb->get_var("show tables like '%" . $bp['friends']['table_name'] . "%'") == false ) || ( get_site_option('bp-friends-version') < BP_FRIENDS_VERSION )  )
    81         friends_install(BP_FRIENDS_VERSION);
    82 }
    83 add_action( 'admin_menu', 'friends_add_admin_menu' );
     63function friends_check_installed() {   
     64    global $wpdb, $bp;
     65
     66    if ( is_site_admin() ) {
     67        /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
     68        if ( ( $wpdb->get_var("show tables like '%" . $bp['friends']['table_name'] . "%'") == false ) || ( get_site_option('bp-friends-version') < BP_FRIENDS_VERSION )  )
     69            friends_install();
     70    }
     71}
     72add_action( 'admin_menu', 'friends_check_installed' );
    8473
    8574/**************************************************************************
     
    10291    bp_core_add_subnav_item( $bp['friends']['slug'], 'requests', __('Requests', 'buddypress'), $friends_link, 'friends_screen_requests' );
    10392    bp_core_add_subnav_item( $bp['friends']['slug'], 'friend-finder', __('Friend Finder', 'buddypress'), $friends_link, 'friends_screen_friend_finder' );
    104     bp_core_add_subnav_item( $bp['friends']['slug'], 'invite-friend', __('Invite Friends', 'buddypress'), $friends_link, 'friends_screen_invite_friends' );
     93    //bp_core_add_subnav_item( $bp['friends']['slug'], 'invite-friend', __('Invite Friends', 'buddypress'), $friends_link, 'friends_screen_invite_friends' );
    10594   
    10695    if ( $bp['current_component'] == $bp['friends']['slug'] ) {
     
    118107
    119108function friends_screen_my_friends() {
     109    global $bp;
     110   
     111    // Remove any notifications of new friend requests as we are viewing the
     112    // friend request page
     113    bp_core_delete_notifications_for_user_by_type( $bp['loggedin_userid'], 'friends', 'friendship_accepted' );
     114   
    120115    bp_catch_uri( 'friends/index' );   
    121116}
     
    124119    global $bp;
    125120   
     121    // Remove any notifications of new friend requests as we are viewing the
     122    // friend request page
     123    bp_core_delete_notifications_for_user_by_type( $bp['loggedin_userid'], 'friends', 'friendship_request' );
     124       
    126125    if ( isset($bp['action_variables']) && in_array( 'accept', $bp['action_variables'] ) && is_numeric($bp['action_variables'][1]) ) {
    127126       
     
    209208}
    210209
     210function friends_format_notifications( $action, $item_id, $total_items ) {
     211    global $bp;
     212   
     213    switch ( $action ) {
     214        case 'friendship_accepted':
     215            if ( (int)$total_items > 1 ) {
     216                return '<a href="' . $bp['loggedin_domain'] . $bp['friends']['slug'] . '" title="' . __( 'My Friends', 'buddypress' ) . '">' . sprintf( __('%d friends accepted your friendship requests'), (int)$total_items ) . '</a>';       
     217            } else {
     218                $user_fullname = bp_core_global_user_fullname( $item_id );
     219                $user_url = bp_core_get_userurl( $item_id );
     220                return '<a href="' . $user_url . '" title="' . $user_fullname .'\'s profile">' . sprintf( __('%s accepted your friendship request'), $user_fullname ) . '</a>';
     221            }   
     222        break;
     223       
     224        case 'friendship_request':
     225            if ( (int)$total_items > 1 ) {
     226                return '<a href="' . $bp['loggedin_domain'] . $bp['friends']['slug'] . '/requests" title="' . __( 'Friendship requests', 'buddypress' ) . '">' . sprintf( __('You have %d pending friendship requests'), (int)$total_items ) . '</a>';     
     227            } else {
     228                $user_fullname = bp_core_global_user_fullname( $item_id );
     229                $user_url = bp_core_get_userurl( $item_id );
     230                return '<a href="' . $bp['loggedin_domain'] . $bp['friends']['slug'] . '/requests" title="' . __( 'Friendship requests', 'buddypress' ) . '">' . sprintf( __('You have a friendship request from %s'), $user_fullname ) . '</a>';
     231            }   
     232        break;
     233    }
     234    if ( $action == 'friendship_accepted') {
     235        if ( (int)$total_items > 1 ) {
     236            return '<a href="' . $bp['loggedin_domain'] . $bp['friends']['slug'] . '" title="' . __( 'My Friends', 'buddypress' ) . '">' . sprintf( __('%d friends accepted your friendship requests'), (int)$total_items ) . '</a>';       
     237        } else {
     238            $user_fullname = bp_core_global_user_fullname( $item_id );
     239            $user_url = bp_core_get_userurl( $item_id );
     240            return '<a href="' . $user_url . '" title="' . $user_fullname .'\'s profile">' . sprintf( __('%s accepted your friendship request'), $user_fullname ) . '</a>';
     241        }
     242    }
     243   
     244    return false;
     245}
    211246
    212247/**************************************************************************
     
    373408    if ( BP_Friends_Friendship::accept( $friendship_id ) ) {
    374409        friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id );
     410        bp_core_add_notification( $friendship->friend_user_id, $friendship->initiator_user_id, 'friends', 'friendship_accepted' );
    375411       
    376412        do_action( 'bp_friends_friendship_accepted', array( 'item_id' => $friendship_id, 'component_name' => 'friends', 'component_action' => 'friendship_accepted', 'is_private' => 0, 'dual_record' => true ) );
  • trunk/bp-friends/bp-friends-ajax.php

    r436 r439  
    4242                    <span class="activity"><?php echo $friend->last_active ?></span>
    4343                <?php } ?>
     44                <div class="action">
     45                    <?php bp_add_friend_button( $friend->id ) ?>
     46                </div>
    4447            </li>
    4548            <?php   
     
    9598                        <span class="activity"><?php echo $user->last_active ?></span>
    9699                    <?php } ?>
    97                     <?php bp_add_friend_button( $user->id ) ?>
     100                    <div class="action">
     101                        <?php bp_add_friend_button( $user->id ) ?>
     102                    </div>
    98103                </li>
    99104            <?php   
  • trunk/bp-friends/bp-friends-classes.php

    r431 r439  
    2727        global $wpdb, $bp, $creds;
    2828       
    29         $sql = $wpdb->prepare( "SELECT * FROM " . $bp['friends']['table_name'] . " WHERE id = %d", $this->id );
    30         $friendship = $wpdb->get_row($sql);
    31        
    32         if ( $friendship ) {
    33             if ( !$this->is_request ) {
    34                 $this->initiator_user_id = $friendship->initiator_user_id;
    35                 $this->friend_user_id = $friendship->friend_user_id;
    36             } else {
    37                 $this->initiator_user_id = $friendship->friend_user_id;
    38                 $this->friend_user_id = $friendship->initiator_user_id;     
    39             }
    40 
     29        if ( $friendship = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $bp['friends']['table_name'] . " WHERE id = %d", $this->id ) ) ) {
     30            $this->initiator_user_id = $friendship->initiator_user_id;
     31            $this->friend_user_id = $friendship->friend_user_id;
    4132            $this->is_confirmed = $friendship->is_confirmed;
    4233            $this->is_limited = $friendship->is_limited;
  • trunk/bp-groups.php

    r414 r439  
    1818 **************************************************************************/
    1919
    20 function groups_install( $version ) {
     20function groups_install() {
    2121    global $wpdb, $bp;
    2222   
     
    8585    dbDelta($sql);
    8686   
    87     add_site_option( 'bp-groups-version', $version );
     87    add_site_option( 'bp-groups-version', BP_GROUPS_VERSION );
    8888}
    8989
     
    122122
    123123
    124 /**************************************************************************
    125  groups_add_admin_menu()
    126  
    127  Creates the administration interface menus and checks to see if the DB
    128  tables are set up.
    129  **************************************************************************/
    130 
    131 function groups_add_admin_menu() { 
    132     global $wpdb, $bp, $userdata;
    133    
    134     if ( $wpdb->blogid == $bp['current_homebase_id'] ) {
    135         /* Add the administration tab under the "Site Admin" tab for site administrators */
    136         //add_submenu_page( 'wpmu-admin.php', __("Friends"), __("Friends"), 1, basename(__FILE__), "friends_settings" );
    137     }
    138 
    139     /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
    140     if ( ( $wpdb->get_var("show tables like '%" . $bp['groups']['table_name'] . "%'") == false ) || ( get_site_option('bp-groups-version') < BP_GROUPS_VERSION )  )
    141         groups_install(BP_GROUPS_VERSION);
    142    
    143 }
    144 add_action( 'admin_menu', 'groups_add_admin_menu' );
     124function groups_check_installed() {
     125    global $wpdb, $bp;
     126   
     127    if ( is_site_admin() ) {
     128        /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
     129        if ( ( $wpdb->get_var("show tables like '%" . $bp['groups']['table_name'] . "%'") == false ) || ( get_site_option('bp-groups-version') < BP_GROUPS_VERSION )  )
     130            groups_install();
     131    }
     132}
     133add_action( 'admin_menu', 'groups_check_installed' );
    145134
    146135/**************************************************************************
  • trunk/bp-messages.php

    r398 r439  
    1717 **************************************************************************/
    1818
    19 function messages_install( $version ) {
     19function messages_install() {
    2020    global $wpdb, $bp;
    2121   
     
    7979    dbDelta($sql);
    8080   
    81     add_site_option( 'bp-messages-version', $version );
     81    add_site_option( 'bp-messages-version', BP_MESSAGES_VERSION );
    8282}
    8383
     
    115115 **************************************************************************/
    116116
    117 function messages_add_admin_menu() {   
     117function messages_check_installed() {   
    118118    global $wpdb, $bp, $userdata;
    119119
    120     if ( $wpdb->blogid == $bp['current_homebase_id'] ) {   
    121         //Add the administration tab under the "Site Admin" tab for site administrators
    122         //add_submenu_page ( 'wpmu-admin.php', __('Messages'), __('Messages'), 1, basename(__FILE__), "messages_settings" );
    123     }
    124    
    125     /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
    126     if ( ( $wpdb->get_var( "show tables like '%" . $bp['messages']['table_name'] . "%'" ) == false ) || ( get_site_option('bp-messages-version') < BP_MESSAGES_VERSION ) )
    127         messages_install(BP_MESSAGES_VERSION);
    128 }
    129 add_action( 'admin_menu', 'messages_add_admin_menu' );
     120    if ( is_site_admin() ) {
     121        /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
     122        if ( ( $wpdb->get_var( "show tables like '%" . $bp['messages']['table_name'] . "%'" ) == false ) || ( get_site_option('bp-messages-version') < BP_MESSAGES_VERSION ) )
     123            messages_install();
     124    }
     125}
     126add_action( 'admin_menu', 'messages_check_installed' );
    130127
    131128/**************************************************************************
     
    340337}
    341338
     339function messages_format_notifications( $action, $item_id, $total_items ) {
     340    global $bp;
     341   
     342    if ( $action == 'new_message') {
     343        if ( (int)$total_items > 1 )
     344            return '<a href="' . $bp['loggedin_domain'] . $bp['messages']['slug'] . '/inbox" title="Inbox">' . sprintf( __('You have %d new messages'), (int)$total_items ) . '</a>';       
     345        else
     346            return '<a href="' . $bp['loggedin_domain'] . $bp['messages']['slug'] . '/inbox" title="Inbox">' . sprintf( __('You have %d new message'), (int)$total_items ) . '</a>';
     347    }
     348}
     349
     350
    342351/**************************************************************************
    343352 messages_write_new()
     
    349358    <?php
    350359    global $messages_write_new_action;
    351    
    352     if ( $messages_write_new_action == '' )
    353         $messages_write_new_action = 'admin.php?page=bp-messages.php&amp;mode=send';
    354360    ?>
    355361   
     
    409415}
    410416
    411 function messages_inbox() {
    412     messages_box( 'inbox', __('Inbox', 'buddypress') );
    413 }
    414 
    415 function messages_sentbox() {
    416     messages_box( 'sentbox', __('Sent Messages', 'buddypress') );
    417 }
    418 
    419 
    420 /**************************************************************************
    421  messages_box()
    422  
    423  Handles and displays the messages in a particular box for the current user.
    424  **************************************************************************/
    425 
    426 function messages_box( $box = 'inbox', $display_name = 'Inbox', $message = '', $type = '' ) {
    427     global $bp, $userdata;
    428    
    429     if ( isset($_GET['mode']) && isset($_GET['thread_id']) && $_GET['mode'] == 'view' ) {
    430         messages_view_thread( $_GET['thread_id'], 'inbox' );
    431     } else if ( isset($_GET['mode']) && isset($_GET['thread_id']) && $_GET['mode'] == 'delete' ) {
    432         messages_delete_thread( $_GET['thread_id'], $box, $display_name );
    433     } else if ( isset($_GET['mode']) && isset($_POST['thread_ids']) && $_GET['mode'] == 'delete_bulk' ) {
    434         messages_delete_thread( $_POST['thread_ids'], $box, $display_name );
    435     } else if ( isset($_GET['mode']) && $_GET['mode'] == 'send' ) {
    436         messages_send_message( $_POST['send_to'], $_POST['subject'], $_POST['content'], $_POST['thread_id'] );
    437     } else {
    438     ?>
    439    
    440         <div class="wrap">
    441             <h2><?php echo $display_name ?></h2>
    442             <form action="admin.php?page=bp-messages.php&amp;mode=delete_bulk" method="post">
    443 
    444             <?php
    445                 if ( $message != '' ) {
    446                     $type = ( $type == 'error' ) ? 'error' : 'updated';
    447             ?>
    448                 <div id="message" class="<?php echo $type; ?> fade">
    449                     <p><?php echo $message; ?></p>
    450                 </div>
    451             <?php } ?>
    452            
    453             <?php if ( $box == 'inbox' ) { ?>
    454                 <div class="messages-options"> 
    455                     <?php bp_messages_options() ?>
    456                 </div>
    457                
    458                 <?php bp_message_get_notices(); ?>
    459             <?php } ?>
    460    
    461             <table class="widefat" id="message-threads" style="margin-top: 10px;">
    462                 <tbody id="the-list">
    463         <?php
    464         $threads = BP_Messages_Thread::get_current_threads_for_user( $userdata->ID, $box );
    465        
    466         if ( $threads ) {
    467             $counter = 0;
    468             foreach ( $threads as $thread ) {
    469                 if ( $thread->unread_count ) {
    470                     $is_read = '<img src="' . $bp['messages']['image_base'] .'/email.gif" alt="New Message" /><a href="admin.php?page=bp-messages.php&amp;mode=view&amp;thread_id=' . $thread->thread_id . '"><span id="awaiting-mod" class="count-1"><span class="message-count">' . $thread->unread_count . '</span></span></a>';
    471                     $new = " unread";
    472                 } else {
    473                     $is_read = '<img src="' . $bp['messages']['image_base'] .'/email_open.gif" alt="Older Message" />';
    474                     $new = " read";
    475                 }
    476                
    477                 if ( $counter % 2 == 0 )
    478                     $class = "alternate";
    479                 ?>
    480                     <tr class="<?php echo $class . $new ?>" id="m-<?php echo $message->id ?>">
    481                         <td class="is-read" width="1%"><?php echo $is_read ?></td>
    482                         <td class="avatar" width="1%">
    483                             <?php if ( function_exists('bp_core_get_avatar') )
    484                                     echo bp_core_get_avatar($thread->last_sender_id, 1);
    485                             ?>
    486                         </td>
    487                         <td class="sender-details" width="20%">
    488                             <?php if ( $box == 'sentbox') { ?>
    489                                 <h3>To: <?php echo BP_Messages_Thread::get_recipient_links($thread->recipients); ?></h3>
    490                             <?php } else { ?>
    491                                 <h3>From: <?php echo bp_core_get_userlink($thread->last_sender_id) ?></h3>
    492                             <?php } ?>
    493                             <?php echo bp_format_time(strtotime($thread->last_post_date)) ?>
    494                         </td>
    495                         <td class="message-details" width="40%">
    496                             <h4><a href="admin.php?page=bp-messages.php&amp;mode=view&amp;thread_id=<?php echo $thread->thread_id ?>"><?php echo stripslashes($thread->last_message_subject) ?></a></h4>
    497                             <?php echo bp_create_excerpt($thread->last_message_message, 20); ?>
    498                         </td>
    499                         <td width="10%"><a href="admin.php?page=bp-messages.php&amp;mode=delete&amp;thread_id=<?php echo $thread->thread_id ?>">Delete</a> <input type="checkbox" name="message_ids[]" value="<?php echo $thread->thread_id ?>" /></td>
    500                     </tr>
    501                 <?php
    502    
    503                 $counter++;
    504                 unset($class);
    505                 unset($new);
    506                 unset($is_read);
    507             }
    508            
    509             echo '
    510                 </tbody>
    511                 </table>
    512                 <p class="submit">
    513                     <input id="deletebookmarks" class="button" type="submit" onclick="return confirm(\'You are about to delete these messages permanently.\n[Cancel] to stop, [OK] to delete.\')" value="Delete Checked Messages &raquo;" name="deletebookmarks"/>
    514                 </p>
    515                 </form>
    516             </div>';
    517            
    518         } else {
    519             ?>
    520                 <tr class="alternate">
    521                 <td colspan="7" style="text-align: center; padding: 15px 0;">
    522                     <?php _e('You have no messages in your', 'buddypress'); echo ' ' . $display_name . '.'; ?>
    523                 </td>
    524                 </tr>
    525             <?php
    526         }
    527         ?>
    528             </tbody>
    529             </table>
    530             </form>
    531         </div>
    532         <?php
    533     }
    534 }
    535 
    536417/**************************************************************************
    537418 messages_send_message()
     
    603484                    $type = 'success';
    604485                   
    605                     do_action( 'bp_messages_message_sent', array( 'item_id' => $pmessage->id, 'component_name' => 'messages', 'component_action' => 'message_sent', 'is_private' => 1 ) );
     486                    // Send notices to the recipients
     487                    for ( $i = 0; $i < count($pmessage->recipients); $i++ ) {
     488                        if ( $pmessage->recipients[$i] != $bp['loggedin_userid'] )
     489                            bp_core_add_notification( $pmessage->id, $pmessage->recipients[$i], 'messages', 'new_message' );   
     490                    }
     491                   
     492                    do_action( 'bp_messages_message_sent', array( 'item_id' => $pmessage->id, 'recipient_ids' => $pmessage->recipients, 'component_name' => 'messages', 'component_action' => 'message_sent', 'is_private' => 1 ) );
    606493           
    607494                    if ( $from_ajax ) {
  • trunk/bp-messages/bp-messages-templatetags.php

    r391 r439  
    102102        wp_die('No Access');
    103103    } else {
     104        if ( $bp['current_action'] == 'inbox' )
     105            bp_core_delete_notifications_for_user_by_type( $bp['loggedin_userid'], 'messages', 'new_message' );
     106   
    104107        $messages_template = new BP_Messages_Template( $bp['loggedin_userid'], $bp['current_action'] );
    105108    }
  • trunk/bp-wire.php

    r398 r439  
    1818 **************************************************************************/
    1919
    20 function bp_wire_install( $version ) {
     20function bp_wire_install() {
    2121    global $wpdb, $bp;
    2222   
    2323    // No DB tables need to be installed, DB tables for each component wire
    2424    // are set up within that component *if* this component is installed.
    25    
    26     add_site_option( 'bp-wire-version', $version );
     25    add_site_option( 'bp-wire-version', BP_WIRE_VERSION );
    2726}
    2827
     
    3837   
    3938    if ( get_site_option('bp-wire-version') < BP_WIRE_VERSION ) {
    40         bp_wire_install(BP_WIRE_VERSION);
     39        bp_wire_install();
    4140    }
    4241   
     
    183182}
    184183
     184
    185185?>
  • trunk/bp-wire/bp-wire-templatetags.php

    r436 r439  
    2323        if ( $bp['current_component'] == $bp['wire']['slug'] ) {
    2424            $this->table_name = $bp['profile']['table_name_wire'];
     25           
     26            // Seeing as we're viewing a users wire, lets remove any new wire
     27            // post notifications
     28            if ( $bp['current_action'] == 'all-posts' )
     29                bp_core_delete_notifications_for_user_by_type( $bp['loggedin_userid'], 'xprofile', 'new_wire_post' );
     30           
    2531        } else {
    2632            $this->table_name = $bp[$bp['current_component']]['table_name_wire'];
  • trunk/bp-xprofile.php

    r438 r439  
    2020 **************************************************************************/
    2121
    22 function xprofile_install( $version ) {
     22function xprofile_install() {
    2323    global $bp;
    2424   
     
    9797
    9898    dbDelta($sql);
    99     add_site_option('bp-xprofile-version', $version);
     99    add_site_option('bp-xprofile-version', BP_XPROFILE_VERSION);
    100100}
    101101
     
    142142    global $wpdb, $bp, $groups, $userdata;
    143143   
    144     if ( $wpdb->blogid == $bp['current_homebase_id'] ) {
    145         add_menu_page( __('Profile', 'buddypress'), __('Profile', 'buddypress'), 1, basename(__FILE__), 'bp_core_avatar_admin' );
    146         add_submenu_page( basename(__FILE__), __('Profile &rsaquo; Avatar', 'buddypress'), __('Avatar', 'buddypress'), 1, basename(__FILE__), 'xprofile_avatar_admin' );       
    147        
    148         $groups = BP_XProfile_Group::get_all();
    149 
    150         for ( $i=0; $i < count($groups); $i++ ) {
    151             if ( $groups[$i]->fields ) {
    152                 add_submenu_page( basename(__FILE__), __('Profile', 'buddypress') . '  &rsaquo; ' . $groups[$i]->name, $groups[$i]->name, 1, "xprofile_" . $groups[$i]->name, "xprofile_edit" );       
    153             }
    154         }
    155     }               
    156 
    157144    if ( is_site_admin() ) {
    158145        wp_enqueue_script( 'jquery.tablednd', '/wp-content/mu-plugins/bp-core/js/jquery/jquery.tablednd.js', array( 'jquery' ), '0.4' );
     
    160147        /* Add the administration tab under the "Site Admin" tab for site administrators */
    161148        add_submenu_page( 'wpmu-admin.php', __("Profiles", 'buddypress'), __("Profiles", 'buddypress'), 1, "xprofile_settings", "xprofile_admin" );
    162     }
    163 
    164     /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
    165     if ( ( $wpdb->get_var("show tables like '%" . $bp['profile']['table_name_groups'] . "%'") == false ) || ( get_site_option('bp-xprofile-version') < BP_XPROFILE_VERSION )  )
    166         xprofile_install(BP_XPROFILE_VERSION);
    167    
     149
     150        /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
     151        if ( ( $wpdb->get_var("show tables like '%" . $bp['profile']['table_name_groups'] . "%'") == false ) || ( get_site_option('bp-xprofile-version') < BP_XPROFILE_VERSION )  )
     152            xprofile_install();
     153    }
    168154}
    169155add_action( 'admin_menu', 'xprofile_add_admin_menu' );
     
    282268                return false;
    283269               
    284             return bp_core_get_userlink($bp['current_userid']) . ' ' . __('updated the', 'buddypress') . ' "<a href="' . $bp['current_domain'] . $bp['profile']['slug'] . '">' . $profile_group->name . '</a>" ' . __('information on your profile', 'buddypress') . '. <span class="time-since">%s</span>';
     270            return bp_core_get_userlink($bp['current_userid']) . ' ' . __('updated the', 'buddypress') . ' "<a href="' . $bp['current_domain'] . $bp['profile']['slug'] . '">' . $profile_group->name . '</a>" ' . __('information on their profile', 'buddypress') . '. <span class="time-since">%s</span>';
    285271        break;
    286272    }
     
    288274    return false;
    289275}
     276
     277function xprofile_format_notifications( $action, $item_id, $total_items ) {
     278    global $bp;
     279
     280    if ( $action == 'new_wire_post') {
     281        if ( (int)$total_items > 1 ) {
     282            return '<a href="' . $bp['loggedin_domain'] . $bp['wire']['slug'] . '" title="Wire">' . sprintf( __('You have %d new posts on your wire'), (int)$total_items ) . '</a>';       
     283        } else {
     284            $user_fullname = bp_core_global_user_fullname( $item_id );
     285            return '<a href="' . $bp['loggedin_domain'] . $bp['wire']['slug'] . '" title="Wire">' . sprintf( __('%s posted on your wire'), $user_fullname ) . '</a>';
     286        }
     287    }
     288   
     289    return false;
     290}
     291
     292function xprofile_record_wire_post_notification( $wire_post_id, $user_id, $poster_id ) {
     293    global $bp;
     294   
     295    if ( $bp['current_component'] == $bp['wire']['slug'] && !bp_is_home() )
     296        bp_core_add_notification( $poster_id, $user_id, 'xprofile', 'new_wire_post' );
     297}
     298add_action( 'bp_wire_post_posted', 'xprofile_record_wire_post_notification', 10, 3 );
    290299
    291300/**************************************************************************
Note: See TracChangeset for help on using the changeset viewer.