Skip to:
Content

bbPress.org

Changeset 3826


Ignore:
Timestamp:
03/26/2012 07:36:47 AM (10 years ago)
Author:
johnjamesjacoby
Message:

Add 'bump' functions for forum, topic, reply, and voice counts.

  • Functions not used yet
  • See #1799
Location:
branches/plugin/bbp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-forum-functions.php

    r3799 r3826  
    951951}
    952952
     953/** Count Bumpers *************************************************************/
     954
     955/**
     956 * Bump the total topic count of a forum
     957 *
     958 * @since bbPress (r3825)
     959 *
     960 * @param int $forum_id Optional. Forum id.
     961 * @param int $difference Optional. Default 1
     962 * @param bool $update_ancestors Optional. Default true
     963 * @uses bbp_get_forum_id() To get the forum id
     964 * @uses update_post_meta() To update the forum's topic count meta
     965 * @uses apply_filters() Calls 'bbp_bump_forum_topic_count' with the topic
     966 *                        count, forum id, and difference
     967 * @return int Forum topic count
     968 */
     969function bbp_bump_forum_topic_count( $forum_id = 0, $difference = 1, $update_ancestors = true ) {
     970
     971    // Get some counts
     972    $forum_id          = bbp_get_forum_id( $forum_id );
     973    $topic_count       = bbp_get_forum_topic_count( $forum_id, false );
     974    $total_topic_count = bbp_get_forum_topic_count( $forum_id, true  );
     975
     976    // Update this forum id
     977    update_post_meta( $forum_id, '_bbp_topic_count',       (int) $topic_count       + (int) $difference );
     978    update_post_meta( $forum_id, '_bbp_total_topic_count', (int) $total_topic_count + (int) $difference );
     979
     980    // Check for ancestors
     981    if ( true === $update_ancestors ) {
     982
     983        // Get post ancestors
     984        $forum     = get_post( $forum_id );
     985        $ancestors = get_post_ancestors( $forum );
     986
     987        // If has ancestors, loop through them...
     988        if ( !empty( $ancestors ) ) {
     989            foreach ( (array) $ancestors as $parent_forum_id ) {
     990
     991                // Get forum counts
     992                $parent_topic_count       = bbp_get_forum_topic_count( $parent_forum_id, false );
     993                $parent_total_topic_count = bbp_get_forum_topic_count( $parent_forum_id, true  );
     994
     995                // Update counts
     996                update_post_meta( $parent_forum_id, '_bbp_topic_count',       (int) $parent_topic_count       + (int) $difference );
     997                update_post_meta( $parent_forum_id, '_bbp_total_topic_count', (int) $parent_total_topic_count + (int) $difference );
     998            }
     999        }
     1000    }
     1001
     1002    return (int) apply_filters( 'bbp_bump_forum_topic_count', (int) $total_topic_count + (int) $difference, $forum_id, (int) $difference, (bool) $update_ancestors );
     1003}
     1004
     1005/**
     1006 * Bump the total hidden topic count of a forum
     1007 *
     1008 * @since bbPress (r3825)
     1009 *
     1010 * @param int $forum_id Optional. Forum id.
     1011 * @param int $difference Optional. Default 1
     1012 * @uses bbp_get_forum_id() To get the forum id
     1013 * @uses update_post_meta() To update the forum's topic count meta
     1014 * @uses apply_filters() Calls 'bbp_bump_forum_topic_count_hidden' with the
     1015 *                        topic count, forum id, and difference
     1016 * @return int Forum hidden topic count
     1017 */
     1018function bbp_bump_forum_topic_count_hidden( $forum_id = 0, $difference = 1 ) {
     1019
     1020    // Get some counts
     1021    $forum_id    = bbp_get_forum_id( $forum_id );
     1022    $topic_count = bbp_get_forum_topic_count_hidden( $forum_id, false );
     1023    $new_count   = (int) $topic_count + (int) $difference;
     1024
     1025    // Update this forum id
     1026    update_post_meta( $forum_id, '_bbp_topic_count_hidden', (int) $new_count );
     1027
     1028    return (int) apply_filters( 'bbp_bump_forum_topic_count_hidden', (int) $new_count, $forum_id, (int) $difference );
     1029}
     1030
     1031/**
     1032 * Bump the total topic count of a forum
     1033 *
     1034 * @since bbPress (r3825)
     1035 *
     1036 * @param int $forum_id Optional. Forum id.
     1037 * @param int $difference Optional. Default 1
     1038 * @param bool $update_ancestors Optional. Default true
     1039 * @uses bbp_get_forum_id() To get the forum id
     1040 * @uses update_post_meta() To update the forum's topic count meta
     1041 * @uses apply_filters() Calls 'bbp_bump_forum_reply_count' with the topic
     1042 *                        count, forum id, and difference
     1043 * @return int Forum topic count
     1044 */
     1045function bbp_bump_forum_reply_count( $forum_id = 0, $difference = 1, $update_ancestors = true ) {
     1046
     1047    // Get some counts
     1048    $forum_id          = bbp_get_forum_id( $forum_id );
     1049    $topic_count       = bbp_get_forum_reply_count( $forum_id, false );
     1050    $total_reply_count = bbp_get_forum_reply_count( $forum_id, true  );
     1051
     1052    // Update this forum id
     1053    update_post_meta( $forum_id, '_bbp_reply_count',       (int) $topic_count       + (int) $difference );
     1054    update_post_meta( $forum_id, '_bbp_total_reply_count', (int) $total_reply_count + (int) $difference );
     1055
     1056    // Check for ancestors
     1057    if ( true === $update_ancestors ) {
     1058
     1059        // Get post ancestors
     1060        $forum     = get_post( $forum_id );
     1061        $ancestors = get_post_ancestors( $forum );
     1062
     1063        // If has ancestors, loop through them...
     1064        if ( !empty( $ancestors ) ) {
     1065            foreach ( (array) $ancestors as $parent_forum_id ) {
     1066
     1067                // Get forum counts
     1068                $parent_topic_count       = bbp_get_forum_reply_count( $parent_forum_id, false );
     1069                $parent_total_reply_count = bbp_get_forum_reply_count( $parent_forum_id, true  );
     1070
     1071                // Update counts
     1072                update_post_meta( $parent_forum_id, '_bbp_reply_count',       (int) $parent_topic_count       + (int) $difference );
     1073                update_post_meta( $parent_forum_id, '_bbp_total_reply_count', (int) $parent_total_reply_count + (int) $difference );
     1074            }
     1075        }
     1076    }
     1077
     1078    return (int) apply_filters( 'bbp_bump_forum_reply_count', (int) $total_reply_count + (int) $difference, $forum_id, (int) $difference, (bool) $update_ancestors );
     1079}
     1080
    9531081/** Forum Updaters ************************************************************/
    9541082
  • branches/plugin/bbp-includes/bbp-topic-functions.php

    r3808 r3826  
    20472047}
    20482048
     2049/** Count Bumpers *************************************************************/
     2050
     2051/**
     2052 * Bump the total reply count of a topic
     2053 *
     2054 * @since bbPress (r3825)
     2055 *
     2056 * @param int $topic_id Optional. Forum id.
     2057 * @param int $difference Optional. Default 1
     2058 * @param bool $update_ancestors Optional. Default true
     2059 * @uses bbp_get_topic_id() To get the topic id
     2060 * @uses update_post_meta() To update the topic's reply count meta
     2061 * @uses apply_filters() Calls 'bbp_bump_topic_reply_count' with the reply
     2062 *                        count, topic id, and difference
     2063 * @return int Forum reply count
     2064 */
     2065function bbp_bump_topic_reply_count( $topic_id = 0, $difference = 1 ) {
     2066
     2067    // Get counts
     2068    $topic_id    = bbp_get_topic_id( $topic_id );
     2069    $reply_count = bbp_get_topic_reply_count( $topic_id, false );
     2070    $new_count   = (int) $reply_count + (int) $difference;
     2071
     2072    // Update this topic id's reply count
     2073    update_post_meta( $topic_id, '_bbp_reply_count', (int) $new_count );
     2074
     2075    return (int) apply_filters( 'bbp_bump_topic_reply_count', (int) $new_count, $topic_id, (int) $difference );
     2076}
     2077
     2078/**
     2079 * Bump the total hidden reply count of a topic
     2080 *
     2081 * @since bbPress (r3825)
     2082 *
     2083 * @param int $topic_id Optional. Forum id.
     2084 * @param int $difference Optional. Default 1
     2085 * @uses bbp_get_topic_id() To get the topic id
     2086 * @uses update_post_meta() To update the topic's reply count meta
     2087 * @uses apply_filters() Calls 'bbp_bump_topic_reply_count_hidden' with the
     2088 *                        reply count, topic id, and difference
     2089 * @return int Forum hidden reply count
     2090 */
     2091function bbp_bump_topic_reply_count_hidden( $topic_id = 0, $difference = 1 ) {
     2092
     2093    // Get counts
     2094    $topic_id    = bbp_get_topic_id( $topic_id );
     2095    $reply_count = bbp_get_topic_reply_count_hidden( $topic_id, false );
     2096    $new_count   = (int) $reply_count + (int) $difference;
     2097
     2098    // Update this topic id's hidder reply count
     2099    update_post_meta( $topic_id, '_bbp_reply_count_hidden', (int) $new_count );
     2100
     2101    return (int) apply_filters( 'bbp_bump_topic_reply_count_hidden', (int) $new_count, $topic_id, (int) $difference );
     2102}
     2103
    20492104/** Topic Updaters ************************************************************/
    20502105
     
    23192374    $voices = $wpdb->get_col( $wpdb->prepare( "SELECT COUNT( DISTINCT post_author ) FROM {$wpdb->posts} WHERE ( post_parent = %d AND post_status = '%s' AND post_type = '%s' ) OR ( ID = %d AND post_type = '%s' );", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ) );
    23202375
    2321     // If there's an error, make sure we at least have 1 voice
     2376    // If there's an error, make sure we have at least have 1 voice
    23222377    $voices = ( empty( $voices ) || is_wp_error( $voices ) ) ? 1 : $voices[0];
    23232378
Note: See TracChangeset for help on using the changeset viewer.