コード例 #1
0
 function buddystream_achievement_unlocked($achievement_id, $user_id)
 {
     $content = __('I just unlocked the', 'buddystream_lang') . " " . dpa_get_achievement_name() . " " . __('achievement!', 'buddystream');
     if (get_user_meta($user_id, 'tweetstream_achievements', 1)) {
         $content = "#twitter " . $content;
     }
     if (get_user_meta($user_id, 'facestream_achievements', 1)) {
         $content = "#facebook " . $content;
     }
     $shortLink = buddystream_getShortUrl(dpa_get_achievement_slug_permalink());
     buddystream_SocialIt($content, $shortLink, $user_id);
 }
コード例 #2
0
/**
 * Sends the email notification to the user when an Achievement is unlocked.
 *
 * @global object $bp BuddyPress global settings
 * @global nxtdb $nxtdb NXTClass database object
 * @param int $achievement_id
 * @param int $user_id
 * @since 2.0
 */
function dpa_achievement_unlocked_notification($achievement_id, $user_id)
{
    global $achievements_template, $bp, $nxtdb;
    if ('no' == get_user_meta($user_id, 'notification_dpa_unlock_achievement', true)) {
        return;
    }
    $recipient = get_userdata($user_id);
    $settings_link = bp_core_get_user_domain($user_id) . bp_get_settings_slug() . '/notifications/';
    $achievements_link = bp_core_get_user_domain($user_id) . DPA_SLUG . '/';
    $email_subject = sprintf(__('[%1$s] Achievement unlocked: %2$s', 'dpa'), nxt_specialchars_decode(get_blog_option(BP_ROOT_BLOG, 'blogname'), ENT_QUOTES), dpa_get_achievement_name());
    $email_content = sprintf(__('
You have unlocked an Achievement: %1$s

To review this and see all of your Achievements, go to %2$s

---------------------
To disable these notifications please log in and go to: %3$s', 'dpa'), dpa_get_achievement_name(), $achievements_link, $settings_link);
    // Send the message
    $email_to = apply_filters('dpa_unlock_achievement_notification_to', $recipient->user_email, $achievement_id);
    $email_subject = apply_filters('dpa_unlock_achievement_notification_subject', $email_subject, $achievement_id);
    $email_content = apply_filters('dpa_unlock_achievement_notification_message', $email_content, $achievement_id, $achievements_link, $settings_link);
    nxt_mail($email_to, $email_subject, $email_content);
}
コード例 #3
0
/**
 * Returns Achievement's picture; takes into account size of image required
 *
 * @since 2.0
 * @global DPA_Achievement_Template $achievements_template Achievements template tag object
 * @global int $blog_id Site ID
 * @global object $bp BuddyPress global settings
 * @param string $size Optional; set to "thumb" to fetch thumbnail-sized picture, and "activitystream" for a thumbnail-sized picture with width/height style tags.
 * @return string HTML image tag
 */
function dpa_get_achievement_picture($size = '')
{
    global $achievements_template, $blog_id, $bp;
    $achievement_slug = dpa_get_achievement_slug();
    $achievement_id = dpa_get_achievement_id();
    if ('thumb' == $size || 'activitystream' == $size) {
        $is_thumbnail = true;
    } else {
        $is_thumbnail = dpa_get_achievement_picture_is_thumbnail();
    }
    if (($picture_id = dpa_get_achievement_picture_id()) < 1) {
        if (empty($bp->grav_default->user)) {
            $default_grav = 'wavatar';
        } elseif ('mystery' == $bp->grav_default->user) {
            $default_grav = apply_filters('bp_core_mysteryman_src', BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg');
        } else {
            $default_grav = $bp->grav_default->user;
        }
        if ('thumb' == $size) {
            $grav_size = apply_filters('dpa_get_achievement_picture_gravatar_width', BP_AVATAR_THUMB_WIDTH, 'thumb');
        } elseif ('activitystream' == $size) {
            $grav_size = apply_filters('dpa_get_achievement_picture_gravatar_width', 20, 'activitystream');
        } else {
            $grav_size = apply_filters('dpa_get_achievement_picture_gravatar_width', BP_AVATAR_FULL_WIDTH, 'full');
        }
        $email = apply_filters('bp_core_gravatar_email', $achievement_slug . '@' . $bp->root_domain, $achievement_id, 'achievements');
        if (is_ssl()) {
            $host = 'https://secure.gravatar.com/avatar/';
        } else {
            $host = 'http://www.gravatar.com/avatar/';
        }
        $avatar_url = apply_filters('bp_gravatar_url', $host) . md5($email) . '?d=' . $default_grav . '&amp;s=' . $grav_size;
    } else {
        if ($cached_urls = nxt_cache_get('dpa_achievement_picture_urls', 'dpa') && isset($cached_urls) && is_array($cached_urls) && isset($cached_urls[$picture_id]) && $cached_urls[$picture_id]) {
            $avatar_url = $cached_urls[$picture_id];
        } else {
            if ($is_nonroot_multisite = is_multisite() && BP_ROOT_BLOG != $blog_id) {
                switch_to_blog(BP_ROOT_BLOG);
            }
            // Necessary evil
            list($avatar_url, $avatar_width, $avatar_height, $is_intermediate) = image_downsize($picture_id, 'large');
            if ($is_nonroot_multisite) {
                restore_current_blog();
            }
            if (!is_array($cached_urls)) {
                $cached_urls = array($picture_id => $avatar_url);
            } else {
                $cached_urls[$picture_id] = $avatar_url;
            }
            $grav_size = 0;
            nxt_cache_set('dpa_achievement_picture_urls', $cached_urls, 'dpa');
        }
    }
    $style = '';
    if ('activitystream' == $size && ('mystery' == $bp->grav_default->user || $picture_id > 0)) {
        $style = 'width="20" height="20"';
    }
    if ($is_thumbnail) {
        $picture_type = "avatar-thumbnail";
    } else {
        $picture_type = "avatar-full";
    }
    $url = '<img src="' . esc_url($avatar_url) . '" alt="' . esc_attr(dpa_get_achievement_name()) . '" title="' . esc_attr(dpa_get_achievement_name()) . '" ' . $style . ' class="avatar' . esc_attr(' achievement-' . $achievement_slug . '-avatar ') . $picture_type . '" />';
    return apply_filters('dpa_get_achievement_picture', $url, $achievement_id, $picture_id, $grav_size, $style);
}
コード例 #4
0
/**
 * Adds entries to the activity stream.
 * Has to be called from within the Achievement template loop.
 *
 * @global object $bp BuddyPress global settings
 * @param int $user_id
 * @param string $content The main text of the activity stream item; see dpa_format_activity()
 * @param int $item_id Achievement ID
 * @param string $component_action Optional; activity stream action name
 * @see dpa_format_activity
 * @since 2.0
 */
function dpa_record_activity($user_id, $content, $item_id, $component_action = 'new_achievement')
{
    global $bp;
    if (!bp_is_active('activity')) {
        return false;
    }
    $permalink = dpa_get_achievement_slug_permalink();
    switch ($component_action) {
        default:
        case 'new_achievement':
            $entry = array('action' => sprintf(__('%1$s unlocked %2$s', 'dpa'), bp_core_get_userlink($user_id), '<a href="' . $permalink . '">' . dpa_get_achievement_picture('activitystream') . '</a><a href="' . $permalink . '">' . dpa_get_achievement_name() . '</a>'), 'component' => $bp->achievements->id, 'type' => $component_action, 'primary_link' => bp_core_get_user_domain($user_id), 'user_id' => $user_id, 'item_id' => $item_id);
            break;
        case 'achievement_created':
            $entry = array('action' => sprintf(__('%1$s created the Achievement %2$s', 'dpa'), bp_core_get_userlink($user_id), '<a href="' . $permalink . '">' . dpa_get_achievement_name() . '</a>'), 'component' => $bp->achievements->id, 'type' => $component_action, 'primary_link' => bp_core_get_user_domain($user_id), 'user_id' => $user_id, 'item_id' => $item_id);
            break;
    }
    return bp_activity_add(apply_filters('dpa_record_activity', $entry, $user_id, $content, $item_id, $component_action));
}