Beispiel #1
0
/**
 * The Progress post type loop.
 *
 * @param array|string $args All the arguments supported by {@link WP_Query}, and some more.
 * @return bool Returns true if the query has any results to loop over
 * @since Achievements (3.0)
 */
function dpa_has_progress($args = array())
{
    // If multisite and running network-wide, switch_to_blog to the data store site
    if (is_multisite() && dpa_is_running_networkwide()) {
        switch_to_blog(DPA_DATA_STORE);
    }
    $defaults = array('ignore_sticky_posts' => true, 'max_num_pages' => false, 'order' => 'DESC', 'orderby' => 'date', 'paged' => dpa_get_paged(), 'post_status' => dpa_get_unlocked_status_id(), 'post_type' => dpa_get_progress_post_type(), 's' => '', 'author' => dpa_is_single_user_achievements() ? dpa_get_displayed_user_id() : null, 'post_parent' => dpa_is_single_achievement() ? dpa_get_achievement_id() : null, 'posts_per_page' => -1, 'ach_populate_achievements' => dpa_is_single_user_achievements() && is_a(achievements()->achievement_query, 'WP_Query') && empty(achievements()->achievement_query->request));
    $args = dpa_parse_args($args, $defaults, 'has_progress');
    // Run the query
    achievements()->progress_query = new WP_Query($args);
    // If no limit to posts per page, set it to the current post_count
    if (-1 === (int) $args['posts_per_page']) {
        $args['posts_per_page'] = achievements()->progress_query->post_count;
    }
    // Add pagination values to query object
    achievements()->progress_query->posts_per_page = $args['posts_per_page'];
    achievements()->progress_query->paged = $args['paged'];
    // Only add pagination if query returned results
    if (((int) achievements()->progress_query->post_count || (int) achievements()->progress_query->found_posts) && (int) achievements()->progress_query->posts_per_page) {
        // Limit the number of achievements shown based on maximum allowed pages
        if (!empty($args['max_num_pages']) && achievements()->progress_query->found_posts > achievements()->progress_query->max_num_pages * achievements()->progress_query->post_count) {
            achievements()->progress_query->found_posts = achievements()->progress_query->max_num_pages * achievements()->progress_query->post_count;
        }
        // If pretty permalinks are enabled, make our pagination pretty
        if ($GLOBALS['wp_rewrite']->using_permalinks()) {
            // Page or single post
            if (is_page() || is_single()) {
                $base = get_permalink();
            } elseif (dpa_is_single_user_achievements()) {
                $base = dpa_get_user_avatar_link(array('type' => 'url', 'user_id' => dpa_get_displayed_user_id()));
            } else {
                $base = get_permalink($args['post_parent']);
            }
            // Use pagination base
            $base = trailingslashit($base) . user_trailingslashit($GLOBALS['wp_rewrite']->pagination_base . '/%#%/');
            // Unpretty pagination
        } else {
            $base = add_query_arg('paged', '%#%');
        }
        // Pagination settings with filter
        $progress_pagination = apply_filters('dpa_progress_pagination', array('base' => $base, 'current' => (int) achievements()->progress_query->paged, 'format' => '', 'mid_size' => 1, 'next_text' => is_rtl() ? '←' : '→', 'prev_text' => is_rtl() ? '→' : '←', 'total' => $args['posts_per_page'] == achievements()->progress_query->found_posts ? 1 : ceil((int) achievements()->progress_query->found_posts / (int) $args['posts_per_page'])));
        // Add pagination to query object
        achievements()->progress_query->pagination_links = paginate_links($progress_pagination);
        // Remove first page from pagination
        achievements()->progress_query->pagination_links = str_replace($GLOBALS['wp_rewrite']->pagination_base . "/1/'", "'", achievements()->progress_query->pagination_links);
    }
    // If on a user's achievements page, we need to fetch the achievements
    if ($args['ach_populate_achievements'] && achievements()->progress_query->have_posts()) {
        $achievement_ids = wp_list_pluck((array) achievements()->progress_query->posts, 'post_parent');
        $achievement_args = array('order' => $args['order'], 'orderby' => $args['orderby'], 'post__in' => $achievement_ids, 'posts_per_page' => -1);
        // Run the query
        dpa_has_achievements($achievement_args);
    }
    // If multisite and running network-wide, undo the switch_to_blog
    if (is_multisite() && dpa_is_running_networkwide()) {
        restore_current_blog();
    }
    return apply_filters('dpa_has_progress', achievements()->progress_query->have_posts());
}
 *
 */
