Changeset 4615
- Timestamp:
- 12/21/2012 08:12:29 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/users/template-tags.php
r4614 r4615 619 619 * @since bbPress (r2652) 620 620 * 621 * @param array $add Optional. Add to favorites args 622 * @param array $rem Optional. Remove from favorites args 621 * @param mixed $args See {@link bbp_get_user_favorites_link()} 623 622 * @param int $user_id Optional. User id 624 * @param int $topic_id Optional. Topic id623 * @param bool $wrap Optional. If you want to wrap the link in <span id="favorite-toggle">. 625 624 * @uses bbp_get_user_favorites_link() To get the user favorites link 626 625 */ 627 function bbp_user_favorites_link( $a dd = array(), $rem = array(), $user_id = 0, $topic_id = 0) {628 echo bbp_get_user_favorites_link( $a dd, $rem, $user_id, $topic_id);626 function bbp_user_favorites_link( $args = array(), $user_id = 0, $wrap = true ) { 627 echo bbp_get_user_favorites_link( $args, $user_id, $wrap ); 629 628 } 630 629 /** … … 636 635 * @since bbPress (r2652) 637 636 * 638 * @param array $add Optional. Add to favorites args 639 * @param array $rem Optional. Remove from favorites args 637 * @param mixed $args This function supports these arguments: 638 * - subscribe: Favorite text 639 * - unsubscribe: Unfavorite text 640 * - user_id: User id 641 * - topic_id: Topic id 642 * - before: Before the link 643 * - after: After the link 640 644 * @param int $user_id Optional. User id 641 645 * @param int $topic_id Optional. Topic id … … 652 656 * @return string User favorites link 653 657 */ 654 function bbp_get_user_favorites_link( $a dd = array(), $rem = array(), $user_id = 0, $topic_id = 0, $wrap = true ) {658 function bbp_get_user_favorites_link( $args = '', $user_id = 0, $wrap = true ) { 655 659 if ( !bbp_is_favorites_active() ) 656 660 return false; 657 661 662 // Parse arguments against default values 663 $r = bbp_parse_args( $args, array( 664 'favorite' => __( 'Favorite', 'bbpress' ), 665 'favorited' => __( 'Favorited', 'bbpress' ), 666 'user_id' => 0, 667 'topic_id' => 0, 668 'before' => '', 669 'after' => '' 670 ), 'get_user_favorites_link' ); 671 658 672 // Validate user and topic ID's 659 $user_id = bbp_get_user_id( $ user_id, true, true );660 $topic_id = bbp_get_topic_id( $ topic_id);661 if ( empty( $user_id ) || empty( $topic_id ) ) 673 $user_id = bbp_get_user_id( $r['user_id'], true, true ); 674 $topic_id = bbp_get_topic_id( $r['topic_id'] ); 675 if ( empty( $user_id ) || empty( $topic_id ) ) { 662 676 return false; 663 664 if ( !current_user_can( 'edit_user', (int) $user_id ) ) 677 } 678 679 // No link if you can't edit yourself 680 if ( !current_user_can( 'edit_user', (int) $user_id ) ) { 665 681 return false; 666 667 if ( empty( $add ) || !is_array( $add ) ) { 668 $add = array( 669 'mid' => __( 'Add this topic to your favorites', 'bbpress' ), 670 'post' => __( ' (%?%)', 'bbpress' ) 671 ); 672 } 673 674 if ( empty( $rem ) || !is_array( $rem ) ) { 675 $rem = array( 676 'pre' => __( 'This topic is one of your %favorites% [', 'bbpress' ), 677 'mid' => __( '×', 'bbpress' ), 678 'post' => __( ']', 'bbpress' ) 679 ); 680 } 681 682 } 683 684 // Decine which link to show 682 685 $is_fav = bbp_is_user_favorite( $user_id, $topic_id ); 683 686 if ( !empty( $is_fav ) ) { 684 $url = esc_url( bbp_get_favorites_permalink( $user_id ) ); 685 $rem = preg_replace( '|%(.+)%|', "<a href='$url'>$1</a>", $rem ); 686 $favs = array( 'action' => 'bbp_favorite_remove', 'topic_id' => $topic_id ); 687 $pre = ( is_array( $rem ) && isset( $rem['pre'] ) ) ? $rem['pre'] : ''; 688 $mid = ( is_array( $rem ) && isset( $rem['mid'] ) ) ? $rem['mid'] : ( is_string( $rem ) ? $rem : '' ); 689 $_post = ( is_array( $rem ) && isset( $rem['post'] ) ) ? $rem['post'] : ''; 687 $text = $r['favorited']; 688 $query_args = array( 'action' => 'bbp_favorite_remove', 'topic_id' => $topic_id ); 690 689 } else { 691 $url = esc_url( bbp_get_favorites_permalink( $user_id ) ); 692 $add = preg_replace( '|%(.+)%|', "<a href='$url'>$1</a>", $add ); 693 $favs = array( 'action' => 'bbp_favorite_add', 'topic_id' => $topic_id ); 694 $pre = ( is_array( $add ) && isset( $add['pre'] ) ) ? $add['pre'] : ''; 695 $mid = ( is_array( $add ) && isset( $add['mid'] ) ) ? $add['mid'] : ( is_string( $add ) ? $add : '' ); 696 $_post = ( is_array( $add ) && isset( $add['post'] ) ) ? $add['post'] : ''; 690 $text = $r['favorite']; 691 $query_args = array( 'action' => 'bbp_favorite_add', 'topic_id' => $topic_id ); 697 692 } 698 693 … … 707 702 } 708 703 709 $url = esc_url( wp_nonce_url( add_query_arg( $ favs, $permalink ), 'toggle-favorite_' . $topic_id ) );710 $ fav = $is_fav ? 'is-favorite' : '';711 $html = sprintf( ' <span id="favorite-%d" class="%s">%s<a href="%s" class="favorite-toggle" data-topic="%d" >%s</a>%s</span>', $topic_id, $fav, $pre, $url, $topic_id, $mid, $_post);704 $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-favorite_' . $topic_id ) ); 705 $sub = $is_fav ? ' class="is-favorite"' : ''; 706 $html = sprintf( '%s<span id="favorite-%d" %s><a href="%s" class="favorite-toggle" data-topic="%d">%s</a></span>%s', $r['before'], $topic_id, $sub, $url, $topic_id, $text, $r['after'] ); 712 707 713 708 // Initial output is wrapped in a span, ajax output is hooked to this … … 717 712 718 713 // Return the link 719 return apply_filters( 'bbp_get_user_favorites_link', $html, $ add, $rem, $user_id, $topic_id );714 return apply_filters( 'bbp_get_user_favorites_link', $html, $r, $user_id, $topic_id ); 720 715 } 721 716 … … 787 782 * 788 783 * @param mixed $args See {@link bbp_get_user_subscribe_link()} 784 * @param int $user_id Optional. User id 785 * @param bool $wrap Optional. If you want to wrap the link in <span id="subscription-toggle">. 789 786 * @uses bbp_get_user_subscribe_link() To get the subscribe link 790 787 */ 791 function bbp_user_subscribe_link( $args = '' ) {792 echo bbp_get_user_subscribe_link( $args );788 function bbp_user_subscribe_link( $args = '', $user_id = 0, $wrap = true ) { 789 echo bbp_get_user_subscribe_link( $args, $user_id, $wrap ); 793 790 } 794 791 /** … … 805 802 * - after: After the link 806 803 * @param int $user_id Optional. User id 807 * @param bool $wrap Optional. If you want to wrap the link in <span id=" favorite-toggle">.804 * @param bool $wrap Optional. If you want to wrap the link in <span id="subscription-toggle">. 808 805 * @uses bbp_get_user_id() To get the user id 809 806 * @uses current_user_can() To check if the current user can edit user … … 865 862 $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $topic_id ) ); 866 863 $sub = $is_subscribed ? ' class="is_subscribed"' : ''; 867 $html = sprintf( '%s <span id="subscribe-%d" %s><a href="%s" class="subscription-toggle" data-topic="%d">%s</a></span>' . $r['after'] . '</span>', $r['before'], $topic_id, $sub, $url, $topic_id, $text);864 $html = sprintf( '%s<span id="subscribe-%d" %s><a href="%s" class="subscription-toggle" data-topic="%d">%s</a></span>%s', $r['before'], $topic_id, $sub, $url, $topic_id, $text, $r['after'] ); 868 865 869 866 // Initial output is wrapped in a span, ajax output is hooked to this -
trunk/templates/default/bbpress-functions.php
r4576 r4615 301 301 } 302 302 303 // Put subscription attributes in convenient array 304 $attrs = array( 305 'topic_id' => $topic->ID, 306 'user_id' => $user_id 307 ); 308 303 309 // Action succeeded 304 bbp_ajax_response( true, bbp_get_user_favorites_link( array(), array(), $user_id, $id, false ), 200 );310 bbp_ajax_response( true, bbp_get_user_favorites_link( $attrs, $user_id, false ), 200 ); 305 311 } 306 312 -
trunk/templates/default/bbpress/loop-single-topic.php
r4594 r4615 22 22 <?php do_action( 'bbp_theme_before_topic_favorites_action' ); ?> 23 23 24 <?php bbp_user_favorites_link( array( ' mid' => '+', 'post' => '' ), array( 'pre' => '', 'mid' => '×', 'post' => '' ) ); ?>24 <?php bbp_user_favorites_link( array( 'before' => '', 'favorite' => '+', 'favorited' => '×' ) ); ?> 25 25 26 26 <?php do_action( 'bbp_theme_after_topic_favorites_action' ); ?>
Note: See TracChangeset
for help on using the changeset viewer.