Changeset 2660
- Timestamp:
- 11/29/2010 11:09:18 AM (14 years ago)
- Location:
- branches/plugin
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-includes/bbp-functions.php
r2659 r2660 245 245 246 246 /** 247 * bbp_favorites_handler () 248 * 249 * Handles the front end adding and removing of favorite topics 250 */ 251 function bbp_favorites_handler () { 252 global $bbp, $current_user; 253 254 // Only proceed if GET is a favorite action 255 if ( 'GET' == $_SERVER['REQUEST_METHOD'] && !empty( $_GET['action'] ) && !empty( $_GET['topic_id'] ) ) { 256 257 // Load user info 258 $current_user = wp_get_current_user(); 259 $user_id = $current_user->ID; 260 261 // Check users ability to create new reply 262 if ( !current_user_can( 'edit_user', $user_id ) ) 263 return false; 264 265 // What action is taking place? 266 $action = $_GET['action']; 267 268 // Load favorite info 269 $topic_id = intval( $_GET['topic_id'] ); 270 $is_favorite = bbp_is_user_favorite( $user_id, $topic_id ); 271 $success = false; 272 273 // Handle insertion into posts table 274 if ( !empty( $topic_id ) && !empty( $user_id ) ) { 275 276 if ( $is_favorite && 'bbp_favorite_remove' == $action ) 277 $success = bbp_remove_user_favorite( $user_id, $topic_id ); 278 elseif ( !$is_favorite && 'bbp_favorite_add' == $action ) 279 $success = bbp_add_user_favorite( $user_id, $topic_id ); 280 281 // Do additional favorites actions 282 do_action( 'bbp_favorites_handler', $success, $user_id, $topic_id, $action ); 283 284 // Check for missing reply_id or error 285 if ( true == $success ) { 286 287 // Redirect back to new reply 288 $redirect = bbp_is_favorites() ? bbp_get_favorites_permalink( $user_id ) : bbp_get_topic_permalink( $topic_id ); 289 wp_redirect( $redirect ); 290 291 // For good measure 292 exit(); 293 } 294 } 295 } 296 } 297 add_action( 'template_redirect', 'bbp_favorites_handler' ); 298 299 /** 300 * bbp_load_template( $files ) 301 * 302 * 303 * @param str $files 304 * @return On failure 305 */ 306 function bbp_load_template( $files ) { 307 if ( empty( $files ) ) 308 return; 309 310 // Force array 311 if ( is_string( $files ) ) 312 $files = (array)$files; 313 314 // Exit if file is found 315 if ( locate_template( $files, true ) ) 316 exit(); 317 318 return; 319 } 320 321 /** 247 322 * bbp_get_stickies() 248 323 * -
branches/plugin/bbp-includes/bbp-template.php
r2659 r2660 1057 1057 $bbp_topics_template = new WP_Query( $bbp_t ); 1058 1058 1059 if ( -1 == $posts_per_page ) 1060 $posts_per_page = $bbp_topics_template->post_count; 1061 1059 1062 // Add pagination values to query object 1060 1063 $bbp_topics_template->posts_per_page = $posts_per_page; … … 1062 1065 1063 1066 // Only add pagination if query returned results 1064 if ( (int)$bbp_topics_template-> found_posts&& (int)$bbp_topics_template->posts_per_page ) {1067 if ( (int)$bbp_topics_template->post_count && (int)$bbp_topics_template->posts_per_page ) { 1065 1068 1066 1069 // If pretty permalinks are enabled, make our pagination pretty … … 1074 1077 'base' => $base, 1075 1078 'format' => '', 1076 'total' => ceil( (int)$bbp_topics_template->found_posts / (int)$posts_per_page ),1079 'total' => $posts_per_page == $bbp_topics_template->post_count ? 1 : ceil( (int)$bbp_topics_template->found_posts / (int)$posts_per_page ), 1077 1080 'current' => (int)$bbp_topics_template->paged, 1078 1081 'prev_text' => '←', … … 1991 1994 $from_num = bbp_number_format( $start_num ); 1992 1995 $to_num = bbp_number_format( ( $start_num + ( $bbp_topics_template->posts_per_page - 1 ) > $bbp_topics_template->found_posts ) ? $bbp_topics_template->found_posts : $start_num + ( $bbp_topics_template->posts_per_page - 1 ) ); 1993 $total = bbp_number_format( $bbp_topics_template-> found_posts);1996 $total = bbp_number_format( $bbp_topics_template->post_count ); 1994 1997 1995 1998 // Set return string 1996 if ( $total > 1 && $from_num != $to_num ) 1999 if ( $total > 1 && (int)$from_num == (int)$to_num ) 2000 $retstr = sprintf( __( 'Viewing topic %1$s (of %2$s total)', 'bbpress' ), $from_num, $total ); 2001 elseif ( $total > 1 && empty( $to_num ) ) 2002 $retstr = sprintf( __( 'Viewing %1$s topics', 'bbpress' ), $total ); 2003 elseif ( $total > 1 && (int)$from_num != (int)$to_num ) 1997 2004 $retstr = sprintf( __( 'Viewing topics %1$s through %2$s (of %3$s total)', 'bbpress' ), $from_num, $to_num, $total ); 1998 elseif ( $total > 1 && $from_num == $to_num )1999 $retstr = sprintf( __( 'Viewing topic %1$s (of %2$s total)', 'bbpress' ), $from_num, $total );2000 2005 else 2001 2006 $retstr = sprintf( __( 'Viewing %1$s topic', 'bbpress' ), $total ); … … 2561 2566 } 2562 2567 2568 /** 2569 * bbp_is_user_home () 2570 * 2571 * Check if current page is the currently logged in users author page 2572 * 2573 * @global object $current_user 2574 * @return bool 2575 */ 2576 function bbp_is_user_home() { 2577 global $current_user; 2578 2579 $current_user = wp_get_current_user(); 2580 2581 if ( $current_user->ID == get_the_author_meta( 'ID' ) ) 2582 $retval = true; 2583 else 2584 $retval = false; 2585 2586 return apply_filters( 'bbp_is_user_home', $retval, $current_user ); 2587 } 2588 2563 2589 /** END is_ Functions *********************************************************/ 2564 2590 … … 2566 2592 2567 2593 /** 2568 * bbp_favorites_ link ()2594 * bbp_favorites_permalink () 2569 2595 * 2570 2596 * Output the link to the user's favorites page (author page) … … 2575 2601 * 2576 2602 * @param int $user_id optional 2577 * @uses bbp_get_favorites_ link()2578 */ 2579 function bbp_favorites_ link ( $user_id = 0 ) {2580 echo bbp_get_favorites_ link( $user_id );2581 } 2582 /** 2583 * bbp_get_favorites_ link ()2603 * @uses bbp_get_favorites_permalink() 2604 */ 2605 function bbp_favorites_permalink ( $user_id = 0 ) { 2606 echo bbp_get_favorites_permalink( $user_id ); 2607 } 2608 /** 2609 * bbp_get_favorites_permalink () 2584 2610 * 2585 2611 * Return the link to the user's favorites page (author page) … … 2594 2620 * @return string Permanent link to topic 2595 2621 */ 2596 function bbp_get_favorites_ link ( $user_id = 0 ) {2597 return apply_filters( 'bbp_get_favorites_ link', get_author_posts_url( $user_id ) );2622 function bbp_get_favorites_permalink ( $user_id = 0 ) { 2623 return apply_filters( 'bbp_get_favorites_permalink', get_author_posts_url( $user_id ) ); 2598 2624 } 2599 2625 … … 2635 2661 function bbp_get_user_favorites_link ( $add = array(), $rem = array(), $user_id = 0 ) { 2636 2662 global $current_user; 2637 wp_get_current_user(); 2663 2664 $current_user = wp_get_current_user(); 2638 2665 2639 2666 if ( empty( $user_id ) && !$user_id = $current_user->ID ) … … 2651 2678 'post' => __( ' (%?%)', 'bbpress' ) 2652 2679 ); 2653 $url = esc_url( bbp_get_topic_permalink( $topic_id ) );2654 2680 } 2655 2681 … … 2660 2686 'post' => __( ']', 'bbpress' ) 2661 2687 ); 2662 $url = esc_url( bbp_get_favorites_link( $user_id ) );2663 2688 } 2664 2689 2665 2690 if ( bbp_is_user_favorite( $user_id, $topic_id ) ) { 2691 $url = esc_url( bbp_get_topic_permalink( $topic_id ) ); 2666 2692 $rem = preg_replace( '|%(.+)%|', "<a href='$url'>$1</a>", $rem ); 2667 $favs = array( ' fav' => '0', 'topic_id' => $topic_id );2693 $favs = array( 'action' => 'bbp_favorite_remove', 'topic_id' => $topic_id ); 2668 2694 $pre = ( is_array( $rem ) && isset( $rem['pre'] ) ) ? $rem['pre'] : ''; 2669 2695 $mid = ( is_array( $rem ) && isset( $rem['mid'] ) ) ? $rem['mid'] : ( is_string( $rem ) ? $rem : '' ); 2670 2696 $post = ( is_array( $rem ) && isset( $rem['post'] ) ) ? $rem['post'] : ''; 2671 2697 } else { 2698 $url = esc_url( bbp_get_favorites_permalink( $user_id ) ); 2672 2699 $add = preg_replace( '|%(.+)%|', "<a href='$url'>$1</a>", $add ); 2673 $favs = array( ' fav' => '1', 'topic_id' => $topic_id );2700 $favs = array( 'action' => 'bbp_favorite_add', 'topic_id' => $topic_id ); 2674 2701 $pre = ( is_array( $add ) && isset( $add['pre'] ) ) ? $add['pre'] : ''; 2675 2702 $mid = ( is_array( $add ) && isset( $add['mid'] ) ) ? $add['mid'] : ( is_string( $add ) ? $add : '' ); … … 2677 2704 } 2678 2705 2679 $url = esc_url( wp_nonce_url( add_query_arg( $favs, bbp_get_topic_permalink( $topic_id ) ), 'toggle-favorite_' . $topic_id ) ); 2706 $permalink = bbp_is_favorites() ? bbp_get_favorites_permalink( $user_id ) : bbp_get_topic_permalink( $topic_id ); 2707 $url = esc_url( wp_nonce_url( add_query_arg( $favs, $permalink ), 'toggle-favorite_' . $topic_id ) ); 2680 2708 2681 2709 return apply_filters( 'bbp_get_user_favorites_link', "<span id='favorite-toggle'><span id='favorite-$topic_id'>$pre<a href='$url' class='dim:favorite-toggle:favorite-$topic_id:is-favorite'>$mid</a>$post</span></span>" ); -
branches/plugin/bbp-includes/bbp-users.php
r2659 r2660 81 81 */ 82 82 function bbp_get_user_favorites ( $user_id = 0 ) { 83 if ( empty( $user_id ) ) 84 return; 85 83 // Default to author 84 if ( empty( $user_id ) ) 85 $user_id = get_the_author_meta( 'ID' ); 86 87 // If nothing passed and not an author page, return nothing 88 if ( empty( $user_id ) ) 89 return false; 90 91 // Get users' favorites 86 92 $favorites = bbp_get_user_favorites_topic_ids( $user_id ); 87 93 94 // If user has favorites, load them 88 95 if ( !empty( $favorites ) ) { 89 $query = bbp_has_topics( array( 'post__in' => $favorites, 'p er_page' => -1 ) );96 $query = bbp_has_topics( array( 'post__in' => $favorites, 'posts_per_page' => -1 ) ); 90 97 return $query; 91 98 } … … 111 118 112 119 if ( empty( $user_id ) ) { 113 wp_get_current_user();114 $user_id = $current_user->ID;120 $current_user = wp_get_current_user(); 121 $user_id = $current_user->ID; 115 122 } 116 123 … … 213 220 /** END - Favorites ***********************************************************/ 214 221 222 /** 223 * bbp_get_user_topics_started () 224 * 225 * Get the topics that a user created 226 * 227 * @package bbPress 228 * @subpackage Users 229 * @since bbPress (r2652) 230 * 231 * @param int $user_id User ID 232 * @return array|bool Results if user has favorites, otherwise false 233 */ 234 function bbp_get_user_topics_started ( $user_id = 0 ) { 235 // Default to author 236 if ( empty( $user_id ) ) 237 $user_id = get_the_author_meta( 'ID' ); 238 239 // If nothing passed and not an author page, return nothing 240 if ( empty( $user_id ) ) 241 return false; 242 243 if ( $query = bbp_has_topics( array( 'author' => $user_id, 'posts_per_page' => -1 ) ) ) 244 return $query; 245 246 return false; 247 } 248 215 249 ?> -
branches/plugin/bbp-themes/bbp-twentyten/author.php
r2652 r2660 1 1 <?php 2 2 /** 3 * T he template for displaying Author Archive pages.3 * Template Name: bbPress - User Profile 4 4 * 5 * @package WordPress 6 * @subpackage Twenty_Ten 7 * @since Twenty Ten 1.0 5 * @package bbPress 6 * @subpackage Template 8 7 */ 8 ?> 9 9 10 get_header(); ?>10 <?php get_header(); ?> 11 11 12 12 <div id="container"> 13 13 <div id="content" role="main"> 14 14 15 <?php 16 /* Queue the first post, that way we know who 17 * the author is when we try to get their name, 18 * URL, description, avatar, etc. 19 * 20 * We reset this later so we can run the loop 21 * properly with a call to rewind_posts(). 22 */ 23 if ( have_posts() ) 24 the_post(); 25 ?> 15 <?php if ( have_posts() ) the_post(); ?> 26 16 27 17 <h1 class="page-title author"><?php printf( __( 'Author Archives: %s', 'twentyten' ), "<span class='vcard'><a class='url fn n' href='" . get_author_posts_url( get_the_author_meta( 'ID' ) ) . "' title='" . esc_attr( get_the_author() ) . "' rel='me'>" . get_the_author() . "</a></span>" ); ?></h1> 28 18 29 <?php 30 // If a user has filled out their description, show a bio on their entries. 31 if ( get_the_author_meta( 'description' ) ) : ?> 19 <?php if ( get_the_author_meta( 'description' ) ) : ?> 20 32 21 <div id="entry-author-info"> 33 22 <div id="author-avatar"> 23 34 24 <?php echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'twentyten_author_bio_avatar_size', 60 ) ); ?> 25 35 26 </div><!-- #author-avatar --> 36 27 <div id="author-description"> 37 28 <h2><?php printf( __( 'About %s', 'twentyten' ), get_the_author() ); ?></h2> 29 38 30 <?php the_author_meta( 'description' ); ?> 31 39 32 </div><!-- #author-description --> 40 33 </div><!-- #entry-author-info --> 41 <?php endif; ?>42 34 43 <?php 44 /* Since we called the_post() above, we need to 45 * rewind the loop back to the beginning that way 46 * we can run the loop properly, in full. 47 */ 48 rewind_posts(); 35 <?php endif; ?> 49 36 50 /* Run the loop for the author archive page to output the authors posts 51 * If you want to overload this in a child theme then include a file 52 * called loop-author.php and that will be used instead. 53 */ 54 get_template_part( 'loop', 'author' ); 55 ?> 37 <?php rewind_posts(); ?> 56 38 57 <h2 id="fav-heading"><?php _e( 'Favorites', 'bbpress' ); ?></h2>39 <?php get_template_part( 'loop', 'author' ); ?> 58 40 59 <?php 60 /* @todo Add favorites feeds 61 if ( current_user_can( 'edit_user', get_the_author_meta( 'ID' ) ) ) : ?> 62 <p> 63 <?php printf( __( 'You can also <a href="%1$s">manage your favorites</a> and subscribe to your favorites’ <a href="%2$s"><abbr title="Really Simple Syndication">RSS</abbr> feed</a>.', 'bbpress' ), esc_attr( bbp_get_favorites_link() ), esc_attr( bbp_get_favorites_rss_link() ) ); ?> 64 </p> 41 <div id="bbp-author-favorites" class="bbp-author-favorites"> 42 <hr /> 43 <h1 class="entry-title"><?php _e( 'Favorite Topics', 'bbpress' ); ?></h1> 44 <div class="entry-content"> 65 45 66 <p><?php _e( 'Favorites allow members to create a custom <abbr title="Really Simple Syndication">RSS</abbr> feed which pulls recent replies to the topics they specify.', 'bbpress' ); ?></p>46 <?php if ( bbp_is_user_home() ) : ?> 67 47 68 <?php 69 endif; 70 */ 71 ?> 48 <p><?php _e( 'To add topics to your list of favorites, just click the "Add to Favorites" link found on that topic’s page.', 'bbpress' ); ?></p> 72 49 73 <?php if ( current_user_can( 'edit_user', get_the_author_meta( 'ID' ) ) ) :?>50 <?php endif; ?> 74 51 75 <p><?php _e( 'To add topics to your list of favorites, just click the "Add to Favorites" link found on that topic’s page.', 'bbpress' ); ?></p>52 <?php if ( bbp_get_user_favorites() ) : 76 53 77 <?php endif; ?> 54 get_template_part( 'loop', 'bbp_topics' ); 78 55 79 <?php 80 // Get the user's favorite topics 81 if ( bbp_get_user_favorites( get_the_author_meta( 'ID' ) ) ) : 56 else : ?> 82 57 83 get_template_part( 'loop', 'bbp_topics' );58 <p><?php bbp_is_user_home() ? _e( 'You currently have no favorite topics.', 'bbpress' ) : _e( 'This user has no favorite topics.', 'bbpress' ); ?></p> 84 59 85 else :60 <?php endif; ?> 86 61 87 $current_user = wp_get_current_user(); 62 </div> 63 </div><!-- #bbp-author-favorites --> 88 64 89 if ( get_the_author_meta( 'ID' ) == $current_user->ID ) : ?> 65 <div id="bbp-author-topics-started" class="bbp-author-topics-started"> 66 <hr /> 67 <h1 class="entry-title"><?php _e( 'Topics Created', 'bbpress' ); ?></h1> 68 <div class="entry-content"> 90 69 91 <p><?php _e( 'You currently have no favorite topics.', 'bbpress' ); ?></p>70 <?php if ( bbp_get_user_topics_started() ) : 92 71 93 <?php else : ?> 72 get_template_part( 'loop', 'bbp_topics' ); 94 73 95 <p><?php _e( 'The user currently has no favorite topics.', 'bbpress' ); ?></p>74 else : ?> 96 75 97 <?php 98 endif; 99 endif; 100 ?> 76 <p><?php bbp_is_user_home() ? _e( 'You have not created any topics.', 'bbpress' ) : _e( 'This user has not created any topics.', 'bbpress' ); ?></p> 77 78 <?php endif; ?> 79 80 </div> 81 </div><!-- #bbp-new-topic --> 101 82 102 83 </div><!-- #content --> -
branches/plugin/bbp-themes/bbp-twentyten/functions.php
r2659 r2660 15 15 global $current_user; 16 16 17 wp_get_current_user(); 18 19 $user_id = $current_user->ID; 20 $id = intval( $_POST['id'] ); 17 $current_user = wp_get_current_user(); 18 $user_id = $current_user->ID; 19 $id = intval( $_POST['id'] ); 21 20 22 21 if ( !current_user_can( 'edit_user', $user_id ) ) … … 37 36 38 37 die( '0' ); 39 40 38 } 41 39 add_action( 'wp_ajax_dim-favorite', 'bbp_twentyten_dim_favorite' ); … … 110 108 'currentUserId' => $user_id, 111 109 'topicId' => bbp_get_topic_id(), 112 'favoritesLink' => bbp_get_favorites_ link( $user_id ),110 'favoritesLink' => bbp_get_favorites_permalink( $user_id ), 113 111 'isFav' => (int) bbp_is_user_favorite( $user_id ), 114 112 'favLinkYes' => __( 'favorites', 'bbpress' ), … … 118 116 'favDel' => __( '×', 'bbpress' ), 119 117 'favAdd' => __( 'Add this topic to your favorites', 'bbpress' ) 120 ) );118 ) ); 121 119 } 122 120 add_filter( 'wp_enqueue_scripts', 'bbp_twentyten_topic_script_localization' ); -
branches/plugin/bbp-themes/bbp-twentyten/loop-bbp_topics.php
r2656 r2660 18 18 <th class="bbp-topic-voice-count"><?php _e( 'Voices', 'bbpress' ); ?></th> 19 19 <th class="bbp-topic-freshness"><?php _e( 'Freshness', 'bbpress' ); ?></th> 20 <?php if ( bbp_is_favorites() ) : ?><th class="bbp-topic-action"><?php _e( 'Favorite', 'bbpress' ); ?></th><?php endif; ?> 20 21 </tr> 21 22 </thead> 22 23 23 24 <tfoot> 24 <tr><td colspan=" 4"> </td></tr>25 <tr><td colspan="<?php echo bbp_is_favorites() ? '5' : '4'; ?>"> </td></tr> 25 26 </tfoot> 26 27 … … 50 51 <td class="bbp-topic-freshness"><?php bbp_topic_freshness_link(); ?></td> 51 52 53 <?php if ( bbp_is_favorites() ) : ?> 54 55 <td class="bbp-topic-action"> 56 57 <?php bbp_user_favorites_link( array( 'mid' => '+', 'post' => '' ), array( 'pre' => '', 'mid' => '×', 'post' => '' ) ); ?> 58 59 </td> 60 61 <?php endif; ?> 62 52 63 </tr><!-- #topic-<?php bbp_topic_id(); ?> --> 53 64 -
branches/plugin/bbp-themes/bbp-twentyten/style.css
r2659 r2660 1345 1345 } 1346 1346 1347 .bbp-forum-topic-count, .bbp-forum-topic-replies, .bbp-topic-reply-count, .bbp-topic-voice-count { 1347 .bbp-forum-topic-count, .bbp-forum-topic-replies, 1348 .bbp-topic-reply-count, .bbp-topic-voice-count, .bbp-topic-action { 1348 1349 width: 10%; 1349 1350 text-align: center; 1350 1351 } 1352 1351 1353 .bbp-topic-freshness, .bbp-forum-freshness { 1352 1354 text-align: center;
Note: See TracChangeset
for help on using the changeset viewer.