コード例 #1
0
ファイル: functions.php プロジェクト: rlybbert/achievements
/**
 * When an achievement is unlocked, give the points to the user.
 *
 * @param WP_Post $achievement_obj The Achievement object to send a notification for.
 * @param int $user_id ID of the user who unlocked the achievement.
 * @param int $progress_id The Progress object's ID.
 * @since Achievements (3.0)
 */
function dpa_send_points(WP_Post $achievement_obj, $user_id, $progress_id)
{
    // Let other plugins easily bypass sending points.
    if (!apply_filters('dpa_maybe_send_points', true, $achievement_obj, $user_id, $progress_id)) {
        return;
    }
    // Get the user's current total points plus the point value for the unlocked achievement
    $points = dpa_get_user_points($user_id) + dpa_get_achievement_points($achievement_obj->ID);
    $points = apply_filters('dpa_send_points_value', $points, $achievement_obj, $user_id, $progress_id);
    // Give points to user
    dpa_update_user_points($points, $user_id);
    // Allow other things to happen after the user's points have been updated
    do_action('dpa_send_points', $achievement_obj, $user_id, $progress_id, $points);
}
コード例 #2
0
</a></h2>

	<p>
		<?php 
if (dpa_is_achievement_a_badge()) {
    ?>
			<span class="highlight"><?php 
    _e('Award', 'dpa');
    ?>
</span>&nbsp;
		<?php 
}
?>

		<span class="highlight"><?php 
printf(_n("%s point", "%s points", bp_core_number_format(dpa_get_achievement_points()), 'dpa'), bp_core_number_format(dpa_get_achievement_points()));
?>
</span>&nbsp;

		<?php 
if (!dpa_get_achievement_is_active() && dpa_permission_can_user_edit()) {
    ?>
			<span class="highlight"><?php 
    _e('Inactive Achievement', 'dpa');
    ?>
</span>&nbsp;
		<?php 
}
?>

		<span class="activity"><?php 
コード例 #3
0
    /**
     * Outputs the HTML for this widget.
     *
     * @global DPA_Achievement_Template $achievements_template Achievements template tag object
     * @global object $bp BuddyPress global settings
     * @param array $args An array of standard parameters for widgets
     * @param array $instance An array of settings for this widget instance
     * @since 2.0
     */
    function widget($args, $instance)
    {
        global $achievements_template, $bp;
        extract($args, EXTR_SKIP);
        if (dpa_has_achievements(array('slug' => $instance['achievement_slug'], 'populate_extras' => false, 'type' => 'single'))) {
            echo $before_widget;
            if ($instance['title']) {
                echo $before_title;
                echo esc_html(apply_filters('dpa_widget_title', $instance['title']));
                echo $after_title;
            }
            ?>

			<?php 
            while (dpa_achievements()) {
                dpa_the_achievement();
                ?>

				<div class="item-avatar">
					<a href="<?php 
                dpa_achievement_slug_permalink();
                ?>
"><?php 
                dpa_achievement_picture();
                ?>
</a>
					<div class="item-title"><a href="<?php 
                dpa_achievement_slug_permalink();
                ?>
"><?php 
                dpa_achievement_name();
                ?>
</a></div>
					<div class="item-meta"><span class="activity"><?php 
                printf(__("%s points", 'dpa'), bp_core_number_format(dpa_get_achievement_points()));
                ?>
</span></div>

					<div class="item-desc"><?php 
                dpa_achievement_description_excerpt();
                ?>
</div>
				</div>

			<?php 
            }
            ?>

			<p class="achievements-widget-showall"><a href="<?php 
            dpa_achievement_slug_permalink();
            ?>
"><?php 
            _e('Show More', 'dpa');
            ?>
</a></p>
			<div style="clear: right;"></div>

		<?php 
            echo $after_widget;
        }
        $achievements_template = null;
    }
コード例 #4
0
/**
 * Template tag version of dpa_achievement_points()
 *
 * @uses dpa_get_achievement_points()
 * @since 2.0
 */
function dpa_achievement_points()
{
    echo bp_core_number_format(dpa_get_achievement_points());
}
コード例 #5
0
        dpa_achievement_directory_class();
        ?>
">
			<div class="item-avatar">
				<a href="<?php 
        dpa_achievement_slug_permalink();
        ?>
"><?php 
        dpa_achievement_picture();
        ?>
</a>
				<p style="width: <?php 
        dpa_achievement_picture_width();
        ?>
px" title="<?php 
        printf(__("This Achievement is worth %s points.", 'dpa'), bp_core_number_format(dpa_get_achievement_points()));
        ?>
"><?php 
        dpa_achievement_points();
        ?>
</p>
			</div>

			<div class="item">
				<div class="item-title"><a href="<?php 
        dpa_achievement_slug_permalink();
        ?>
