Skip to:
Content

bbPress.org

Changeset 2567


Ignore:
Timestamp:
10/19/2010 06:51:32 AM (16 years ago)
Author:
johnjamesjacoby
Message:

First pass at Voices. Fixes #1330. Props GautamGupta

Location:
branches/plugin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-filters.php

    r2486 r2567  
    55add_filter( 'bbp_get_forum_topic_reply_count', 'bbp_number_format' );
    66
     7// Add hooks to insert and delete post functions to update our voice counts
     8add_action( 'wp_insert_post', 'bbp_update_topic_voice_count' );
     9add_action( 'wp_delete_post', 'bbp_update_topic_voice_count' );
     10
    711?>
  • branches/plugin/bbp-templatetags.php

    r2565 r2567  
    244244         */
    245245        function bbp_get_forum_last_active ( $forum_id = 0 ) {
    246                 if ( !$forum_id )
     246                if ( empty( $forum_id ) )
    247247                        $forum_id = bbp_get_forum_id();
    248248
     
    283283         */
    284284        function bbp_get_forum_topic_count ( $forum_id = 0 ) {
    285                 if ( !$forum_id )
     285                if ( empty( $forum_id ) )
    286286                        $forum_id = bbp_get_forum_id();
    287287
     
    309309 */
    310310function bbp_update_forum_topic_count ( $new_topic_count, $forum_id = 0 ) {
    311         if ( !$forum_id )
     311        if ( empty( $forum_id ) )
    312312                $forum_id = bbp_get_forum_id();
    313313
     
    348348         */
    349349        function bbp_get_forum_topic_reply_count ( $forum_id = 0 ) {
    350                 if ( !$forum_id )
     350                if ( empty( $forum_id ) )
    351351                        $forum_id = bbp_get_forum_id();
    352352
     
    378378 */
    379379function bbp_update_forum_topic_reply_count ( $new_topic_reply_count, $forum_id = 0 ) {
    380         if ( !$forum_id )
     380        if ( empty( $forum_id ) )
    381381                $forum_id = bbp_get_forum_id();
    382382
     
    673673                        global $bbp_topics_template;
    674674
    675                         if ( !$topic_id )
     675                        if ( empty( $topic_id ) )
    676676                                $topic_id = bbp_get_topic_id();
    677677
     
    711711         */
    712712        function bbp_get_topic_last_active ( $topic_id = '' ) {
    713                 if ( !$topic_id )
     713                if ( empty( $topic_id ) )
    714714                        $topic_id = bbp_get_topic_id();
    715715
     
    733733}
    734734        /**
    735          * bbp_topic_reply_count ()
     735         * bbp_get_topic_reply_count ()
    736736         *
    737737         * Return total post count of a topic
     
    750750         */
    751751        function bbp_get_topic_reply_count ( $topic_id = '' ) {
    752                 if ( !$topic_id )
     752                if ( empty( $topic_id ) )
    753753                        $topic_id = bbp_get_topic_id();
    754754
     
    771771 * @todo make this not suck
    772772 *
    773  * @uses bbp_get_topic_id(0
     773 * @uses bbp_get_topic_id()
    774774 * @uses apply_filters
    775775 *
     
    780780 */
    781781function bbp_update_topic_reply_count ( $new_topic_reply_count, $topic_id = '' ) {
    782         if ( !$topic_id )
     782        if ( empty( $topic_id ) )
    783783                $topic_id = bbp_get_topic_id();
    784784
    785785        return apply_filters( 'bbp_update_topic_reply_count', (int)update_post_meta( $topic_id, 'bbp_topic_reply_count', $new_topic_reply_count ) );
     786}
     787
     788/**
     789 * bbp_topic_voice_count ()
     790 *
     791 * Output total voice count of a topic
     792 *
     793 * @package bbPress
     794 * @subpackage Template Tags
     795 * @since bbPress (1.2-r2565)
     796 *
     797 * @uses bbp_get_topic_voice_count()
     798 * @uses apply_filters
     799 *
     800 * @param int $topic_id
     801 */
     802function bbp_topic_voice_count ( $topic_id = 0 ) {
     803        echo bbp_get_topic_voice_count( $topic_id );
     804}
     805        /**
     806         * bbp_get_topic_voice_count ()
     807         *
     808         * Return total voice count of a topic
     809         *
     810         * @package bbPress
     811         * @subpackage Template Tags
     812         * @since bbPress (1.2-r2565)
     813         *
     814         * @uses bbp_get_topic_id()
     815         * @uses apply_filters
     816         *
     817         * @param int $topic_id
     818         *
     819         * @return int Voice count of the topic
     820         */
     821        function bbp_get_topic_voice_count ( $topic_id = 0 ) {
     822                if ( empty( $topic_id ) )
     823                        $topic_id = bbp_get_topic_id();
     824
     825                if ( !$voices = get_post_meta( $topic_id, 'bbp_topic_voice_count', true ) )
     826                        $voices = bbp_update_topic_voice_count( $topic_id );
     827
     828                return apply_filters( 'bbp_get_topic_voice_count', (int)$voices, $topic_id );
     829        }
     830
     831/**
     832 * bbp_update_topic_voice_count ()
     833 *
     834 * Adjust the total voice count of a topic
     835 *
     836 * @package bbPress
     837 * @subpackage Template Tags
     838 * @since bbPress (1.2-r2565)
     839 *
     840 * @uses bbp_get_topic_id()
     841 * @uses wpdb
     842 * @uses apply_filters
     843 *
     844 * @todo cache
     845 *
     846 * @param int $topic_id optional Topic ID to update
     847 *
     848 * @return bool false on failure, voice count on success
     849 */
     850function bbp_update_topic_voice_count ( $topic_id = 0 ) {
     851        global $wpdb;
     852
     853        if ( empty( $topic_id ) )
     854                $topic_id = bbp_get_topic_id();
     855
     856        if ( !in_array( get_post_field( 'post_type', $topic_id ), array( BBP_TOPIC_POST_TYPE_ID, BBP_REPLY_POST_TYPE_ID ) ) ) /* If it is not a topic or reply, then we don't need it */
     857                return false;
     858
     859        // If it's a reply, then get the parent (topic id)
     860        if ( BBP_REPLY_POST_TYPE_ID == get_post_field( 'post_type', $topic_id ) )
     861                $topic_id = get_post_field( 'post_parent', $topic_id );
     862
     863        // There should always be at least 1 voice
     864        if ( !$voices = count( $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE ( post_parent = %d AND post_status = 'publish' AND post_type = '" . BBP_REPLY_POST_TYPE_ID . "' ) OR ( ID = %d AND post_type = '" . BBP_TOPIC_POST_TYPE_ID . "' );", $topic_id, $topic_id ) ) ) )
     865                $voices = 1;
     866
     867        update_post_meta( $topic_id, 'bbp_topic_voice_count', $voices );
     868
     869        return apply_filters( 'bbp_update_topic_voice_count', (int)$voices );
    786870}
    787871
     
    11891273         */
    11901274        function bbp_get_reply_topic_id ( $reply_id = 0 ) {
    1191                 if ( !$reply_id )
     1275                if ( empty( $reply_id ) )
    11921276                        $reply_id = bbp_get_reply_id();
    11931277
  • branches/plugin/bbp-themes/bbp-twentyten/loop-bbp_topics.php

    r2564 r2567  
    3636                                        <td class="bbp-topic-replies"><?php bbp_topic_reply_count(); ?></td>
    3737
    38                                         <td class="bbp-topic-voices"><?php // @todo - bbp_topic_voice_count(); ?></td>
     38                                        <td class="bbp-topic-voices"><?php bbp_topic_voice_count(); ?></td>
    3939
    4040                                        <td class="bbp-topic-freshness">
Note: See TracChangeset for help on using the changeset viewer.