Skip to:
Content

bbPress.org


Ignore:
Timestamp:
12/05/2012 09:02:01 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Subscriptions/Favorites:

  • Improvements to AJAX handling.
  • Introduces bbp_ajax_response() function in common/functions.php, to handle JSON output.
  • Adds AJAX failure responses.
  • Props MZAWeb.
  • Fixes #1905.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/users/template-tags.php

    r4542 r4543  
    640640         * @param int $user_id Optional. User id
    641641         * @param int $topic_id Optional. Topic id
     642         * @param bool $wrap Optional. If you want to wrap the link in <span id="favorite-toggle">. See ajax_favorite()
    642643         * @uses bbp_get_user_id() To get the user id
    643644         * @uses current_user_can() If the current user can edit the user
     
    651652         * @return string User favorites link
    652653         */
    653         function bbp_get_user_favorites_link( $add = array(), $rem = array(), $user_id = 0, $topic_id = 0 ) {
     654        function bbp_get_user_favorites_link( $add = array(), $rem = array(), $user_id = 0, $topic_id = 0, $wrap = true ) {
    654655                if ( !bbp_is_favorites_active() )
    655656                        return false;
     
    704705                } elseif ( is_singular( bbp_get_reply_post_type() ) ) {
    705706                        $permalink = bbp_get_topic_permalink( $topic_id );
    706                 } elseif ( bbp_is_query_name( 'bbp_single_topic' ) ) {
     707                } else {
    707708                        $permalink = get_permalink();
    708709                }
    709710
    710                 $url    = esc_url( wp_nonce_url( add_query_arg( $favs, $permalink ), 'toggle-favorite_' . $topic_id ) );
    711                 $is_fav = $is_fav ? 'is-favorite' : '';
    712                 $html   = '<span id="favorite-toggle"><span id="favorite-' . $topic_id . '" class="' . $is_fav . '">' . $pre . '<a href="' . $url . '" class="dim:favorite-toggle:favorite-' . $topic_id . ':is-favorite">' . $mid . '</a>' . $_post . '</span></span>';
     711                $url  = esc_url( wp_nonce_url( add_query_arg( $favs, $permalink ), 'toggle-favorite_' . $topic_id ) );
     712                $fav  = $is_fav ? 'is-favorite' : '';
     713                $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 );
     714
     715                // Initial output is wrapped in a span, ajax output is hooked to this
     716                if ( !empty( $wrap ) ) {
     717                        $html = '<span id="favorite-toggle">' . $html . '</span>';
     718                }
    713719
    714720                // Return the link
     
    801807         *  - after: After the link
    802808         * @param int $user_id Optional. User id
     809         * @param bool $wrap Optional. If you want to wrap the link in <span id="favorite-toggle">.
    803810         * @uses bbp_get_user_id() To get the user id
    804811         * @uses current_user_can() To check if the current user can edit user
     
    812819         * @return string Permanent link to topic
    813820         */
    814         function bbp_get_user_subscribe_link( $args = '', $user_id = 0 ) {
     821        function bbp_get_user_subscribe_link( $args = '', $user_id = 0, $wrap = true ) {
    815822                if ( !bbp_is_subscriptions_active() )
    816823                        return;
     
    856863                } elseif ( is_singular( bbp_get_reply_post_type() ) ) {
    857864                        $permalink = bbp_get_topic_permalink( $topic_id );
    858                 } elseif ( bbp_is_query_name( 'bbp_single_topic' ) ) {
     865                } else {
    859866                        $permalink = get_permalink();
    860867                }
    861868
    862                 $url        = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $topic_id ) );
    863                 $subscribed = $is_subscribed ? ' class="is_subscribed"' : '';
    864                 $html       = '<span id="subscription-toggle">' . $r['before'] . '<span id="subscribe-' . $topic_id . '"' . $subscribed . '><a href="' . $url . '" class="dim:subscription-toggle:subscribe-' . $topic_id . ':is-subscribed">' . $text . '</a></span>' . $r['after'] . '</span>';
     869                $url  = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $topic_id ) );
     870                $sub  = $is_subscribed ? ' class="is_subscribed"' : '';
     871                $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 );
     872
     873                // Initial output is wrapped in a span, ajax output is hooked to this
     874                if ( !empty( $wrap ) ) {
     875                        $html = '<span id="subscription-toggle">' . $html . '</span>';
     876                }
    865877
    866878                // Return the link
Note: See TracChangeset for help on using the changeset viewer.