/**
 * xprofile_record_wire_post_notification()
 *
 * Records a notification for a new profile wire post to the database and sends out a notification
 * email if the user has this setting enabled.
 * 
 * @package BuddyPress XProfile
 * @param $wire_post_id The ID of the wire post
 * @param $user_id The id of the user that the wire post was sent to
 * @param $poster_id The id of the user who wrote the wire post
 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
 * @global $current_user WordPress global variable containing current logged in user information
 * @uses bp_is_home() Returns true if the current user being viewed is equal the logged in user
 * @uses get_usermeta() Get a user meta value based on meta key from wp_usermeta
 * @uses BP_Wire_Post Class Creates a new wire post object based on ID.
 * @uses site_url Returns the site URL
 * @uses wp_mail Sends an email
 */
function xprofile_record_wire_post_notification($wire_post_id, $user_id, $poster_id)
{
    global $bp, $current_user;
    if ($bp->current_component == $bp->wire->slug && !bp_is_home()) {
        bp_core_add_notification($poster_id, $user_id, 'xprofile', 'new_wire_post');
        if (!get_usermeta($bp->loggedin_user->id, 'notification_profile_wire_post') || 'yes' == get_usermeta($bp->loggedin_user->id, 'notification_profile_wire_post')) {
            $poster_name = bp_fetch_user_fullname($poster_id, false);
            $wire_post = new BP_Wire_Post($bp->profile->table_name_wire, $wire_post_id, true);
            $ud = get_userdata($user_id);
            $wire_link = site_url() . '/' . BP_MEMBERS_SLUG . '/' . $ud->user_login . '/wire';
            $settings_link = site_url() . '/' . BP_MEMBERS_SLUG . '/' . $ud->user_login . '/settings/notifications';
            // Set up and send the message
            $to = $ud->user_email;
            $subject = '[' . get_blog_option(1, 'blogname') . '] ' . sprintf(__('%s posted on your wire.', 'buddypress'), stripslashes($poster_name));
            $message = sprintf(__('%s posted on your wire:

"%s"

To view your wire: %s

---------------------
', 'buddypress'), $poster_name, stripslashes($wire_post->content), $wire_link);
            $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
            // Send it
            wp_mail($to, $subject, $message);
        }
    }
}
/**
 * Sends an email notification and a BP notification when someone mentions you in an update
 *
 * @since BuddyPress (1.2)
 *
 * @param int $activity_id The id of the activity update
 * @param int $receiver_user_id The unique user_id of the user who is receiving the update
 *
 * @uses bp_core_add_notification()
 * @uses bp_get_user_meta()
 * @uses bp_core_get_user_displayname()
 * @uses bp_activity_get_permalink()
 * @uses bp_core_get_user_domain()
 * @uses bp_get_settings_slug()
 * @uses bp_activity_filter_kses()
 * @uses bp_core_get_core_userdata()
 * @uses wp_specialchars_decode()
 * @uses get_blog_option()
 * @uses bp_is_active()
 * @uses bp_is_group()
 * @uses bp_get_current_group_name()
 * @uses apply_filters() To call the 'bp_activity_at_message_notification_to' hook
 * @uses apply_filters() To call the 'bp_activity_at_message_notification_subject' hook
 * @uses apply_filters() To call the 'bp_activity_at_message_notification_message' hook
 * @uses wp_mail()
 * @uses do_action() To call the 'bp_activity_sent_mention_email' hook
 */
function bp_activity_at_message_notification($activity_id, $receiver_user_id)
{
    // Don't leave multiple notifications for the same activity item
    $notifications = BP_Core_Notification::get_all_for_user($receiver_user_id, 'all');
    foreach ($notifications as $notification) {
        if ($activity_id == $notification->item_id) {
            return;
        }
    }
    $activity = new BP_Activity_Activity($activity_id);
    $subject = '';
    $message = '';
    $content = '';
    // Add the BP notification
    bp_core_add_notification($activity_id, $receiver_user_id, 'activity', 'new_at_mention', $activity->user_id);
    // Now email the user with the contents of the message (if they have enabled email notifications)
    if ('no' != bp_get_user_meta($receiver_user_id, 'notification_activity_new_mention', true)) {
        $poster_name = bp_core_get_user_displayname($activity->user_id);
        $message_link = bp_activity_get_permalink($activity_id);
        $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
        $settings_link = bp_core_get_user_domain($receiver_user_id) . $settings_slug . '/notifications/';
        $poster_name = stripslashes($poster_name);
        $content = bp_activity_filter_kses(strip_tags(stripslashes($activity->content)));
        // Set up and send the message
        $ud = bp_core_get_core_userdata($receiver_user_id);
        $to = $ud->user_email;
        $subject = bp_get_email_subject(array('text' => sprintf(__('%s mentioned you in an update', 'buddypress'), $poster_name)));
        if (bp_is_active('groups') && bp_is_group()) {
            $message = sprintf(__('%1$s mentioned you in the group "%2$s":

"%3$s"

To view and respond to the message, log in and visit: %4$s

---------------------
', 'buddypress'), $poster_name, bp_get_current_group_name(), $content, $message_link);
        } else {
            $message = sprintf(__('%1$s mentioned you in an update:

"%2$s"

To view and respond to the message, log in and visit: %3$s

---------------------
', 'buddypress'), $poster_name, $content, $message_link);
        }
        // Only show the disable notifications line if the settings component is enabled
        if (bp_is_active('settings')) {
            $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
        }
        /* Send the message */
        $to = apply_filters('bp_activity_at_message_notification_to', $to);
        $subject = apply_filters('bp_activity_at_message_notification_subject', $subject, $poster_name);
        $message = apply_filters('bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link, $settings_link);
        wp_mail($to, $subject, $message);
    }
    do_action('bp_activity_sent_mention_email', $activity, $subject, $message, $content);
}
function social_articles_send_notification($id)
{
    global $bp, $socialArticles;
    $savedPost = get_post($id);
    $notification_already_sent = get_post_meta($id, 'notification_already_sent', true);
    if (empty($notification_already_sent) && function_exists("friends_get_friend_user_ids") && $savedPost->post_status == "publish" && $savedPost->post_type == "post" && !wp_is_post_revision($id) && $socialArticles->options['bp_notifications'] == "true") {
        $friends = friends_get_friend_user_ids($savedPost->post_author);
        foreach ($friends as $friend) {
            bp_core_add_notification($savedPost->ID, $friend, $bp->social_articles->id, 'new_article' . $savedPost->ID, $savedPost->post_author);
        }
        bp_core_add_notification($savedPost->ID, $savedPost->post_author, $bp->social_articles->id, 'new_article' . $savedPost->ID, -1);
        update_post_meta($id, 'notification_already_sent', true);
    }
}
/**
 * Sends an email notification and a BP notification when someone mentions you in an update
 *
 * @since 1.2.0
 *
 * @param int $activity_id The id of the activity update
 * @param int $receiver_user_id The unique user_id of the user who is receiving the update
 *
 * @global object $bp BuddyPress global settings
 * @uses bp_core_add_notification()
 * @uses bp_get_user_meta()
 * @uses bp_core_get_user_displayname()
 * @uses bp_activity_get_permalink()
 * @uses bp_core_get_user_domain()
 * @uses bp_get_settings_slug()
 * @uses bp_activity_filter_kses()
 * @uses bp_core_get_core_userdata()
 * @uses nxt_specialchars_decode()
 * @uses get_blog_option()
 * @uses bp_is_active()
 * @uses bp_is_group()
 * @uses bp_get_current_group_name()
 * @uses apply_filters() To call the 'bp_activity_at_message_notification_to' hook
 * @uses apply_filters() To call the 'bp_activity_at_message_notification_subject' hook
 * @uses apply_filters() To call the 'bp_activity_at_message_notification_message' hook
 * @uses nxt_mail()
 * @uses do_action() To call the 'bp_activity_sent_mention_email' hook
 */
function bp_activity_at_message_notification($activity_id, $receiver_user_id)
{
    global $bp;
    $activity = new BP_Activity_Activity($activity_id);
    $subject = '';
    $message = '';
    // Add the BP notification
    bp_core_add_notification($activity_id, $receiver_user_id, 'activity', 'new_at_mention', $activity->user_id);
    // Now email the user with the contents of the message (if they have enabled email notifications)
    if ('no' != bp_get_user_meta($receiver_user_id, 'notification_activity_new_mention', true)) {
        $poster_name = bp_core_get_user_displayname($activity->user_id);
        $message_link = bp_activity_get_permalink($activity_id);
        $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
        $settings_link = bp_core_get_user_domain($receiver_user_id) . $settings_slug . '/notifications/';
        $poster_name = stripslashes($poster_name);
        $content = bp_activity_filter_kses(strip_tags(stripslashes($activity->content)));
        // Set up and send the message
        $ud = bp_core_get_core_userdata($receiver_user_id);
        $to = $ud->user_email;
        $sitename = nxt_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES);
        $subject = '[' . $sitename . '] ' . sprintf(__('%s mentioned you in an update', 'buddypress'), $poster_name);
        if (bp_is_active('groups') && bp_is_group()) {
            $message = sprintf(__('%1$s mentioned you in the group "%2$s":

"%3$s"

To view and respond to the message, log in and visit: %4$s

---------------------
', 'buddypress'), $poster_name, bp_get_current_group_name(), $content, $message_link);
        } else {
            $message = sprintf(__('%1$s mentioned you in an update:

"%2$s"

To view and respond to the message, log in and visit: %3$s

---------------------
', 'buddypress'), $poster_name, $content, $message_link);
        }
        $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
        /* Send the message */
        $to = apply_filters('bp_activity_at_message_notification_to', $to);
        $subject = apply_filters('bp_activity_at_message_notification_subject', $subject, $poster_name);
        $message = apply_filters('bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link, $settings_link);
        nxt_mail($to, $subject, $message);
    }
    do_action('bp_activity_sent_mention_email', $activity, $subject, $message, $content);
}
Exemplo n.º 5
0
/**
 * Catch booking saves and add a BP notification.
 * @param boolean $result
 * @param EM_Booking $EM_Booking
 * @return boolean
 */
function bp_em_add_booking_notification($result, $EM_Booking)
{
    global $bp;
    if (get_option('dbem_bookings_approval') && $EM_Booking->get_status() == 0) {
        $action = 'pending_booking';
    } elseif ($EM_Booking->get_status() == 1 || get_option('dbem_bookings_approval') && $EM_Booking->get_status() == 0) {
        $action = 'confirmed_booking';
    } elseif ($EM_Booking->get_status() == 3) {
        $action = 'cancelled_booking';
    }
    if (!empty($action)) {
        bp_core_add_notification($EM_Booking->booking_id, $EM_Booking->get_event()->get_contact()->ID, 'events', $action);
    }
    return $result;
}
/**
 * Adds notification when a user follows another user.
 *
 * @since 1.2.1
 *
 * @param object $follow The BP_Follow object.
 */
function bp_follow_notifications_add_on_follow(BP_Follow $follow)
{
    // this only applies to users
    if (!empty($follow->follow_type)) {
        return;
    }
    // Add a screen notification
    //
    // BP 1.9+
    if (bp_is_active('notifications')) {
        bp_notifications_add_notification(array('item_id' => $follow->follower_id, 'user_id' => $follow->leader_id, 'component_name' => buddypress()->follow->id, 'component_action' => 'new_follow'));
        // BP < 1.9 - add notifications the old way
    } elseif (!class_exists('BP_Core_Login_Widget')) {
        global $bp;
        bp_core_add_notification($follow->follower_id, $follow->leader_id, $bp->follow->id, 'new_follow');
    }
    // Add an email notification
    bp_follow_new_follow_email_notification(array('leader_id' => $follow->leader_id, 'follower_id' => $follow->follower_id));
}
Exemplo n.º 7
0
/**
 * storing notification for users
 * notify all the users who have commented, or who was the original poster of the update, when someone comments
 * hook to activity_comment_posted action
 */
function ac_notifier_notify($comment_id, $params)
{
    global $bp;
    extract($params);
    $users = ac_notifier_find_involved_persons($activity_id);
    $activity = new BP_Activity_Activity($activity_id);
    //since there is a bug in bp 1.2.9 and causes trouble with private notificatin, so let us  not notify for any of the private activities
    if ($activity->hide_sitewide) {
        return;
    }
    //push the original poster user_id, if the original poster has not commented on his/her status yet
    if (!in_array($activity->user_id, $users) && $bp->loggedin_user->id != $activity->user_id) {
        //if someone else is commenting
        array_push($users, $activity->user_id);
    }
    foreach ((array) $users as $user_id) {
        //create a notification
        bp_core_add_notification($activity_id, $user_id, $bp->ac_notifier->id, 'new_activity_comment_' . $activity_id);
        //a hack to not allow grouping by component,action, rather group by component and individual action item
    }
}
Exemplo n.º 8
0
function friends_accept_friendship($friendship_id)
{
    global $bp;
    $friendship = new BP_Friends_Friendship($friendship_id, true, false);
    if (!$friendship->is_confirmed && BP_Friends_Friendship::accept($friendship_id)) {
        friends_update_friend_totals($friendship->initiator_user_id, $friendship->friend_user_id);
        // Remove the friend request notice
        bp_core_delete_notifications_by_item_id($friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request');
        // Add a friend accepted notice for the initiating user
        bp_core_add_notification($friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_accepted');
        $initiator_link = bp_core_get_userlink($friendship->initiator_user_id);
        $friend_link = bp_core_get_userlink($friendship->friend_user_id);
        // Record in activity streams for the initiator
        friends_record_activity(array('user_id' => $friendship->initiator_user_id, 'type' => 'friendship_created', 'action' => apply_filters('friends_activity_friendship_accepted_action', sprintf(__('%1$s and %2$s are now friends', 'buddypress'), $initiator_link, $friend_link), $friendship), 'item_id' => $friendship_id, 'secondary_item_id' => $friendship->friend_user_id));
        // Record in activity streams for the friend
        friends_record_activity(array('user_id' => $friendship->friend_user_id, 'type' => 'friendship_created', 'action' => apply_filters('friends_activity_friendship_accepted_action', sprintf(__('%1$s and %2$s are now friends', 'buddypress'), $friend_link, $initiator_link), $friendship), 'item_id' => $friendship_id, 'secondary_item_id' => $friendship->initiator_user_id, 'hide_sitewide' => true));
        // Send the email notification
        friends_notification_accepted_request($friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id);
        do_action('friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id);
        return true;
    }
    return false;
}
Exemplo n.º 9
0
/**
 * bp_zoneideas_send_high_five()
 *
 * Sends a high five message to a user. Registers an notification to the user
 * via their notifications menu, as well as sends an email to the user.
 *
 * Also records an activity stream item saying "User 1 high-fived User 2".
 */
function bp_zoneideas_send_highfive($to_user_id, $from_user_id)
{
    global $bp;
    if (!check_admin_referer('bp_zoneideas_send_high_five')) {
        return false;
    }
    /**
     * We'll store high-fives as usermeta, so we don't actually need
     * to do any database querying. If we did, and we were storing them
     * in a custom DB table, we'd want to reference a function in
     * bp-zoneideas-classes.php that would run the SQL query.
     */
    /* Get existing fives */
    $existing_fives = maybe_unserialize(get_usermeta($to_user_id, 'high-fives'));
    /* Check to see if the user has already high-fived. That's okay, but lets not
     * store duplicate high-fives in the database. What's the point, right?
     */
    if (!in_array($from_user_id, (array) $existing_fives)) {
        $existing_fives[] = (int) $from_user_id;
        /* Now wrap it up and fire it back to the database overlords. */
        update_usermeta($to_user_id, 'high-fives', serialize($existing_fives));
    }
    /***
     * Now we've registered the new high-five, lets work on some notification and activity
     * stream magic. 
     */
    /***
     * Post a screen notification to the user's notifications menu.
     * Remember, like activity streams we need to tell the activity stream component how to format
     * this notification in bp_zoneideas_format_notifications() using the 'new_high_five' action.
     */
    bp_core_add_notification($from_user_id, $to_user_id, $bp->zoneideas->slug, 'new_high_five');
    /* Now record the new 'new_high_five' activity item */
    bp_zoneideas_record_activity(array('item_id' => $to_user_id, 'user_id' => $from_user_id, 'component_name' => $bp->zoneideas->slug, 'component_action' => 'new_high_five', 'is_private' => 0));
    /* We'll use this do_action call to send the email notification. See bp-zoneideas-notifications.php */
    do_action('bp_zoneideas_send_high_five', $to_user_id, $from_user_id);
    return true;
}
function groups_notification_group_invites(&$group, &$member, $inviter_user_id)
{
    global $bp;
    $inviter_ud = bp_core_get_core_userdata($inviter_user_id);
    $inviter_name = bp_core_get_userlink($inviter_user_id, true, false, true);
    $inviter_link = bp_core_get_user_domain($inviter_user_id);
    $group_link = bp_get_group_permalink($group);
    if (!$member->invite_sent) {
        $invited_user_id = $member->user_id;
        // Post a screen notification first.
        bp_core_add_notification($group->id, $invited_user_id, 'groups', 'group_invite');
        if ('no' == bp_get_user_meta($invited_user_id, 'notification_groups_invite', true)) {
            return false;
        }
        $invited_ud = bp_core_get_core_userdata($invited_user_id);
        $settings_link = bp_core_get_user_domain($invited_user_id) . bp_get_settings_slug() . '/notifications/';
        $invited_link = bp_core_get_user_domain($invited_user_id);
        $invites_link = $invited_link . bp_get_groups_slug() . '/invites';
        // Set up and send the message
        $to = $invited_ud->user_email;
        $sitename = wp_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES);
        $subject = '[' . $sitename . '] ' . sprintf(__('You have an invitation to the group: "%s"', 'buddypress'), $group->name);
        $message = sprintf(__('One of your friends %1$s has invited you to the group: "%2$s".

To view your group invites visit: %3$s

To view the group visit: %4$s

To view %5$s\'s profile visit: %6$s

---------------------
', 'buddypress'), $inviter_name, $group->name, $invites_link, $group_link, $inviter_name, $inviter_link);
        $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
        /* Send the message */
        $to = apply_filters('groups_notification_group_invites_to', $to);
        $subject = apply_filters_ref_array('groups_notification_group_invites_subject', array($subject, &$group));
        $message = apply_filters_ref_array('groups_notification_group_invites_message', array($message, &$group, $inviter_name, $inviter_link, $invites_link, $group_link, $settings_link));
        wp_mail($to, $subject, $message);
        do_action('bp_groups_sent_invited_email', $invited_user_id, $subject, $message, $group);
    }
}
/**
 * Add a notification when a compliment get submitted.
 *
 * @since 0.0.2
 * @package BuddyPress_Compliments
 *
 * @global object $bp BuddyPress instance.
 * @param BP_Compliments $compliment The compliment object.
 */
function bp_compliments_notifications_add_on_compliment(BP_Compliments $compliment)
{
    // Add a screen notification
    // BP 1.9+
    if (bp_is_active('notifications')) {
        bp_notifications_add_notification(array('item_id' => $compliment->sender_id, 'user_id' => $compliment->receiver_id, 'secondary_item_id' => $compliment->id, 'component_name' => buddypress()->compliments->id, 'component_action' => 'new_compliment'));
        // BP < 1.9 - add notifications the old way
    } elseif (!class_exists('BP_Core_Login_Widget')) {
        global $bp;
        bp_core_add_notification($compliment->sender_id, $compliment->receiver_id, $bp->compliments->id, 'new_compliment');
    }
    // Add an email notification
    bp_compliments_new_compliment_email_notification(array('receiver_id' => $compliment->receiver_id, 'sender_id' => $compliment->sender_id));
}
Exemplo n.º 12
0
function friends_accept_friendship($friendship_id)
{
    /* Check the nonce */
    if (!check_admin_referer('friends_accept_friendship')) {
        return false;
    }
    $friendship = new BP_Friends_Friendship($friendship_id, true, false);
    if (!$friendship->is_confirmed && BP_Friends_Friendship::accept($friendship_id)) {
        friends_update_friend_totals($friendship->initiator_user_id, $friendship->friend_user_id);
        // Remove the friend request notice
        bp_core_delete_notifications_for_user_by_item_id($friendship->friend_user_id, $friendship->initiator_user_id, 'friends', 'friendship_request');
        // Add a friend accepted notice for the initiating user
        bp_core_add_notification($friendship->friend_user_id, $friendship->initiator_user_id, 'friends', 'friendship_accepted');
        // Record in activity streams
        friends_record_activity(array('item_id' => $friendship_id, 'component_name' => $bp->friends->slug, 'component_action' => 'friendship_accepted', 'is_private' => 0, 'user_id' => $friendship->initiator_user_id, 'secondary_user_id' => $friendship->friend_user_id));
        // Send the email notification
        require_once BP_PLUGIN_DIR . '/bp-friends/bp-friends-notifications.php';
        friends_notification_accepted_request($friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id);
        do_action('friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id);
        return true;
    }
    return false;
}
function groups_notification_group_invites(&$group, &$member, $inviter_user_id)
{
    // @todo $inviter_up may be used for caching, test without it
    $inviter_ud = bp_core_get_core_userdata($inviter_user_id);
    $inviter_name = bp_core_get_userlink($inviter_user_id, true, false, true);
    $inviter_link = bp_core_get_user_domain($inviter_user_id);
    $group_link = bp_get_group_permalink($group);
    if (!$member->invite_sent) {
        $invited_user_id = $member->user_id;
        // Post a screen notification first.
        bp_core_add_notification($group->id, $invited_user_id, 'groups', 'group_invite');
        if ('no' == bp_get_user_meta($invited_user_id, 'notification_groups_invite', true)) {
            return false;
        }
        $invited_ud = bp_core_get_core_userdata($invited_user_id);
        $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
        $settings_link = bp_core_get_user_domain($invited_user_id) . $settings_slug . '/notifications/';
        $invited_link = bp_core_get_user_domain($invited_user_id);
        $invites_link = trailingslashit($invited_link . bp_get_groups_slug() . '/invites');
        // Set up and send the message
        $to = $invited_ud->user_email;
        $subject = bp_get_email_subject(array('text' => sprintf(__('You have an invitation to the group: "%s"', 'buddypress'), $group->name)));
        $message = sprintf(__('One of your friends %1$s has invited you to the group: "%2$s".

To view your group invites visit: %3$s

To view the group visit: %4$s

To view %5$s\'s profile visit: %6$s

---------------------
', 'buddypress'), $inviter_name, $group->name, $invites_link, $group_link, $inviter_name, $inviter_link);
        // Only show the disable notifications line if the settings component is enabled
        if (bp_is_active('settings')) {
            $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
        }
        /* Send the message */
        $to = apply_filters('groups_notification_group_invites_to', $to);
        $subject = apply_filters_ref_array('groups_notification_group_invites_subject', array($subject, &$group));
        $message = apply_filters_ref_array('groups_notification_group_invites_message', array($message, &$group, $inviter_name, $inviter_link, $invites_link, $group_link, $settings_link));
        wp_mail($to, $subject, $message);
        do_action('bp_groups_sent_invited_email', $invited_user_id, $subject, $message, $group);
    }
}
Exemplo n.º 14
0
/**
 * xprofile_action_new_wire_post()
 *
 * Posts a new wire post to the users profile wire. 
 * 
 * @package BuddyPress XProfile
 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
 * @uses bp_wire_new_post() Adds a new wire post to a specific wire using the ID of the item passed and the table name.
 * @uses bp_core_add_message() Adds an error/success message to the session to be displayed on the next page load.
 * @uses bp_core_redirect() Safe redirects to a new page using the wp_redirect() function
 */
function xprofile_action_new_wire_post()
{
    global $bp;
    if ($bp->current_component != $bp->wire->slug) {
        return false;
    }
    if ('post' != $bp->current_action) {
        return false;
    }
    /* Check the nonce */
    if (!check_admin_referer('bp_wire_post')) {
        return false;
    }
    if (!($wire_post_id = bp_wire_new_post($bp->displayed_user->id, $_POST['wire-post-textarea'], $bp->profile->slug, false, $bp->profile->table_name_wire))) {
        bp_core_add_message(__('Wire message could not be posted. Please try again.', 'buddypress'), 'error');
    } else {
        bp_core_add_message(__('Wire message successfully posted.', 'buddypress'));
        if (!bp_is_home()) {
            /* Record the notification for the user */
            bp_core_add_notification($bp->loggedin_user->id, $bp->displayed_user->id, 'profile', 'new_wire_post');
        }
        do_action('xprofile_new_wire_post', $wire_post_id);
    }
    if (!strpos($_SERVER['HTTP_REFERER'], $bp->wire->slug)) {
        bp_core_redirect($bp->displayed_user->domain);
    } else {
        bp_core_redirect($bp->displayed_user->domain . $bp->wire->slug);
    }
}
Exemplo n.º 15
0
 /**
  * Adds a new post notification
  * @uses publish_post action
  * @param int $post_id
  * @param obj $post
  * @return void
  */
 public function add_notification($post_id, $post)
 {
     // Bail early if post_type isn't post or if post has already been published
     if (get_post_type($post) !== 'post' || $_POST['original_post_status'] == 'publish') {
         return;
     }
     // Get all subscribers
     $subscribers = get_option('bp_site_subscriber_subscribers', array());
     // Bail early if no subscribers
     if (empty($subscribers)) {
         return;
     }
     $subscribers = array_values($subscribers);
     $subscribers = array_unique($subscribers);
     $link = get_permalink($post_id);
     $title = get_the_title($post_id);
     $site_name = get_option('blogname');
     foreach ($subscribers as $subscriber) {
         if ($subscriber != $post->post_author && !in_array($subscriber, $sent)) {
             // Notify
             bp_core_add_notification($post_id, $subscriber, $this->id, 'new_post_' . $post_id, get_current_blog_id());
             // Mail
             if ('no' != bp_get_user_meta($subscriber, 'bp-site-subscriber-send-email', true)) {
                 $user = get_userdata($subscriber);
                 $email = $user->user_email;
                 $profile_link = bp_core_get_user_domain($subscriber);
                 $subject = sprintf(__('New post on the site %s', 'bp-site-subscriber'), $site_name);
                 $message = sprintf(__("New post %s (%s) on the site %s \n\n--------------------\n\n Go to your profile to disable these emails: %s", 'bp-site-subscriber'), $title, $link, $site_name, $profile_link);
                 wp_mail($email, $subject, $message);
             }
         }
     }
 }
Exemplo n.º 16
0
 protected function bp_gtm_edit_g_task($data)
 {
     global $bp, $wpdb;
     if (!check_admin_referer('bp_gtm_edit_task')) {
         return false;
     }
     $task_id = $_POST['task_id'];
     if (!$project_id) {
         $project_id = $_POST['task_project'];
     }
     $name = apply_filters('bp_gtm_task_name_content', $_POST['task_name']);
     $description = apply_filters('bp_gtm_task_desc_content', $_POST['task_desc']);
     $status = bp_gtm_get_project_status($project_id);
     // resps workaround
     if (!empty($_POST['user_ids'])) {
         $task_resps_old = $_POST['user_ids'];
         // array{ slaFFik: 0, bot1: 1, ... }
     } else {
         $task_resps_old = array();
     }
     $resps = (array) $task_resps_old;
     bp_gtm_change_user_group_role($change_roles, $project_id, $task_id);
     // todo smth with this:
     if (count($resps) > 0) {
         bp_gtm_save_g_resps($task_id, $_POST['task_project'], $_POST['task_group'], $resps);
         $task_resps = implode(' ', $resps);
         // make resps in a line to save in DB
     } else {
         $resps[] = bp_core_get_username($_POST['task_creator']);
         bp_gtm_save_g_resps($task_id, $_POST['task_project'], $_POST['task_group'], $resps);
         $task_resps = bp_core_get_username($_POST['task_creator']);
     }
     // update task
     $updated_task = $wpdb->query($wpdb->prepare("\n            UPDATE " . $bp->gtm->table_tasks . "\n            SET `name` = %s, `desc` = %s, `status` = %s, `resp_id` = %s, `project_id` = %d, `deadline` = %s\n            WHERE `group_id` = %d AND `id` = %d\n            ", $name, $description, $status, $task_resps, $_POST['task_project'], bp_gtm_covert_date($_POST['task_deadline']), $_POST['task_group'], $task_id));
     // delete old tags
     $updated_tag = $wpdb->query($wpdb->prepare("DELETE FROM " . $bp->gtm->table_taxon . " WHERE `task_id` = %d AND `taxon` = 'tag'", $task_id));
     // get rid of unnecessary chars in existed tags
     $this->bp_gtm_insert_term($_POST['task_tag_names'], '', $project_id, 'tag', $task_id);
     // update cats
     $updated_cat = $wpdb->query($wpdb->prepare("DELETE FROM " . $bp->gtm->table_taxon . " WHERE `task_id` = %d AND `taxon` = 'cat'", $task_id));
     $this->bp_gtm_insert_term($_POST['task_old_cats'], $_POST['project_cats'], $project_id, 'cat', $task_id);
     // display user message
     if ($updated_task != null || $updated_cat != null || $updated_tag != null) {
         if (count($resps) > 0) {
             foreach ((array) $resps as $resp) {
                 $resp_id = bp_core_get_userid($resp);
                 bp_core_add_notification($task_id, $resp_id, 'gtm', 'task_edited', $_POST['task_group']);
             }
         }
     }
     do_action('bp_gtm_save_discussion_post', 'task', $_POST['task_creator'], false, $task_id, false, $bp->groups->current_group->id);
     bp_core_add_message(__('Task data was successfully updated.', 'bp_gtm'));
     do_action('bp_gtm_edit_task', $_POST['task_group']);
     bp_core_redirect(bp_get_group_permalink($bp->groups->current_group) . $bp->gtm->slug . '/tasks/view/' . $task_id . '?action=edited');
 }
Exemplo n.º 17
0
/**
 * Checks if an Achievement's criteria has been met, and if it has, unlock the Achievement.
 * Achievements with an action count of 0 are, effectively, unlocked each time but only
 * the points are added to user's total.
 *
 * @global object $bp BuddyPress global settings
 * @param int $user_id
 * @param string $skip_validation Set to 'force' to skip Achievement validation, e.g. the Achievement is unlocked regardless of its criteria.
 * @since 2.0
 */
function dpa_maybe_unlock_achievement($user_id, $skip_validation = '')
{
    global $bp;
    $action_count = dpa_get_achievement_action_count();
    if (dpa_is_achievement_unlocked() && $action_count > 0) {
        return;
    }
    $counters = get_user_meta($user_id, 'achievements_counters', true);
    $achievement_id = dpa_get_achievement_id();
    $skip_validation = 'force' == $skip_validation;
    // No point saving a count of 1 if the action_count is 1.
    $unlocked = false;
    if (0 === $action_count || 1 == $action_count) {
        $unlocked = true;
    } elseif (!$skip_validation) {
        if (!$counters && !is_array($counters)) {
            $counters = array();
        }
        $counters[$achievement_id] += apply_filters('dpa_achievement_counter_increment_by', 1);
        update_user_meta($user_id, 'achievements_counters', $counters);
        do_action('dpa_achievement_counter_incremented');
    }
    if (!$unlocked && ($skip_validation || $counters[$achievement_id] >= $action_count)) {
        if (isset($counters[$achievement_id])) {
            unset($counters[$achievement_id]);
            update_user_meta($user_id, 'achievements_counters', $counters);
        }
        $unlocked = true;
    }
    // Update points, insert unlocked record into DB and send notifications.
    if ($unlocked) {
        dpa_points_increment(dpa_get_achievement_points(), $user_id);
        // Let Achievements with action_count == 0, which have already been unlocked, only increment points.
        if (dpa_is_achievement_unlocked() && 0 === $action_count) {
            return;
        }
        dpa_unlock_achievement($user_id);
        if (apply_filters('dpa_achievement_unlocked_tell_user', true, $achievement_id, $user_id)) {
            bp_core_add_notification($achievement_id, $user_id, $bp->achievements->id, 'new_achievement', $user_id);
            dpa_record_activity($user_id, dpa_format_activity($user_id, $achievement_id), $achievement_id);
        }
        do_action('dpa_achievement_unlocked', $achievement_id, $user_id);
    }
}
function messages_new_message($args = '')
{
    $defaults = array('sender_id' => bp_loggedin_user_id(), 'thread_id' => false, 'recipients' => false, 'subject' => false, 'content' => false, 'date_sent' => bp_core_current_time());
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    if (empty($sender_id) || empty($content)) {
        return false;
    }
    // Create a new message object
    $message = new BP_Messages_Message();
    $message->thread_id = $thread_id;
    $message->sender_id = $sender_id;
    $message->subject = $subject;
    $message->message = $content;
    $message->date_sent = $date_sent;
    // If we have a thread ID, use the existing recipients, otherwise use the recipients passed
    if (!empty($thread_id)) {
        $thread = new BP_Messages_Thread($thread_id);
        $message->recipients = $thread->get_recipients();
        // Strip the sender from the recipient list if they exist
        if (isset($message->recipients[$sender_id])) {
            unset($message->recipients[$sender_id]);
        }
        if (empty($message->subject)) {
            $message->subject = sprintf(__('Re: %s', 'buddypress'), $thread->messages[0]->subject);
        }
        // No thread ID, so make some adjustments
    } else {
        if (empty($recipients)) {
            return false;
        }
        if (empty($message->subject)) {
            $message->subject = __('No Subject', 'buddypress');
        }
        $recipient_ids = array();
        // Invalid recipients are added to an array, for future enhancements
        $invalid_recipients = array();
        // Loop the recipients and convert all usernames to user_ids where needed
        foreach ((array) $recipients as $recipient) {
            $recipient = trim($recipient);
            if (empty($recipient)) {
                continue;
            }
            $recipient_id = false;
            // input was numeric
            if (is_numeric($recipient)) {
                // do a check against the user ID column first
                if (bp_core_get_core_userdata((int) $recipient)) {
                    $recipient_id = (int) $recipient;
                } else {
                    if (bp_is_username_compatibility_mode()) {
                        $recipient_id = bp_core_get_userid((int) $recipient);
                    } else {
                        $recipient_id = bp_core_get_userid_from_nicename((int) $recipient);
                    }
                }
            } else {
                if (bp_is_username_compatibility_mode()) {
                    $recipient_id = bp_core_get_userid($recipient);
                } else {
                    $recipient_id = bp_core_get_userid_from_nicename($recipient);
                }
            }
            if (!$recipient_id) {
                $invalid_recipients[] = $recipient;
            } else {
                $recipient_ids[] = (int) $recipient_id;
            }
        }
        // Strip the sender from the recipient list if they exist
        if ($key = array_search($sender_id, (array) $recipient_ids)) {
            unset($recipient_ids[$key]);
        }
        // Remove duplicates
        $recipient_ids = array_unique((array) $recipient_ids);
        if (empty($recipient_ids)) {
            return false;
        }
        // Format this to match existing recipients
        foreach ((array) $recipient_ids as $i => $recipient_id) {
            $message->recipients[$i] = new stdClass();
            $message->recipients[$i]->user_id = $recipient_id;
        }
    }
    if ($message->send()) {
        // Send screen notifications to the recipients
        foreach ((array) $message->recipients as $recipient) {
            bp_core_add_notification($message->id, $recipient->user_id, 'messages', 'new_message');
        }
        // Send email notifications to the recipients
        messages_notification_new_message(array('message_id' => $message->id, 'sender_id' => $message->sender_id, 'subject' => $message->subject, 'content' => $message->message, 'recipients' => $message->recipients, 'thread_id' => $message->thread_id));
        do_action_ref_array('messages_message_sent', array(&$message));
        return $message->thread_id;
    }
    return false;
}
Exemplo n.º 19
0
function bp_checkins_send_screen_notification($author_id = false, $place_id = false, $user_id = false, $comment_id = false)
{
    if (empty($author_id) || empty($place_id) || empty($user_id)) {
        return false;
    }
    if ($author_id == $user_id) {
        return false;
    }
    bp_core_add_notification($place_id, $author_id, 'checkins', 'new_comment', $comment_id);
}
function groups_notification_group_invites(&$group, &$member, $inviter_user_id)
{
    global $bp;
    $inviter_ud = get_userdata($inviter_user_id);
    $inviter_name = bp_core_get_userlink($inviter_user_id, true, false, true);
    $inviter_link = site_url() . '/' . BP_MEMBERS_SLUG . '/' . $inviter_ud->user_login;
    $group_link = bp_get_group_permalink($group);
    if (!$member->invite_sent) {
        $invited_user_id = $member->user_id;
        // Post a screen notification first.
        bp_core_add_notification($group->id, $invited_user_id, 'groups', 'group_invite');
        if ('no' == get_usermeta($invited_user_id, 'notification_groups_invite')) {
            return false;
        }
        $invited_ud = get_userdata($invited_user_id);
        $settings_link = site_url() . '/' . BP_MEMBERS_SLUG . '/' . $invited_ud->user_login . '/settings/notifications';
        $invited_link = site_url() . '/' . BP_MEMBERS_SLUG . '/' . $invited_ud->user_login;
        $invites_link = $invited_link . '/' . $bp->groups->slug . '/invites';
        // Set up and send the message
        $to = $invited_ud->user_email;
        $subject = '[' . get_blog_option(1, 'blogname') . '] ' . sprintf(__('You have an invitation to the group: "%s"', 'buddypress'), stripslashes($group->name));
        $message = sprintf(__('One of your friends %s has invited you to the group: "%s".

To view your group invites visit: %s

To view the group visit: %s

To view %s\'s profile visit: %s

---------------------
', 'buddypress'), $inviter_name, stripslashes($group->name), $invites_link, $group_link, $inviter_name, $inviter_link);
        $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
        // Send it
        wp_mail($to, $subject, $message);
    }
}
Exemplo n.º 21
0
function bp_gtm_do_task_actions()
{
    global $bp, $wpdb;
    if ($_GET['action_type'] == 'complete') {
        $wpdb->query($wpdb->prepare("\n         UPDATE {$bp->gtm->table_tasks}\n         SET `done` = 1\n         WHERE `id` = {$_GET['task_id']} OR `parent_id` = {$_GET['task_id']}"));
        $task = BP_GTM_Tasks::get_task_by_id($_GET['task_id']);
        $resps = explode(' ', $task['0']->resp_id);
        foreach ($resps as $resp) {
            if ($resp != '') {
                $resp_id = bp_core_get_userid($resp);
                if ($resp_id != $bp->loggedin_user->id) {
                    bp_core_add_notification($_GET['task_id'], $resp_id, $bp->gtm->slug, 'task_done', $bp->groups->current_group->id);
                }
            }
        }
        echo 'completed';
    } elseif ($_GET['action_type'] == 'delete') {
        $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_tasks} WHERE `id` = %d AND `group_id` = %d", $_GET['task_id'], $bp->groups->current_group->id));
        $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_taxon} WHERE `task_id` = %d AND `group_id` = %d", $_GET['task_id'], $bp->groups->current_group->id));
        $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_resps} WHERE `task_id` = %d AND `group_id` = %d", $_GET['task_id'], $bp->groups->current_group->id));
        $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_discuss} WHERE `task_id` = %d AND `group_id` = %d", $_GET['task_id'], $bp->groups->current_group->id));
        $wpdb->query($wpdb->prepare("DELETE FROM {$bp->core->table_name_notifications} WHERE `item_id` = %d AND `secondary_item_id` = %d AND `component_name` = {$bp->gtm->slug} AND `component_action` LIKE `task_%%`", $_GET['task_id'], $bp->groups->current_group->id));
        $task = BP_GTM_Tasks::get_task_by_id($_GET['task_id']);
        $resps = explode(' ', $task['0']->resp_id);
        foreach ($resps as $resp) {
            if ($resp != '') {
                $resp_id = bp_core_get_userid($resp);
                if ($resp_id != $bp->loggedin_user->id) {
                    bp_core_add_notification($_GET['task_id'], $resp_id, $bp->gtm->slug, 'task_deleted', $bp->groups->current_group->id);
                }
            }
        }
        echo 'deleted';
    }
    die;
}
Exemplo n.º 22
0
function messages_send_message($recipients, $subject, $content, $thread_id, $from_ajax = false, $from_template = false, $is_reply = false)
{
    global $pmessage;
    global $message, $type;
    global $bp, $current_user;
    if (!check_admin_referer('messages_send_message')) {
        return false;
    }
    messages_add_callback_values($recipients, $subject, $content);
    if (isset($_POST['send-notice'])) {
        if (messages_send_notice($subject, $content, $from_template)) {
            bp_core_add_message(__('Notice posted successfully.', 'buddypress'));
        } else {
            bp_core_add_message(__('There was an error posting that notice.', 'buddypress'), 'error');
        }
        bp_core_redirect($bp->loggedin_user->domain . $bp->current_component . '/notices');
        return true;
    }
    $recipients = explode(' ', $recipients);
    // If there are no recipients
    if (count($recipients) < 1) {
        if (!$from_ajax) {
            bp_core_add_message(__('Please enter at least one valid user to send this message to.', 'buddypress'), 'error');
            bp_core_redirect($bp->loggedin_user->domain . $bp->current_component . '/compose');
        } else {
            return array('status' => 0, 'message' => __('There was an error sending the reply, please try again.', 'buddypress'));
        }
        // If there is only 1 recipient and it is the logged in user.
    } else {
        if (1 == count($recipients) && $recipients[0] == $current_user->user_login) {
            bp_core_add_message(__('You must send your message to one or more users not including yourself.', 'buddypress'), 'error');
            bp_core_redirect($bp->loggedin_user->domain . $bp->current_component . '/compose');
            // If the subject or content boxes are empty.
        } else {
            if (empty($subject) || empty($content)) {
                if (!$from_ajax) {
                    bp_core_add_message(__('Please make sure you fill in all the fields.', 'buddypress'), 'error');
                    bp_core_redirect($bp->loggedin_user->domain . $bp->current_component . '/compose');
                } else {
                    return array('status' => 0, 'message' => __('Please make sure you have typed a message before sending a reply.', 'buddypress'));
                }
                // Passed validation continue.
            } else {
                // Strip the logged in user from the recipient list if they exist
                if ($key = array_search($current_user->user_login, $recipients)) {
                    unset($recipients[$key]);
                }
                $pmessage = new BP_Messages_Message();
                $pmessage->sender_id = $bp->loggedin_user->id;
                $pmessage->subject = $subject;
                $pmessage->message = $content;
                $pmessage->thread_id = $thread_id;
                $pmessage->date_sent = time();
                $pmessage->message_order = 0;
                // TODO
                $pmessage->sender_is_group = 0;
                if ($is_reply) {
                    $thread = new BP_Messages_Thread($thread_id);
                    $pmessage->recipients = $thread->get_recipients();
                } else {
                    $pmessage->recipients = BP_Messages_Message::get_recipient_ids($recipients);
                }
                if (!is_null($pmessage->recipients)) {
                    if (!$pmessage->send()) {
                        $message = __('Message could not be sent, please try again.', 'buddypress');
                        $type = 'error';
                        if ($from_ajax) {
                            return array('status' => 0, 'message' => $message);
                        } else {
                            bp_core_add_message($message, $type);
                            bp_core_redirect($bp->loggedin_user->domain . $bp->current_component . '/compose');
                        }
                    } else {
                        $message = __('Message sent successfully!', 'buddypress') . ' <a href="' . $bp->loggedin_user->domain . $bp->messages->slug . '/view/' . $pmessage->thread_id . '">' . __('View Message', 'buddypress') . '</a> &raquo;';
                        $type = 'success';
                        // Send screen notifications to the recipients
                        for ($i = 0; $i < count($pmessage->recipients); $i++) {
                            if ($pmessage->recipients[$i] != $bp->loggedin_user->id) {
                                bp_core_add_notification($pmessage->id, $pmessage->recipients[$i], 'messages', 'new_message');
                            }
                        }
                        // Send email notifications to the recipients
                        require_once BP_PLUGIN_DIR . '/bp-messages/bp-messages-notifications.php';
                        messages_notification_new_message(array('item_id' => $pmessage->id, 'recipient_ids' => $pmessage->recipients, 'thread_id' => $pmessage->thread_id, 'component_name' => 'messages', 'component_action' => 'message_sent', 'is_private' => 1));
                        do_action('messages_send_message', array('item_id' => $pmessage->id, 'recipient_ids' => $pmessage->recipients, 'thread_id' => $pmessage->thread_id, 'component_name' => 'messages', 'component_action' => 'message_sent', 'is_private' => 1));
                        if ($from_ajax) {
                            return array('status' => 1, 'message' => $message, 'reply' => $pmessage);
                        } else {
                            bp_core_add_message($message);
                            bp_core_redirect($bp->loggedin_user->domain . $bp->current_component . '/inbox');
                        }
                    }
                } else {
                    $message = __('Message could not be sent, please try again.', 'buddypress');
                    $type = 'error';
                    if ($from_ajax) {
                        return array('status' => 0, 'message' => $message);
                    } else {
                        bp_core_add_message($message, $type);
                        bp_core_redirect($bp->loggedin_user->domain . $bp->messages->slug . '/compose');
                    }
                }
            }
        }
    }
}
Exemplo n.º 23
0
function bp_gtm_done_item()
{
    global $bp, $wpdb;
    if ($_GET['doneAction'] == 'done') {
        if ($_GET['doneType'] == 'projects') {
            $wpdb->query($wpdb->prepare("UPDATE " . $bp->gtm->table_projects . " SET `done` = '1' WHERE `id` = %d AND `group_id` = %d", $_GET['doneID'], $bp->groups->current_group->id));
            $wpdb->query($wpdb->prepare("UPDATE " . $bp->gtm->table_tasks . " SET `done` = '1' WHERE `project_id` = %d AND `group_id` = %d", $_GET['doneID'], $bp->groups->current_group->id));
            $project = BP_GTM_Projects::get_project_by_id($_GET['doneID']);
            $resps = explode(' ', $project['0']->resp_id);
            foreach ($resps as $resp) {
                if ($resp != '') {
                    $resp_id = bp_core_get_userid($resp);
                    if ($resp_id != $bp->loggedin_user->id) {
                        bp_core_add_notification($_GET['doneID'], $resp_id, $bp->gtm->slug, 'project_done', $bp->groups->current_group->id);
                    }
                }
            }
        } elseif ($_GET['doneType'] == 'tasks') {
            $wpdb->query($wpdb->prepare("UPDATE " . $bp->gtm->table_tasks . " SET `done` = '1' WHERE `id` = %d AND `group_id` = %d", $_GET['doneID'], $bp->groups->current_group->id));
            $wpdb->query($wpdb->prepare("UPDATE " . $bp->gtm->table_tasks . " SET `done` = '1' WHERE `parent_id` = %d AND `group_id` = %d", $_GET['doneID'], $bp->groups->current_group->id));
            $task = BP_GTM_Tasks::get_task_by_id($_GET['doneID']);
            $resps = explode(' ', $task['0']->resp_id);
            foreach ($resps as $resp) {
                if ($resp != '') {
                    $resp_id = bp_core_get_userid($resp);
                    if ($resp_id != $bp->loggedin_user->id) {
                        bp_core_add_notification($_GET['doneID'], $resp_id, $bp->gtm->slug, 'task_done', $bp->groups->current_group->id);
                    }
                }
            }
        }
    } elseif ($_GET['doneAction'] == 'undone') {
        if ($_GET['doneType'] == 'projects') {
            $wpdb->query($wpdb->prepare("UPDATE " . $bp->gtm->table_projects . " SET `done` = '0' WHERE `id` = %d AND `group_id` = %d", $_GET['doneID'], $bp->groups->current_group->id));
            //         $wpdb->query( $wpdb->prepare("UPDATE ".$bp->gtm->table_tasks." SET `done` = '0' WHERE `project_id` = %d AND `group_id` = %d", $_GET['doneID'], $bp->groups->current_group->id));
            $project = BP_GTM_Projects::get_project_by_id($_GET['doneID']);
            $resps = explode(' ', $project['0']->resp_id);
            foreach ($resps as $resp) {
                if ($resp != '') {
                    $resp_id = bp_core_get_userid($resp);
                    if ($resp_id != $bp->loggedin_user->id) {
                        bp_core_add_notification($_GET['doneID'], $resp_id, $bp->gtm->slug, 'project_undone', $bp->groups->current_group->id);
                    }
                }
            }
        } elseif ($_GET['doneType'] == 'tasks') {
            $wpdb->query($wpdb->prepare("UPDATE " . $bp->gtm->table_tasks . " SET `done` = '0' WHERE `id` = %d AND `group_id` = %d", $_GET['doneID'], $bp->groups->current_group->id));
            $task = BP_GTM_Tasks::get_task_by_id($_GET['doneID']);
            $resps = explode(' ', $task['0']->resp_id);
            foreach ($resps as $resp) {
                if ($resp != '') {
                    $resp_id = bp_core_get_userid($resp);
                    if ($resp_id != $bp->loggedin_user->id) {
                        bp_core_add_notification($_GET['doneID'], $resp_id, $bp->gtm->slug, 'task_undone', $bp->groups->current_group->id);
                    }
                }
            }
        }
    }
    return true;
}
Exemplo n.º 24
0
function messages_new_message( $args = '' ) {
	global $bp;

	$defaults = array(
		'thread_id' => false, // false for a new message, thread id for a reply to a thread.
		'sender_id' => $bp->loggedin_user->id,
		'recipients' => false, // Can be an array of usernames, user_ids or mixed.
		'subject' => false,
		'content' => false,
		'date_sent' => bp_core_current_time()
	);

	$r = wp_parse_args( $args, $defaults );
	extract( $r, EXTR_SKIP );

	if ( !$sender_id || !$content )
		return false;

	/* Create a new message object */
	$message = new BP_Messages_Message;
	$message->thread_id = $thread_id;
	$message->sender_id = $sender_id;
	$message->subject = $subject;
	$message->message = $content;
	$message->date_sent = $date_sent;

	// If we have a thread ID, use the existing recipients, otherwise use the recipients passed
	if ( $thread_id ) {
		$thread = new BP_Messages_Thread( $thread_id );
		$message->recipients = $thread->get_recipients();

		// Strip the sender from the recipient list if they exist
		if ( isset( $message->recipients[$sender_id] ) )
			unset( $message->recipients[$sender_id] );

		if ( empty( $message->subject ) )
			$message->subject = sprintf( __( 'Re: %s', 'buddypress' ), $thread->messages[0]->subject );

	// No thread ID, so make some adjustments
	} else {
		if ( empty( $recipients ) )
			return false;

		if ( empty( $message->subject ) )
			$message->subject = __( 'No Subject', 'buddypress' );

		/* Loop the recipients and convert all usernames to user_ids where needed */
		foreach( (array) $recipients as $recipient ) {
			if ( is_numeric( trim( $recipient ) ) )
				$recipient_ids[] = (int)trim( $recipient );

			if ( $recipient_id = bp_core_get_userid( trim( $recipient ) ) )
				$recipient_ids[] = (int)$recipient_id;
		}

		/* Strip the sender from the recipient list if they exist */
		if ( $key = array_search( $sender_id, (array)$recipient_ids ) )
			unset( $recipient_ids[$key] );

		/* Remove duplicates */
		$recipient_ids = array_unique( (array)$recipient_ids );

		if ( empty( $recipient_ids ) )
			return false;

		/* Format this to match existing recipients */
		foreach( (array)$recipient_ids as $i => $recipient_id ) {
			$message->recipients[$i] = new stdClass;
			$message->recipients[$i]->user_id = $recipient_id;
		}
	}

	if ( $message->send() ) {
		require_once( BP_PLUGIN_DIR . '/bp-messages/bp-messages-notifications.php' );

		// Send screen notifications to the recipients
		foreach ( (array)$message->recipients as $recipient )
			bp_core_add_notification( $message->id, $recipient->user_id, 'messages', 'new_message' );

		// Send email notifications to the recipients
		messages_notification_new_message( array( 'message_id' => $message->id, 'sender_id' => $message->sender_id, 'subject' => $message->subject, 'content' => $message->message, 'recipients' => $message->recipients, 'thread_id' => $message->thread_id) );

		do_action( 'messages_message_sent', &$message );

		return $message->thread_id;
	}

	return false;
}
/**
 * bp_example_send_high_five()
 *
 * Sends a high five message to a user. Registers an notification to the user
 * via their notifications menu, as well as sends an email to the user.
 *
 * Also records an activity stream item saying "User 1 high-fived User 2".
 */
function bp_example_send_highfive($to_user_id, $from_user_id)
{
    global $bp;
    check_admin_referer('bp_example_send_high_five');
    /**
     * We'll store high-fives as usermeta, so we don't actually need
     * to do any database querying. If we did, and we were storing them
     * in a custom DB table, we'd want to reference a function in
     * bp-example-classes.php that would run the SQL query.
     */
    delete_user_meta($to_user_id, 'high-fives');
    /* Get existing fives */
    $existing_fives = maybe_unserialize(get_user_meta($to_user_id, 'high-fives', true));
    /* Check to see if the user has already high-fived. That's okay, but lets not
     * store duplicate high-fives in the database. What's the point, right?
     */
    if (!in_array($from_user_id, (array) $existing_fives)) {
        $existing_fives[] = (int) $from_user_id;
        /* Now wrap it up and fire it back to the database overlords. */
        update_user_meta($to_user_id, 'high-fives', serialize($existing_fives));
        // Let's also record it in our custom database tables
        $db_args = array('recipient_id' => (int) $to_user_id, 'high_fiver_id' => (int) $from_user_id);
        $high_five = new BP_Example_Highfive($db_args);
        $high_five->save();
    }
    /***
     * Now we've registered the new high-five, lets work on some notification and activity
     * stream magic.
     */
    /***
     * Post a screen notification to the user's notifications menu.
     * Remember, like activity streams we need to tell the activity stream component how to format
     * this notification in bp_example_format_notifications() using the 'new_high_five' action.
     */
    bp_core_add_notification($from_user_id, $to_user_id, $bp->example->slug, 'new_high_five');
    /* Now record the new 'new_high_five' activity item */
    $to_user_link = bp_core_get_userlink($to_user_id);
    $from_user_link = bp_core_get_userlink($from_user_id);
    bp_example_record_activity(array('type' => 'rejected_terms', 'action' => apply_filters('bp_example_new_high_five_activity_action', sprintf(__('%s high-fived %s!', 'bp-example'), $from_user_link, $to_user_link), $from_user_link, $to_user_link), 'item_id' => $to_user_id));
    /* We'll use this do_action call to send the email notification. See bp-example-notifications.php */
    do_action('bp_example_send_high_five', $to_user_id, $from_user_id);
    return true;
}