Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/06/2011 07:10:08 PM (14 years ago)
Author:
boonebgorges
Message:

Provides initial support for Notifications menu in WP Admin Bar. Refactors group and friendship notifications to return values compatible with the WP Admin Bar constructor. Modifies bp_core_get_notifications_for_user() in order to provide WP Admin Bar support in addition to BuddyBar backpat. References #3294

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-activity.php

    r4384 r4620  
    7474add_action( 'groups_new_forum_topic_post', 'groups_update_last_activity' );
    7575
    76 function groups_format_notifications( $action, $item_id, $secondary_item_id, $total_items ) {
     76function groups_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
    7777    global $bp;
    7878
     
    8383
    8484            $group = new BP_Groups_Group( $group_id );
    85 
    86             $group_link = bp_get_group_permalink( $group );
    87 
    88             if ( (int)$total_items > 1 ) {
    89                 return apply_filters( 'bp_groups_multiple_new_membership_requests_notification', '<a href="' . $group_link . '/admin/membership-requests/?n=1" title="' . __( 'Group Membership Requests', 'buddypress' ) . '">' . sprintf( __( '%1$d new membership requests for the group "%2$s"', 'buddypress' ), (int)$total_items, $group->name ) . '</a>', $group_link, $total_items, $group->name );
     85            $group_link = bp_get_group_permalink( $group );
     86
     87            // Set up the string and the filter
     88            // Because different values are passed to the filters, we'll return the
     89            // values inline
     90            if ( (int)$total_items > 1 ) {
     91                $text = sprintf( __( '%1$d new membership requests for the group "%2$s"', 'buddypress' ), (int)$total_items, $group->name );
     92                $filter = 'bp_groups_multiple_new_membership_requests_notification';
     93                $notification_link = $group_link . 'admin/membership-requests/?n=1';
     94               
     95                if ( 'string' == $format ) {
     96                    return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Group Membership Requests', 'buddypress' ) . '">' . $text . '</a>', $group_link, $total_items, $group->name, $text, $notification_link );
     97                } else {
     98                    return apply_filters( $filter, array(
     99                        'link' => $notification_link,
     100                        'text' => $text
     101                    ), $group_link, $total_items, $group->name, $text, $notification_link );
     102                }
    90103            } else {
    91104                $user_fullname = bp_core_get_user_displayname( $requesting_user_id );
    92                 return apply_filters( 'bp_groups_single_new_membership_request_notification', '<a href="' . $group_link . 'admin/membership-requests/?n=1" title="' . sprintf( __( '%s requests group membership', 'buddypress' ), $user_fullname ) . '">' . sprintf( __( '%1$s requests membership for the group "%2$s"', 'buddypress' ), $user_fullname, $group->name ) . '</a>', $group_link, $user_fullname, $group->name );
    93             }
     105                $text = sprintf( __( '%s requests group membership', 'buddypress' ), $user_fullname );
     106                $filter = 'bp_groups_single_new_membership_request_notification';
     107                $notification_link = $group_link . '?n=1';
     108               
     109                if ( 'string' == $format ) {
     110                    return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . sprintf( __( '%s requests group membership', 'buddypress' ), $user_fullname ) . '">' . $text . '</a>', $group_link, $user_fullname, $group->name, $text, $notification_link );
     111                } else {
     112                    return apply_filters( $filter, array(
     113                        'link' => $notification_link,
     114                        'text' => $text
     115                    ), $group_link, $user_fullname, $group->name, $text, $notification_link );
     116                }
     117            }
     118           
    94119            break;
    95120
     
    100125            $group_link = bp_get_group_permalink( $group );
    101126
    102             if ( (int)$total_items > 1 )
    103                 return apply_filters( 'bp_groups_multiple_membership_request_accepted_notification', '<a href="' . $bp->loggedin_user->domain . $bp->groups->slug . '/?n=1" title="' . __( 'Groups', 'buddypress' ) . '">' . sprintf( __( '%d accepted group membership requests', 'buddypress' ), (int)$total_items, $group->name ) . '</a>', $total_items, $group->name );
    104             else
    105                 return apply_filters( 'bp_groups_single_membership_request_accepted_notification', '<a href="' . $group_link . '?n=1">' . sprintf( __( 'Membership for group "%s" accepted', 'buddypress' ), $group->name ) . '</a>', $group_link, $group->name );
     127            if ( (int)$total_items > 1 ) {
     128                $text = sprintf( __( '%d accepted group membership requests', 'buddypress' ), (int)$total_items, $group->name );
     129                $filter = 'bp_groups_multiple_membership_request_accepted_notification';               
     130                $notification_link = bp_loggedin_user_domain() . bp_get_groups_slug() . '/?n=1';
     131               
     132                if ( 'string' == $format ) {
     133                    return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $group->name, $text, $notification_link );
     134                } else {
     135                    return apply_filters( $filter, array(
     136                        'link' => $notification_link,
     137                        'text' => $text
     138                    ), $total_items, $group->name, $text, $notification_link );
     139                }
     140            } else {
     141                $text = sprintf( __( 'Membership for group "%s" accepted', 'buddypress' ), $group->name );
     142                $filter = 'bp_groups_single_membership_request_accepted_notification';
     143                $notification_link = $group_link . '?n=1';
     144               
     145                if ( 'string' == $format ) {
     146                    return apply_filters( $filter, '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link );
     147                } else {
     148                    return apply_filters( $filter, array(
     149                        'link' => $notification_link,
     150                        'text' => $text
     151                    ), $group_link, $group->name, $text, $notification_link );
     152                }
     153            }
    106154
    107155            break;
     
    112160            $group = new BP_Groups_Group( $group_id );
    113161            $group_link = bp_get_group_permalink( $group );
    114 
    115             if ( (int)$total_items > 1 )
    116                 return apply_filters( 'bp_groups_multiple_membership_request_rejected_notification', '<a href="' . $bp->loggedin_user->domain . $bp->groups->slug . '/?n=1" title="' . __( 'Groups', 'buddypress' ) . '">' . sprintf( __( '%d rejected group membership requests', 'buddypress' ), (int)$total_items, $group->name ) . '</a>', $total_items, $group->name );
    117             else
    118                 return apply_filters( 'bp_groups_single_membership_request_rejected_notification', '<a href="' . $group_link . '?n=1">' . sprintf( __( 'Membership for group "%s" rejected', 'buddypress' ), $group->name ) . '</a>', $group_link, $group->name );
     162           
     163            if ( (int)$total_items > 1 ) {
     164                $text = sprintf( __( '%d rejected group membership requests', 'buddypress' ), (int)$total_items, $group->name );
     165                $filter = 'bp_groups_multiple_membership_request_rejected_notification';
     166                $notification_link = bp_loggedin_user_domain() . bp_get_groups_slug() . '/?n=1';
     167               
     168                if ( 'string' == $format ) {
     169                    return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $group->name );
     170                } else {
     171                    return apply_filters( $filter, array(
     172                        'link' => $notification_link,
     173                        'text' => $text
     174                    ), $total_items, $group->name, $text, $notification_link );
     175                }
     176            } else {
     177                $text = sprintf( __( 'Membership for group "%s" rejected', 'buddypress' ), $group->name );
     178                $filter = 'bp_groups_single_membership_request_rejected_notification';
     179                $notification_link = $group_link . '?n=1';
     180               
     181                if ( 'string' == $format ) {
     182                    return apply_filters( $filter, '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link );
     183                } else {
     184                    return apply_filters( $filter, array(
     185                        'link' => $notification_link,
     186                        'text' => $text
     187                    ), $group_link, $group->name, $text, $notification_link );
     188                }
     189            }
    119190
    120191            break;
     
    126197            $group_link = bp_get_group_permalink( $group );
    127198
    128             if ( (int)$total_items > 1 )
    129                 return apply_filters( 'bp_groups_multiple_member_promoted_to_admin_notification', '<a href="' . $bp->loggedin_user->domain . $bp->groups->slug . '/?n=1" title="' . __( 'Groups', 'buddypress' ) . '">' . sprintf( __( 'You were promoted to an admin in %d groups', 'buddypress' ), (int)$total_items ) . '</a>', $total_items );
    130             else
    131                 return apply_filters( 'bp_groups_single_member_promoted_to_admin_notification', '<a href="' . $group_link . '?n=1">' . sprintf( __( 'You were promoted to an admin in the group %s', 'buddypress' ), $group->name ) . '</a>', $group_link, $group->name );
     199            if ( (int)$total_items > 1 ) {
     200                $text = sprintf( __( 'You were promoted to an admin in %d groups', 'buddypress' ), (int)$total_items );
     201                $filter = 'bp_groups_multiple_member_promoted_to_admin_notification';
     202                $notification_link = bp_loggedin_user_domain() . bp_get_groups_slug() . '?n=1';
     203               
     204                if ( 'string' == $format ) {
     205                    return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $text, $notification_link );
     206                } else {
     207                    return apply_filters( $filter, array(
     208                        'link' => $notification_link,
     209                        'text' => $text
     210                    ), $total_items, $text, $notification_link );
     211                }
     212            } else {
     213                $text = sprintf( __( 'You were promoted to an admin in the group "%s"', 'buddypress' ), $group->name );
     214                $filter = 'bp_groups_single_member_promoted_to_admin_notification';
     215                $notification_link = $group_link . '?n=1';
     216               
     217                if ( 'string' == $format ) {
     218                    return apply_filters( $filter, '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link );
     219                } else {
     220                    return apply_filters( $filter, array(
     221                        'link' => $notification_link,
     222                        'text' => $text
     223                    ), $group_link, $group->name, $text, $notification_link );
     224                }
     225            }
    132226
    133227            break;
     
    139233            $group_link = bp_get_group_permalink( $group );
    140234
    141             if ( (int)$total_items > 1 )
    142                 return apply_filters( 'bp_groups_multiple_member_promoted_to_mod_notification', '<a href="' . $bp->loggedin_user->domain . $bp->groups->slug . '/?n=1" title="' . __( 'Groups', 'buddypress' ) . '">' . sprintf( __( 'You were promoted to a mod in %d groups', 'buddypress' ), (int)$total_items ) . '</a>', $total_items );
    143             else
    144                 return apply_filters( 'bp_groups_single_member_promoted_to_mod_notification', '<a href="' . $group_link . '?n=1">' . sprintf( __( 'You were promoted to a mod in the group %s', 'buddypress' ), $group->name ) . '</a>', $group_link, $group->name );
     235            if ( (int)$total_items > 1 ) {
     236                $text = sprintf( __( 'You were promoted to a mod in %d groups', 'buddypress' ), (int)$total_items );
     237                $filter = 'bp_groups_multiple_member_promoted_to_mod_notification';
     238                $notification_link = bp_loggedin_user_domain() . bp_get_groups_slug() . '?n=1';
     239               
     240                if ( 'string' == $format ) {
     241                    return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $text, $notification_link );
     242                } else {
     243                    return apply_filters( $filter, array(
     244                        'link' => $notification_link,
     245                        'text' => $text
     246                    ), $total_items, $text, $notification_link );
     247                }
     248            } else {
     249                $text = sprintf( __( 'You were promoted to a mod in the group "%s"', 'buddypress' ), $group->name );
     250                $filter = 'bp_groups_single_member_promoted_to_mod_notification';
     251                $notification_link = $group_link . '?n=1';
     252               
     253                if ( 'string' == $format ) {
     254                    return apply_filters( $filter, '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link );
     255                } else {
     256                    return apply_filters( $filter, array(
     257                        'link' => $notification_link,
     258                        'text' => $text
     259                    ), $group_link, $group->name, $text, $notification_link );
     260                }
     261            }
    145262
    146263            break;
     
    148265        case 'group_invite':
    149266            $group_id = $item_id;
    150             $group = new BP_Groups_Group( $group_id );
    151 
    152             if ( (int)$total_items > 1 )
    153                 return apply_filters( 'bp_groups_multiple_group_invite_notification', '<a href="' . $bp->loggedin_user->domain . $bp->groups->slug . '/invites/?n=1" title="' . __( 'Group Invites', 'buddypress' ) . '">' . sprintf( __( 'You have %d new group invitations', 'buddypress' ), (int)$total_items ) . '</a>', $total_items );
    154             else
    155                 return apply_filters( 'bp_groups_single_group_invite_notification', '<a href="' . $bp->loggedin_user->domain . $bp->groups->slug . '/invites/?n=1" title="' . __( 'Group Invites', 'buddypress' ) . '">' . sprintf( __( 'You have an invitation to the group: %s', 'buddypress' ), $group->name ) . '</a>', $group->name );
     267            $group = new BP_Groups_Group( $group_id ); 
     268            $group_link = bp_get_group_permalink( $group );
     269           
     270            $notification_link = bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/?n=1';
     271
     272            if ( (int)$total_items > 1 ) {
     273                $text = sprintf( __( 'You have %d new group invitations', 'buddypress' ), (int)$total_items );
     274                $filter = 'bp_groups_multiple_group_invite_notification';
     275               
     276                if ( 'string' == $format ) {
     277                    return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Group Invites', 'buddypress' ) . '">' . $text . '</a>', $total_items, $text, $notification_link );
     278                } else {
     279                    return apply_filters( $filter, array(
     280                        'link' => $notification_link,
     281                        'text' => $text
     282                    ), $total_items, $text, $notification_link );
     283                }
     284            } else {
     285                $text = sprintf( __( 'You have an invitation to the group: %s', 'buddypress' ), $group->name );
     286                $filter = 'bp_groups_single_group_invite_notification';
     287               
     288                if ( 'string' == $format ) {
     289                    return apply_filters( $filter, '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link );
     290                } else {
     291                    return apply_filters( $filter, array(
     292                        'link' => $notification_link,
     293                        'text' => $text
     294                    ), $group_link, $group->name, $text, $notification_link );
     295                }
     296            }
    156297
    157298            break;
Note: See TracChangeset for help on using the changeset viewer.