function bp_links_at_message_notification($content, $poster_user_id, $link_id, $activity_id)
{
    global $bp;
    /* Scan for @username strings in an activity update. Notify each user. */
    $pattern = '/[@]+([A-Za-z0-9-_]+)/';
    preg_match_all($pattern, $content, $usernames);
    /* Make sure there's only one instance of each username */
    if (!($usernames = array_unique($usernames[1]))) {
        return false;
    }
    $link = new BP_Links_Link($link_id);
    foreach ((array) $usernames as $username) {
        if (!($receiver_user_id = bp_core_get_userid($username))) {
            continue;
        }
        if (!bp_links_is_link_visibile($link, $receiver_user_id)) {
            continue;
        }
        // Now email the user with the contents of the message (if they have enabled email notifications)
        if ('no' != get_usermeta($user_id, 'notification_activity_new_mention')) {
            $poster_name = bp_core_get_user_displayname($poster_user_id);
            $message_link = bp_activity_get_permalink($activity_id);
            $settings_link = bp_core_get_user_domain($receiver_user_id) . 'settings/notifications/';
            // Set up and send the message
            $ud = bp_core_get_core_userdata($receiver_user_id);
            $to = $ud->user_email;
            $subject = '[' . get_blog_option(BP_ROOT_BLOG, 'blogname') . '] ' . sprintf(__('%s mentioned you in the link "%s"', 'buddypress-links'), stripslashes($poster_name), wp_filter_kses(stripslashes($link->name)));
            $message = sprintf(__('%s mentioned you in the link "%s":

"%s"

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

---------------------
', 'buddypress-links'), $poster_name, wp_filter_kses(stripslashes_deep($link->name)), wp_filter_kses(stripslashes_deep($content)), $message_link);
            $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
            // Send it
            wp_mail($to, $subject, $message);
        }
    }
}
function bp_link_is_visible($link = false)
{
    global $bp, $links_template;
    if (!$link) {
        $link =& $links_template->link;
    }
    return bp_links_is_link_visibile($link);
}
Esempio n. 3
0
/**
 * Cast a user vote for a link
 * 
 * Returns a BP_Links_Link object on successful vote
 * in case you need immediate access to the link data
 *
 * @see BP_Links_Link
 * @param integer $link_id
 * @param string $up_or_down "up" or "down"
 * @return BP_Links_Link|false
 */
function bp_links_cast_vote($link_id, $up_or_down)
{
    global $bp;
    $bp->links->current_link = new BP_Links_Link($link_id, true);
    if (false === bp_links_is_link_visibile($bp->links->current_link)) {
        return false;
    }
    $vote = $bp->links->current_link->vote();
    if (!$vote instanceof BP_Links_Vote) {
        return false;
    }
    // determine if member has voted for this link already
    $is_first_vote = is_numeric($vote->vote) ? false : true;
    // the default behavior is to allow members to change their vote,
    // which can be overriden with the configuration constant you see passed
    // to the filter below. use this filter to override the `configured` behavior
    // for special circumstances. you must return a boolean value!
    $allow_change = (bool) apply_filters('bp_links_cast_vote_allow_change', (bool) BP_LINKS_VOTE_ALLOW_CHANGE, $vote);
    // member can vote if its first time, or they are allowed to change vote
    if ($is_first_vote || $allow_change) {
        // the default behavior is to record vote activity.
        // this can be overriden with the configuration constant you see below.
        if ((bool) BP_LINKS_VOTE_RECORD_ACTIVITY === true) {
            // the default behavior is to only record activity if this is their
            // original vote. use the filter below to override this behavior.
            // you must return a boolean value!
            $record_activity = (bool) apply_filters('bp_links_cast_vote_record_activity', $is_first_vote, $vote);
        } else {
            // do not record activity per configuration constant
            $record_activity = false;
        }
        switch ($up_or_down) {
            case 'up':
                $vote->up();
                break;
            case 'down':
                $vote->down();
                break;
            default:
                return false;
        }
        if (true === $bp->links->current_link->save()) {
            if ($record_activity) {
                // translate up or down string
                $up_or_down_translated = 'up' == $up_or_down ? __('up', 'buddypress-links') : __('down', 'buddypress-links');
                // record the activity
                $activity_action = sprintf(__('%1$s voted %2$s the link %3$s', 'buddypress-links'), bp_core_get_userlink($bp->loggedin_user->id), $up_or_down_translated, '<a href="' . bp_get_link_permalink($bp->links->current_link) . '">' . attribute_escape($bp->links->current_link->name) . '</a>');
                bp_links_record_activity(array('action' => apply_filters('bp_links_activity_voted', $activity_action), 'primary_link' => apply_filters('bp_links_activity_voted_primary_link', bp_get_link_permalink($bp->links->current_link)), 'type' => BP_LINKS_ACTIVITY_ACTION_VOTE, 'item_id' => $bp->links->current_link->id));
            }
            do_action('bp_links_cast_vote_success', $bp->links->current_link->id);
            // return the link object
            return $bp->links->current_link;
        } else {
            return false;
        }
    } else {
        // member not allowed change vote
        // this is not an error, so return true!
        return true;
    }
}