"><?php 
        dpa_achievement_name();
        ?>
</a></div>
コード例 #6
0
ファイル: template.php プロジェクト: rlybbert/achievements
/**
 * Output the points value of the achievement.
 *
 * @param int $achievement_id Optional. Achievement ID
 * @since Achievements (1.0)
 */
function dpa_achievement_points($achievement_id = 0)
{
    echo number_format_i18n(dpa_get_achievement_points($achievement_id));
}
コード例 #7
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);
    }
}
コード例 #8
0
ファイル: functions.php プロジェクト: rlybbert/achievements
/**
 * Achievements metabox
 *
 * Contains fields to set the karma points, pick between action/event, and the list of events.
 *
 * @param WP_Post $post The post being added or edited
 * @since Achievements (3.0)
 */
function dpa_achievement_metabox(WP_Post $post)
{
    // Get all events grouped by the extension which provided them
    $events = dpa_get_all_events_details();
    // Get existing values (if this is an edit)
    $existing_points = dpa_get_achievement_points($post->ID);
    $existing_target = dpa_get_achievement_target($post->ID);
    $existing_events = wp_get_post_terms($post->ID, dpa_get_event_tax_id(), array('fields' => 'ids'));
    $existing_type = empty($existing_events) && !empty($_GET['action']) && 'edit' === $_GET['action'] ? 'award' : 'event';
    $existing_code = dpa_get_achievement_redemption_code($post->ID);
    // Ensure sane defaults
    if (empty($existing_points)) {
        $existing_points = 0;
    }
    if (empty($existing_target)) {
        $existing_target = 1;
    }
    ?>

	<div class="misc-pub-section dpa-karma">
		<label for="dpa-points"><?php 
    _e('Karma points:', 'achievements');
    ?>
</label>
		<input type="number" name="dpa_points" id="dpa-points" value="<?php 
    echo esc_attr($existing_points);
    ?>
" />
	</div>

	<div class="misc-pub-section dpa-type">
		<label for="dpa_type"><?php 
    _ex('Type:', 'type of achievement', 'achievements');
    ?>
</label>
		<input type="radio" name="dpa_type" id="dpa-type-award" value="award" <?php 
    checked($existing_type, 'award');
    ?>
><?php 
    _ex('&nbsp;Award', 'type of achievement', 'achievements');
    ?>
</input>
		<input type="radio" name="dpa_type" id="dpa-type-event" value="event" <?php 
    checked($existing_type, 'event');
    ?>
><?php 
    _ex('&nbsp;Event', 'type of achievement', 'achievements');
    ?>
</input>

		<p class="hint"><?php 
    _e("An <em>award</em> is given by a site admin, whereas an <em>event</em> is unlocked automatically when its criteria have been met.", 'achievements');
    ?>
</p>

		<select id="dpa-event" name="dpa_event[]" style="visibility: hidden" data-placeholder="<?php 
    esc_attr_e('Press here to pick events', 'achievements');
    ?>
" class="chzn-select <?php 
    if (is_rtl()) {
        echo 'chzn-rtl';
    }
    ?>
" multiple="multiple">
			<option value=""></option>

			<?php 
    foreach ($events as $extension => $extension_events) {
        ?>
				<optgroup label="<?php 
        echo esc_attr($extension);
        ?>
">

				<?php 
        foreach ($extension_events as $event) {
            ?>
					<option value="<?php 
            echo esc_attr($event['id']);
            ?>
" <?php 
            selected(in_array($event['id'], $existing_events), true);
            ?>
><?php 
            echo esc_html($event['description']);
            ?>
</option>
				<?php 
        }
        ?>

				</optgroup>
			<?php 
    }
    ?>

		</select>
	</div>

	<div class="misc-pub-section dpa-target">
		<label for="dpa_target"><?php 
    _ex('Events repeat:', "Number of times an achievement&#8217;s events need to repeat before the achievement is awarded", 'achievements');
    ?>
</label>
		<input type="number" name="dpa_target" id="dpa-target" min="1" value="<?php 
    echo esc_attr($existing_target);
    ?>
" />

		<p class="hint"><?php 
    _e("Number of times the events need to repeat before the achievement is awarded.", 'achievements');
    ?>
</p>
	</div>

	<div class="misc-pub-section dpa-redemption-code">
		<label for="dpa-code"><?php 
    _e('Redemption code:', 'achievements');
    ?>
</label>
		<input id="dpa-code" value="<?php 
    echo esc_attr($existing_code);
    ?>
" name="dpa_code" type="text" />

		<p class="hint"><?php 
    _e("Users can enter this code into the Redemption widget to unlock the achievement.", 'achievements');
    ?>
</p>
	</div>

	<?php 
    wp_nonce_field('dpa_achievement_metabox_save', 'dpa_achievement_metabox');
    do_action('dpa_achievement_metabox');
}