// Exit if accessed directly
if (!defined('ABSPATH')) {
    exit;
}
?>

<div id="dpa-achievements">

	<?php 
do_action('dpa_template_before_achievements_index');
?>

	<?php 
if (dpa_has_achievements()) {
    ?>

		<?php 
    dpa_achievements_index_description();
    ?>

		<?php 
    dpa_get_template_part('pagination-achievements');
    ?>

		<?php 
    dpa_get_template_part('loop-achievements');
    ?>

		<?php 
    /**
     * 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;
        if ($instance['loggedin_user'] && empty($bp->loggedin_user->id) || !$instance['loggedin_user'] && empty($bp->displayed_user->id)) {
            return;
        }
        if ($instance['loggedin_user']) {
            $user_id = $bp->loggedin_user->id;
        } else {
            $user_id = $bp->displayed_user->id;
        }
        extract($args, EXTR_SKIP);
        if (dpa_has_achievements(array('user_id' => $user_id, 'max' => $instance['limit'], 'populate_extras' => false, 'type' => 'locked'))) {
            echo $before_widget;
            if ($instance['title']) {
                echo $before_title;
                echo esc_html(apply_filters('dpa_widget_title', $instance['title']));
                echo $after_title;
            }
            ?>

			<div class="avatar-block">
				<?php 
            while (dpa_achievements()) {
                dpa_the_achievement();
                ?>
					<div class="item-avatar">
						<a href="<?php 
                dpa_achievement_slug_permalink();
                ?>
"><?php 
                dpa_achievement_picture();
                ?>
</a>
					</div>
				<?php 
            }
            ?>
			</div>

		<?php 
            echo $after_widget;
        }
        $achievements_template = null;
    }
Beispiel #4
0
    	
    		<?php 
if (isset($lok_options['lok_breadcrumbs_show']) && $lok_options['lok_breadcrumbs_show'] == 'true' && !is_front_page()) {
    ?>
				<section id="breadcrumbs">
					<?php 
    lok_breadcrumbs();
    ?>
				</section><!--/#breadcrumbs -->
			<?php 
}
?>
			<section id="main" class="col-left"> 
		<div class="padder">
			<?php 
if (dpa_has_achievements('skip_detail_page_result=0')) {
    while (dpa_achievements()) {
        dpa_the_achievement();
        ?>

			<?php 
        do_action('dpa_before_achievement_home_content');
        ?>

			<div id="item-header">
				<?php 
        dpa_load_template(array('achievements/single/achievement-header.php'));
        ?>
			</div><!-- #item-header -->

			<div id="item-nav">
<?php

do_action('dpa_before_achievements_loop');
?>

<?php 
if (dpa_has_achievements(bp_ajax_querystring('achievements'))) {
    ?>

	<div class="pagination">

		<div class="pag-count" id="achievements-count-top">
			<?php 
    dpa_achievements_pagination_count();
    ?>
		</div>

		<div class="pagination-links" id="achievements-pag-top">
			<?php 
    dpa_achievements_pagination_links();
    ?>
		</div>

	</div>

	<ul id="achievements-list" class="item-list">
	<?php 
    while (dpa_achievements()) {
        dpa_the_achievement();
        ?>
Beispiel #6
0
/**
 * Implements the Achievement actions and unlocks if criteria met.
 *
 * @see dpa_register_events()
 * @since Achievements (3.0)
 */
function dpa_handle_event()
{
    // Look at the current_filter to find out what action has occured
    $event_name = current_filter();
    $func_args = func_get_args();
    // Let other plugins do things before anything happens
    do_action('dpa_before_handle_event', $event_name, $func_args);
    // Allow other plugins to change the name of the event being processed, or to bail out early
    $event_name = apply_filters('dpa_handle_event_name', $event_name, $func_args);
    if (false === $event_name) {
        return;
    }
    /**
     * Extensions using the DPA_CPT_Extension base class may not capture their generic CPT
     * actions if that same action was used with by another extension with a different post
     * type. As no achievement will ever be associated with a generic action, if we're about
     * to query for a generic action, bail out.
     */
    foreach (achievements()->extensions as $extension) {
        if (!is_a($extension, 'DPA_CPT_Extension')) {
            continue;
        }
        // Is $event_name a generic CPT action?
        if (in_array($event_name, $extension->get_generic_cpt_actions(array()))) {
            return;
        }
    }
    // This filter allows the user ID to be updated (e.g. for draft posts which are then published by someone else)
    $user_id = absint(apply_filters('dpa_handle_event_user_id', get_current_user_id(), $event_name, $func_args));
    if (!$user_id) {
        return;
    }
    // Only proceed if the specified user is active (logged in and not a spammer)
    if (!dpa_is_user_active($user_id)) {
        return;
    }
    // Only proceed if the specified user can create progress posts
    if (!user_can($user_id, 'publish_achievement_progresses')) {
        return;
    }
    // Find achievements that are associated with the $event_name taxonomy
    $args = array('ach_event' => $event_name, 'ach_populate_progress' => $user_id, 'no_found_rows' => true, 'nopaging' => true, 'post_status' => 'any', 'posts_per_page' => -1, 's' => '');
    // If multisite and running network-wide, switch_to_blog to the data store site
    if (is_multisite() && dpa_is_running_networkwide()) {
        switch_to_blog(DPA_DATA_STORE);
    }
    // Loop through achievements found
    if (dpa_has_achievements($args)) {
        while (dpa_achievements()) {
            dpa_the_achievement();
            // Check that the post status is published or privately published
            // We need to check this here to work around WP_Query not
            // constructing the query correctly with private
            if (!in_array($GLOBALS['post']->post_status, array('publish', 'private'))) {
                continue;
            }
            // Let other plugins do things before we maybe_unlock_achievement
            do_action('dpa_handle_event', $event_name, $func_args, $user_id, $args);
            // Allow plugins to stop any more processing for this achievement
            if (false === apply_filters('dpa_handle_event_maybe_unlock_achievement', true, $event_name, $func_args, $user_id, $args)) {
                continue;
            }
            // Look in the progress posts and match against a post_parent which is the same as the current achievement.
            $progress = wp_filter_object_list(achievements()->progress_query->posts, array('post_parent' => dpa_get_the_achievement_ID()));
            $progress = array_shift($progress);
            // If the achievement hasn't already been unlocked, maybe_unlock_achievement.
            if (empty($progress) || dpa_get_unlocked_status_id() !== $progress->post_status) {
                dpa_maybe_unlock_achievement($user_id, false, $progress);
            }
        }
    }
    // If multisite and running network-wide, undo the switch_to_blog
    if (is_multisite() && dpa_is_running_networkwide()) {
        restore_current_blog();
    }
    achievements()->achievement_query = new WP_Query();
    achievements()->leaderboard_query = new ArrayObject();
    achievements()->progress_query = new WP_Query();
    // Everything's done. Let other plugins do things.
    do_action('dpa_after_handle_event', $event_name, $func_args, $user_id, $args);
}
/**
 * Implements the Achievement actions, and unlocks if criteria met.
 *
 * @global DPA_Achievement_Template $achievements_template Achievements template tag object
 * @global int $blog_id Site ID (variable is from NXTClass and hasn't been updated for 3.0; confusing name is confusing)
 * @global object $bp BuddyPress global settings
 * @param string $name Action name
 * @param array $func_args Optional; action's arguments, from func_get_args().
 * @param string $type Optional; if the Achievement's action is called from within the loop in this function (i.e. points awarded), set this to "latent" to avoid a single Achievement being awarded mulitple times.
 * @see dpa_setup_achievements()
 * @since 2.0
 * @uses DPA_Achievement
 */
function dpa_handle_action($name, $func_args = null, $type = '')
{
    global $achievements_template, $blog_id, $bp;
    do_action('dpa_before_handle_action', $name, $func_args, $type);
    if (!($name = apply_filters('dpa_handle_action', $name, $func_args, $type))) {
        return;
    }
    $user_id = apply_filters('dpa_handle_action_user_id', $bp->loggedin_user->id, $name, $func_args, $type);
    if (false === $user_id || empty($user_id)) {
        return;
    }
    if ('latent' == $type) {
        $latent_achievements = DPA_Achievement::get(array('user_id' => $user_id, 'type' => 'active_by_action', 'action' => $name));
        $achievements_template->achievements = array_merge($achievements_template->achievements, $latent_achievements['achievements']);
        $achievements_template->achievement_count += count($latent_achievements['achievements']);
        do_action('dpa_handle_latent_action', $name, $func_args, $is_latent, $latent_achievements);
        // Avoid duplicate invocations of latent Achievement actions
        if ('dpa_points_incremented' == $name) {
            remove_action('dpa_points_incremented', 'dpa_handle_action_dpa_points_incremented', 10, 10);
        }
        if ('dpa_achievement_unlocked' == $name) {
            remove_action('dpa_achievement_unlocked', 'dpa_handle_action_dpa_achievement_unlocked', 10, 10);
        }
        return;
    }
    // This is to support plugins which use the 'dpa_handle_action_user_id' filter to return an array of user IDs.
    if (is_array($user_id)) {
        $user_ids = $user_id;
    } else {
        $user_ids = array($user_id);
    }
    foreach ($user_ids as $user_id) {
        if (dpa_has_achievements(array('user_id' => $user_id, 'type' => 'active_by_action', 'action' => $name))) {
            while (dpa_achievements()) {
                dpa_the_achievement();
                $site_id = apply_filters('dpa_handle_action_site_id', dpa_get_achievement_site_id(), $name, $func_args, $type, $user_id);
                if (false === $site_id) {
                    continue;
                }
                $site_is_valid = false;
                if (!is_multisite() || $site_id < 1 || $blog_id == $site_id) {
                    $site_is_valid = true;
                }
                $group_is_valid = false;
                if (dpa_get_achievement_group_id() < 1 || dpa_is_group_achievement_valid($name, $func_args, $user_id)) {
                    $group_is_valid = true;
                }
                $site_is_valid = apply_filters('dpa_handle_action_site_is_valid', $site_is_valid, $name, $func_args, $type, $user_id);
                $group_is_valid = apply_filters('dpa_handle_action_group_is_valid', $group_is_valid, $name, $func_args, $type, $user_id);
                if ($site_is_valid && $group_is_valid) {
                    dpa_maybe_unlock_achievement($user_id);
                }
            }
        }
    }
    do_action('dpa_after_handle_action', $name, $func_args, $type);
    $achievements_template = null;
}
Beispiel #8
0
        /**
         * Add the 'User Points' box to Edit User page, and a list of the user's current achievements.
         *
         * @param WP_User $user
         * @since Achievements (3.0)
         */
        public function add_profile_fields(WP_User $user)
        {
            if (!is_super_admin()) {
                return;
            }
            ?>

		<h3><?php 
            _e('Achievements Settings', 'achievements');
            ?>
</h3>
		<table class="form-table">
			<tr>
				<th><label for="dpa_achievements"><?php 
            _ex('Total Points', "User&rsquo;s total points from unlocked Achievements", 'achievements');
            ?>
</label></th>
				<td><input type="number" name="dpa_achievements" id="dpa_achievements" value="<?php 
            echo (int) dpa_get_user_points($user->ID);
            ?>
" class="regular-text" />
				</td>
			</tr>

			<?php 
            if (dpa_has_achievements(array('ach_populate_progress' => $user->ID, 'ach_progress_status' => dpa_get_unlocked_status_id(), 'posts_per_page' => -1))) {
                ?>
				<tr>
					<th scope="row"><?php 
                _e('Unlocked Achievements', 'achievements');
                ?>
</th>
					<td>
						<fieldset>
							<legend class="screen-reader-text"><?php 
                _e('Assign or remove achievements from this user', 'achievements');
                ?>
</legend>

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

								<label><input type="checkbox" name="dpa_user_achievements[]" value="<?php 
                    echo absint(dpa_get_the_achievement_ID());
                    ?>
" <?php 
                    checked(dpa_is_achievement_unlocked(), true);
                    ?>
> <?php 
                    dpa_achievement_title();
                    ?>
</label><br>
							<?php 
                }
                ?>

						</fieldset>
					</td>
				</tr>
			<?php 
            }
            ?>

		</table>

	<?php 
        }