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);
 }
/**
 * The format notification function takes DB entries for notifications and formats them so that they can be
 * displayed and read on the screen.
 *
 * @since 2.0
 * @see bp_core_add_notification()
 * @uses DPA_Achievement
 * @global DPA_Achievement_Template $achievements_template Achievements template tag object
 * @global object $bp BuddyPress global settings
 * @global nxtdb $nxtdb NXTClass database object
 * @param string $action Type of notification
 * @param int $item_id Achievement ID
 * @param int $secondary_item_id User ID
 * @param int $total_items Number of pending notifications of this type
 */
function dpa_format_notifications($action, $item_id, $secondary_item_id, $total_items, $format = 'string')
{
    global $achievements_template, $bp, $nxtdb;
    do_action('dpa_format_notifications', $action, $item_id, $secondary_item_id, $total_items, $format);
    switch ($action) {
        case 'new_achievement':
            if (1 == $total_items) {
                $achievements_template->achievement = new DPA_Achievement(array('id' => $item_id, 'populate_extras' => false));
                $text = sprintf(__('Achievement unlocked: %s', 'dpa'), dpa_get_achievement_name());
                $link = dpa_get_achievement_slug_permalink();
                unset($achievements_template->achievement);
            } else {
                $text = __('Achievements unlocked!', 'dpa');
                $link = bp_core_get_user_domain($secondary_item_id) . DPA_SLUG . '/' . DPA_SLUG_MY_ACHIEVEMENTS;
            }
            break;
    }
    if ('string' == $format) {
        return apply_filters('dpa_new_achievement_notification', '<a href="' . $link . '">' . $text . '</a>', $item_id, $secondary_item_id, $total_items);
    } else {
        $array = array('text' => $text, 'link' => $link);
        return apply_filters('dpa_new_achievement_notification', $array, $item_id, $secondary_item_id, $total_items);
    }
}
/**
 * Returns the on-hover Quick Admin controls which appear for admin users on the Directory pages
 *
 * @since 2.0
 * @global object $bp BuddyPress global settings
 * @return string
 */
function dpa_get_achievements_quickadmin()
{
    global $bp;
    $items = array();
    if (!dpa_is_directory_page()) {
        return apply_filters('dpa_get_achievements_quickadmin', '', $items);
    }
    $url = dpa_get_achievement_slug_permalink();
    if (dpa_permission_can_user_change_picture()) {
        $items[] = sprintf('<a href="%1$s">%2$s</a>', $url . DPA_SLUG_ACHIEVEMENT_CHANGE_PICTURE, __('Change Picture', 'dpa'));
    }
    if (dpa_permission_can_user_delete()) {
        $items[] = sprintf('<a href="%1$s">%2$s</a>', $url . DPA_SLUG_ACHIEVEMENT_DELETE, __('Delete', 'dpa'));
    }
    if (dpa_permission_can_user_edit()) {
        $items[] = sprintf('<a href="%1$s">%2$s</a>', $url . DPA_SLUG_ACHIEVEMENT_EDIT, __('Edit', 'dpa'));
    }
    if (dpa_permission_can_user_grant()) {
        $items[] = sprintf('<a href="%1$s">%2$s</a>', $url . DPA_SLUG_ACHIEVEMENT_GRANT, __('Give', 'dpa'));
    }
    if (!$items) {
        return apply_filters('dpa_get_achievements_quickadmin', '', $items);
    }
    return apply_filters('dpa_get_achievements_quickadmin', '<span>' . implode('</span> | <span>', $items) . '</span>', $items);
}
Esempio n. 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));
}