| @@ -1,0 +1,280 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Achievement template | |
| 4 | + * | |
| 5 | + * This template can be overridden by copying it to yourtheme/gamipress/achievement.php | |
| 6 | + * To override a specific achievement type just copy it as yourtheme/gamipress/achievement-{achievement-type}.php | |
| 7 | + */ | |
| 8 | +global $gamipress_template_args; | |
| 9 | + | |
| 10 | +// Shorthand | |
| 11 | +$a = $gamipress_template_args; | |
| 12 | + | |
| 13 | +$user_id = isset( $a['user_id'] ) ? absint( $a['user_id'] ) : get_current_user_id(); | |
| 14 | + | |
| 15 | +// Check if user has earned this achievement | |
| 16 | +$earned = gamipress_has_user_earned_achievement( get_the_ID(), $user_id ); | |
| 17 | + | |
| 18 | +// Setup thumbnail size | |
| 19 | +$thumbnail_size = absint( $a['thumbnail_size'] ); | |
| 20 | + | |
| 21 | +if( $thumbnail_size === 0 ) { | |
| 22 | + $thumbnail_size = 'gamipress-achievement'; | |
| 23 | +} else { | |
| 24 | + $thumbnail_size = array( $thumbnail_size, $thumbnail_size ); | |
| 25 | +} | |
| 26 | + | |
| 27 | +// Sanitize title size | |
| 28 | +$a['title_size'] = gamipress_sanitize_title_size_option( $a['title_size'] ); | |
| 29 | + | |
| 30 | +// Setup achievement classes | |
| 31 | +$classes = array( | |
| 32 | + 'gamipress-achievement', | |
| 33 | + ( $earned ? 'user-has-earned' : 'user-has-not-earned' ), | |
| 34 | + 'gamipress-layout-' . $a['layout'], | |
| 35 | + 'gamipress-align-' . $a['align'] | |
| 36 | +); | |
| 37 | + | |
| 38 | +/** | |
| 39 | + * Achievement classes | |
| 40 | + * | |
| 41 | + * @since 1.4.0 | |
| 42 | + * | |
| 43 | + * @param array $classes Array of achievement classes | |
| 44 | + * @param integer $achievement_id The Achievement ID | |
| 45 | + * @param array $template_args Template received arguments | |
| 46 | + */ | |
| 47 | +$classes = apply_filters( 'gamipress_achievement_classes', $classes, get_the_ID(), $a ); ?> | |
| 48 | + | |
| 49 | +<div id="gamipress-achievement-<?php the_ID(); ?>" class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>"> | |
| 50 | + | |
| 51 | + <?php | |
| 52 | + /** | |
| 53 | + * Before render achievement | |
| 54 | + * | |
| 55 | + * @since 1.0.0 | |
| 56 | + * | |
| 57 | + * @param integer $achievement_id The Achievement ID | |
| 58 | + * @param array $template_args Template received arguments | |
| 59 | + */ | |
| 60 | + do_action( 'gamipress_before_render_achievement', get_the_ID(), $a ); ?> | |
| 61 | + | |
| 62 | + <?php // Achievement Image | |
| 63 | + if( $a['thumbnail'] === 'yes' ) : ?> | |
| 64 | + <div class="gamipress-achievement-image"> | |
| 65 | + | |
| 66 | + <?php // Link to the achievement page | |
| 67 | + if( $a['link'] === 'yes' ) : ?> | |
| 68 | + <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo gamipress_get_achievement_post_thumbnail( get_the_ID(), $thumbnail_size ); ?></a> | |
| 69 | + <?php else : ?> | |
| 70 | + <?php echo gamipress_get_achievement_post_thumbnail( get_the_ID(), $thumbnail_size ); ?> | |
| 71 | + <?php endif; ?> | |
| 72 | + | |
| 73 | + <?php // Share | |
| 74 | + echo gamipress_achievement_share_markup( get_the_ID(), $a ); ?> | |
| 75 | + | |
| 76 | + </div><!-- .gamipress-achievement-image --> | |
| 77 | + | |
| 78 | + <?php | |
| 79 | + /** | |
| 80 | + * After achievement thumbnail | |
| 81 | + * | |
| 82 | + * @since 1.0.0 | |
| 83 | + * | |
| 84 | + * @param integer $achievement_id The Achievement ID | |
| 85 | + * @param array $template_args Template received arguments | |
| 86 | + */ | |
| 87 | + do_action( 'gamipress_after_achievement_thumbnail', get_the_ID(), $a ); ?> | |
| 88 | + | |
| 89 | + <?php endif; ?> | |
| 90 | + | |
| 91 | + <?php // Achievement Content ?> | |
| 92 | + <div class="gamipress-achievement-description"> | |
| 93 | + | |
| 94 | + <?php // Achievement Title | |
| 95 | + if( $a['title'] === 'yes' ) : ?> | |
| 96 | + <<?php echo $a['title_size']; ?> class="gamipress-achievement-title"> | |
| 97 | + | |
| 98 | + <?php // Link to the achievement page | |
| 99 | + if( $a['link'] === 'yes' ) : ?> | |
| 100 | + <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> | |
| 101 | + <?php else : ?> | |
| 102 | + <?php the_title(); ?> | |
| 103 | + <?php endif; ?> | |
| 104 | + | |
| 105 | + </<?php echo $a['title_size']; ?>> | |
| 106 | + | |
| 107 | + <?php | |
| 108 | + /** | |
| 109 | + * After achievement title | |
| 110 | + * | |
| 111 | + * @since 1.0.0 | |
| 112 | + * | |
| 113 | + * @param integer $achievement_id The Achievement ID | |
| 114 | + * @param array $template_args Template received arguments | |
| 115 | + */ | |
| 116 | + do_action( 'gamipress_after_achievement_title', get_the_ID(), $a ); ?> | |
| 117 | + | |
| 118 | + <?php endif; ?> | |
| 119 | + | |
| 120 | + <?php // Achievement points | |
| 121 | + if( $a['points_awarded'] === 'yes' ) : ?> | |
| 122 | + | |
| 123 | + <?php echo gamipress_achievement_points_markup( get_the_ID(), $a ); ?> | |
| 124 | + | |
| 125 | + <?php | |
| 126 | + /** | |
| 127 | + * After achievement points | |
| 128 | + * | |
| 129 | + * @since 1.0.0 | |
| 130 | + * | |
| 131 | + * @param integer $achievement_id The Achievement ID | |
| 132 | + * @param array $template_args Template received arguments | |
| 133 | + */ | |
| 134 | + do_action( 'gamipress_after_achievement_points', get_the_ID(), $a ); ?> | |
| 135 | + | |
| 136 | + <?php endif; ?> | |
| 137 | + | |
| 138 | + <?php // Achievement Short Description | |
| 139 | + if( $a['excerpt'] === 'yes' ) : ?> | |
| 140 | + <div class="gamipress-achievement-excerpt"> | |
| 141 | + <?php | |
| 142 | + $excerpt = has_excerpt() ? gamipress_get_post_field( 'post_excerpt', get_the_ID() ) : gamipress_get_post_field( 'post_content', get_the_ID() ); | |
| 143 | + echo wpautop( do_blocks( apply_filters( 'get_the_excerpt', $excerpt, get_post() ) ) ); | |
| 144 | + ?> | |
| 145 | + </div><!-- .gamipress-achievement-excerpt --> | |
| 146 | + | |
| 147 | + <?php | |
| 148 | + /** | |
| 149 | + * After achievement excerpt | |
| 150 | + * | |
| 151 | + * @since 1.0.0 | |
| 152 | + * | |
| 153 | + * @param integer $achievement_id The Achievement ID | |
| 154 | + * @param array $template_args Template received arguments | |
| 155 | + */ | |
| 156 | + do_action( 'gamipress_after_achievement_excerpt', get_the_ID(), $a ); ?> | |
| 157 | + <?php endif; ?> | |
| 158 | + | |
| 159 | + <?php // Times Earned | |
| 160 | + if( $a['times_earned'] === 'yes' ) : ?> | |
| 161 | + | |
| 162 | + <?php echo gamipress_achievement_times_earned_markup( get_the_ID(), $a ); ?> | |
| 163 | + | |
| 164 | + <?php | |
| 165 | + /** | |
| 166 | + * After achievement times earned | |
| 167 | + * | |
| 168 | + * @since 1.5.9 | |
| 169 | + * | |
| 170 | + * @param integer $achievement_id The Achievement ID | |
| 171 | + * @param array $template_args Template received arguments | |
| 172 | + */ | |
| 173 | + do_action( 'gamipress_after_achievement_times_earned', get_the_ID(), $a ); ?> | |
| 174 | + | |
| 175 | + <?php endif; ?> | |
| 176 | + | |
| 177 | + <?php // Global Times Earned | |
| 178 | + if( $a['global_times_earned'] === 'yes' ) : ?> | |
| 179 | + | |
| 180 | + <?php echo gamipress_achievement_global_times_earned_markup( get_the_ID(), $a ); ?> | |
| 181 | + | |
| 182 | + <?php | |
| 183 | + /** | |
| 184 | + * After achievement times earned by all users | |
| 185 | + * | |
| 186 | + * @since 2.0.0 | |
| 187 | + * | |
| 188 | + * @param integer $achievement_id The Achievement ID | |
| 189 | + * @param array $template_args Template received arguments | |
| 190 | + */ | |
| 191 | + do_action( 'gamipress_after_achievement_global_times_earned', get_the_ID(), $a ); ?> | |
| 192 | + | |
| 193 | + <?php endif; ?> | |
| 194 | + | |
| 195 | + <?php // Achievement Steps | |
| 196 | + if ( $a['steps'] === 'yes' && $steps = gamipress_get_achievement_steps( get_the_ID() ) ) : ?> | |
| 197 | + <div class="gamipress-achievement-attached"> | |
| 198 | + | |
| 199 | + <?php if ( $a['toggle'] === 'yes' ) : ?> | |
| 200 | + | |
| 201 | + <div id="show-more-<?php the_ID(); ?>" class="gamipress-open-close-switch"> | |
| 202 | + <a class="show-hide-open" data-achievement-id="<?php the_ID(); ?>" data-action="open" data-open-text="<?php _e( 'Show Details', 'gamipress' ); ?>" data-close-text="<?php _e( 'Hide Details', 'gamipress' ); ?>" href="#"><?php _e( 'Show Details', 'gamipress' ); ?></a> | |
| 203 | + </div> | |
| 204 | + | |
| 205 | + <div id="gamipress-toggle-more-window-<?php the_ID(); ?>" class="gamipress-extras-window"> | |
| 206 | + <?php echo gamipress_get_required_achievements_for_achievement_list_markup( $steps, get_the_ID(), $user_id, $a ); ?> | |
| 207 | + </div><!-- .gamipress-extras-window --> | |
| 208 | + | |
| 209 | + <?php else : ?> | |
| 210 | + | |
| 211 | + <?php echo gamipress_get_required_achievements_for_achievement_list_markup( $steps, get_the_ID(), $user_id, $a ); ?> | |
| 212 | + | |
| 213 | + <?php endif; ?> | |
| 214 | + | |
| 215 | + </div><!-- .gamipress-achievement-attached --> | |
| 216 | + | |
| 217 | + <?php | |
| 218 | + /** | |
| 219 | + * After achievement steps | |
| 220 | + * | |
| 221 | + * @since 1.0.0 | |
| 222 | + * | |
| 223 | + * @param integer $achievement_id The Achievement ID | |
| 224 | + * @param array $template_args Template received arguments | |
| 225 | + */ | |
| 226 | + do_action( 'gamipress_after_achievement_steps', get_the_ID(), $a ); ?> | |
| 227 | + | |
| 228 | + <?php endif; ?> | |
| 229 | + | |
| 230 | + <?php // Achievement unlock with points | |
| 231 | + if ( $a['unlock_button'] === 'yes' ) : | |
| 232 | + echo gamipress_achievement_unlock_with_points_markup( get_the_ID(), $a ); | |
| 233 | + endif; ?> | |
| 234 | + | |
| 235 | + <?php // If thumbnail is not displayed, place the share buttons at bottom | |
| 236 | + if ( $a['thumbnail'] !== 'yes' ) : | |
| 237 | + echo gamipress_achievement_share_markup( get_the_ID(), $a ); | |
| 238 | + endif; ?> | |
| 239 | + | |
| 240 | + <?php // Achievement Earners | |
| 241 | + if ( $a['earners'] === 'yes' ) : | |
| 242 | + echo gamipress_get_achievement_earners_list( get_the_ID(), array( 'limit' => $a['earners_limit'] ) ); | |
| 243 | + | |
| 244 | + /** | |
| 245 | + * After achievement earners | |
| 246 | + * | |
| 247 | + * @since 1.0.0 | |
| 248 | + * | |
| 249 | + * @param integer $achievement_id The Achievement ID | |
| 250 | + * @param array $template_args Template received arguments | |
| 251 | + */ | |
| 252 | + do_action( 'gamipress_after_achievement_earners', get_the_ID(), $a ); ?> | |
| 253 | + | |
| 254 | + <?php endif; ?> | |
| 255 | + | |
| 256 | + <?php | |
| 257 | + /** | |
| 258 | + * Achievement description bottom | |
| 259 | + * | |
| 260 | + * @since 1.4.0 | |
| 261 | + * | |
| 262 | + * @param integer $achievement_id The Achievement ID | |
| 263 | + * @param array $template_args Template received arguments | |
| 264 | + */ | |
| 265 | + do_action( 'gamipress_achievement_description_bottom', get_the_ID(), $a ); ?> | |
| 266 | + | |
| 267 | + </div><!-- .gamipress-achievement-description --> | |
| 268 | + | |
| 269 | + <?php | |
| 270 | + /** | |
| 271 | + * After render achievement | |
| 272 | + * | |
| 273 | + * @since 1.0.0 | |
| 274 | + * | |
| 275 | + * @param integer $achievement_id The Achievement ID | |
| 276 | + * @param array $template_args Template received arguments | |
| 277 | + */ | |
| 278 | + do_action( 'gamipress_after_render_achievement', get_the_ID(), $a ); ?> | |
| 279 | + | |
| 280 | +</div><!-- .gamipress-achievement --> | |