Skip to:
Content

bbPress.org

Ticket #1799: 1799.5.patch

File 1799.5.patch, 13.0 KB (added by thebrandonallen, 10 years ago)

Refresh for current trunk

  • src/includes/core/actions.php

    diff --git src/includes/core/actions.php src/includes/core/actions.php
    index f3395d5..4ce609d 100644
    add_action( 'bbp_unspammed_reply', 'bbp_update_reply_walker' ); 
    254254add_action( 'bbp_approved_reply',   'bbp_update_reply_walker' );
    255255add_action( 'bbp_unapproved_reply', 'bbp_update_reply_walker' );
    256256
     257// Update forum topic/reply counts
     258add_action( 'bbp_new_reply',        'bbp_increase_forum_reply_count'        );
     259add_action( 'bbp_new_topic',        'bbp_increase_forum_topic_count'        );
     260add_action( 'bbp_trashed_reply',    'bbp_decrease_forum_reply_count'        );
     261add_action( 'bbp_trashed_topic',    'bbp_decrease_forum_topic_count'        );
     262add_action( 'bbp_trashed_topic',    'bbp_increase_forum_topic_count_hidden' );
     263add_action( 'bbp_untrashed_reply',  'bbp_increase_forum_reply_count'        );
     264add_action( 'bbp_untrashed_topic',  'bbp_increase_forum_topic_count'        );
     265add_action( 'bbp_untrashed_topic',  'bbp_decrease_forum_topic_count_hidden' );
     266add_action( 'bbp_spammed_reply',    'bbp_decrease_forum_reply_count'        );
     267add_action( 'bbp_spammed_topic',    'bbp_decrease_forum_topic_count'        );
     268add_action( 'bbp_spammed_topic',    'bbp_increase_forum_topic_count_hidden' );
     269add_action( 'bbp_unspammed_reply',  'bbp_increase_forum_reply_count'        );
     270add_action( 'bbp_unspammed_topic',  'bbp_increase_forum_topic_count'        );
     271add_action( 'bbp_unspammed_topic',  'bbp_decrease_forum_topic_count_hidden' );
     272add_action( 'bbp_approved_reply',   'bbp_increase_forum_reply_count'        );
     273add_action( 'bbp_approved_topic',   'bbp_increase_forum_topic_count'        );
     274add_action( 'bbp_approved_topic',   'bbp_decrease_forum_topic_count_hidden' );
     275add_action( 'bbp_unapproved_reply', 'bbp_decrease_forum_reply_count'        );
     276add_action( 'bbp_unapproved_topic', 'bbp_decrease_forum_topic_count'        );
     277add_action( 'bbp_unapproved_topic', 'bbp_increase_forum_topic_count_hidden' );
     278
     279// Update topic reply counts
     280add_action( 'bbp_new_reply',        'bbp_increase_topic_reply_count'        );
     281add_action( 'bbp_trashed_reply',    'bbp_decrease_topic_reply_count'        );
     282add_action( 'bbp_trashed_reply',    'bbp_increase_topic_reply_count_hidden' );
     283add_action( 'bbp_untrashed_reply',  'bbp_increase_topic_reply_count'        );
     284add_action( 'bbp_untrashed_reply',  'bbp_decrease_topic_reply_count_hidden' );
     285add_action( 'bbp_spammed_reply',    'bbp_decrease_topic_reply_count'        );
     286add_action( 'bbp_spammed_reply',    'bbp_increase_topic_reply_count_hidden' );
     287add_action( 'bbp_unspammed_reply',  'bbp_increase_topic_reply_count'        );
     288add_action( 'bbp_unspammed_reply',  'bbp_decrease_topic_reply_count_hidden' );
     289add_action( 'bbp_approved_reply',   'bbp_increase_topic_reply_count'        );
     290add_action( 'bbp_approved_reply',   'bbp_decrease_forum_reply_count_hidden' );
     291add_action( 'bbp_unapproved_reply', 'bbp_decrease_forum_reply_count'        );
     292add_action( 'bbp_unapproved_reply', 'bbp_increase_topic_reply_count_hidden' );
     293
    257294// Users topic & reply counts
    258295add_action( 'bbp_new_topic',     'bbp_increase_user_topic_count' );
    259296add_action( 'bbp_new_reply',     'bbp_increase_user_reply_count' );
  • src/includes/forums/functions.php

    diff --git src/includes/forums/functions.php src/includes/forums/functions.php
    index c6ae18b..4d6a949 100644
    function bbp_bump_forum_topic_count( $forum_id = 0, $difference = 1, $update_anc 
    10891089}
    10901090
    10911091/**
     1092 * Increase the total topic count of a forum by one
     1093 *
     1094 * @since bbPress ()
     1095 *
     1096 * @param int $forum_id Optional. Forum id.
     1097 * @uses bbp_get_forum_id() To get the forum id
     1098 * @uses bbp_bump_forum_topic_count() To bump forum topic count
     1099 */
     1100function bbp_increase_forum_topic_count( $forum_id = 0 ) {
     1101        if ( empty( $forum_id ) ) {
     1102                return;
     1103        }
     1104
     1105        if ( bbp_is_topic( $forum_id ) ) {
     1106                $topic_id = $forum_id;
     1107                $forum_id = bbp_get_topic_forum_id( $topic_id );
     1108
     1109                // If this is a new, unpublished, topic, increase hidden count and bail
     1110                if ( 'bbp_new_topic' === current_action() && ( ! bbp_is_topic_published( $topic_id ) && ! bbp_is_topic_closed( $topic_id ) ) ) {
     1111                        bbp_increase_forum_topic_count_hidden( $forum_id );
     1112                        return;
     1113                }
     1114        }
     1115
     1116        bbp_bump_forum_topic_count( $forum_id );
     1117}
     1118
     1119/**
     1120 * Decrease the total topic count of a forum by one
     1121 *
     1122 * @since bbPress ()
     1123 *
     1124 * @param int $forum_id Optional. Forum id.
     1125 * @uses bbp_get_forum_id() To get the forum id
     1126 * @uses bbp_bump_forum_topic_count() To bump forum topic count
     1127 */
     1128function bbp_decrease_forum_topic_count( $forum_id = 0 ) {
     1129        if ( empty( $forum_id ) ) {
     1130                return;
     1131        }
     1132
     1133        if ( bbp_is_topic( $forum_id ) ) {
     1134                $forum_id = bbp_get_topic_forum_id( $forum_id );
     1135        }
     1136
     1137        bbp_bump_forum_topic_count( $forum_id, -1 );
     1138}
     1139
     1140/**
    10921141 * Bump the total hidden topic count of a forum
    10931142 *
    10941143 * @since bbPress (r3825)
    function bbp_bump_forum_topic_count_hidden( $forum_id = 0, $difference = 1 ) { 
    11161165}
    11171166
    11181167/**
     1168 * Increase the total hidden topic count of a forum by one
     1169 *
     1170 * @since bbPress ()
     1171 *
     1172 * @param int $forum_id Optional. Forum id.
     1173 * @uses bbp_get_forum_id() To get the forum id
     1174 * @uses bbp_bump_forum_topic_count_hidden() To bump forum hidden topic count
     1175 */
     1176function bbp_increase_forum_topic_count_hidden( $forum_id = 0 ) {
     1177        if ( empty( $forum_id ) ) {
     1178                return;
     1179        }
     1180
     1181        if ( bbp_is_topic( $forum_id ) ) {
     1182                $forum_id = bbp_get_topic_forum_id( $forum_id );
     1183        }
     1184
     1185        bbp_bump_forum_topic_count_hidden( $forum_id );
     1186}
     1187
     1188/**
     1189 * Decrease the total hidden topic count of a forum by one
     1190 *
     1191 * @since bbPress ()
     1192 *
     1193 * @param int $forum_id Optional. Forum id.
     1194 * @uses bbp_get_forum_id() To get the forum id
     1195 * @uses bbp_bump_forum_topic_count_hidden() To bump forum hidden topic count
     1196 */
     1197function bbp_decrease_forum_topic_count_hidden( $forum_id = 0 ) {
     1198        if ( empty( $forum_id ) ) {
     1199                return;
     1200        }
     1201
     1202        if ( bbp_is_topic( $forum_id ) ) {
     1203                $forum_id = bbp_get_topic_forum_id( $forum_id );
     1204        }
     1205
     1206        bbp_bump_forum_topic_count_hidden( $forum_id, -1 );
     1207}
     1208
     1209/**
    11191210 * Bump the total topic count of a forum
    11201211 *
    11211212 * @since bbPress (r3825)
    function bbp_bump_forum_reply_count( $forum_id = 0, $difference = 1, $update_anc 
    11651256        return (int) apply_filters( 'bbp_bump_forum_reply_count', (int) $total_reply_count + (int) $difference, $forum_id, (int) $difference, (bool) $update_ancestors );
    11661257}
    11671258
     1259/**
     1260 * Increase the total reply count of a forum by one
     1261 *
     1262 * @since bbPress ()
     1263 *
     1264 * @param int $forum_id Optional. Forum id.
     1265 * @uses bbp_get_forum_id() To get the forum id
     1266 * @uses bbp_bump_forum_reply_count() To bump forum topic count
     1267 */
     1268function bbp_increase_forum_reply_count( $forum_id = 0 ) {
     1269        if ( empty( $forum_id ) ) {
     1270                return;
     1271        }
     1272
     1273        if ( bbp_is_reply( $forum_id ) ) {
     1274                $reply_id = $forum_id;
     1275                $forum_id = bbp_get_reply_forum_id( $reply_id );
     1276
     1277                // Don't update if this is a new, unpublished, reply
     1278                if ( 'bbp_new_reply' === current_action() && ! bbp_is_reply_published( $reply_id ) ) {
     1279                        return;
     1280                }
     1281        }
     1282
     1283        bbp_bump_forum_reply_count( $forum_id, 1 );
     1284}
     1285
     1286/**
     1287 * Decrease the total reply count of a forum by one
     1288 *
     1289 * @since bbPress ()
     1290 *
     1291 * @param int $forum_id Optional. Forum id.
     1292 * @uses bbp_get_forum_id() To get the forum id
     1293 * @uses bbp_bump_forum_reply_count() To bump forum topic count
     1294 */
     1295function bbp_decrease_forum_reply_count( $forum_id = 0 ) {
     1296        if ( empty( $forum_id ) ) {
     1297                return;
     1298        }
     1299
     1300        if ( bbp_is_reply( $forum_id ) ) {
     1301                $forum_id = bbp_get_reply_forum_id( $forum_id );
     1302        }
     1303
     1304        bbp_bump_forum_reply_count( $forum_id, -1 );
     1305}
     1306
    11681307/** Forum Updaters ************************************************************/
    11691308
    11701309/**
    function bbp_update_forum( $args = '' ) { 
    16221761        }
    16231762
    16241763        // Counts
    1625         bbp_update_forum_subforum_count    ( $r['forum_id'] );
    1626         bbp_update_forum_reply_count       ( $r['forum_id'] );
    1627         bbp_update_forum_topic_count       ( $r['forum_id'] );
    1628         bbp_update_forum_topic_count_hidden( $r['forum_id'] );
     1764        bbp_update_forum_subforum_count( $r['forum_id'] );
     1765
     1766        // Only update topic count if we're deleting a topic, or in the dashboard
     1767        if ( in_array( current_action(), array( 'bbp_deleted_topic', 'save_post' ) ) ) {
     1768                bbp_update_forum_reply_count(        $r['forum_id'] );
     1769                bbp_update_forum_topic_count(        $r['forum_id'] );
     1770                bbp_update_forum_topic_count_hidden( $r['forum_id'] );
     1771        }
    16291772
    16301773        // Update the parent forum if one was passed
    16311774        if ( !empty( $r['post_parent'] ) && is_numeric( $r['post_parent'] ) ) {
  • src/includes/replies/functions.php

    diff --git src/includes/replies/functions.php src/includes/replies/functions.php
    index a4698d0..98c51f0 100644
    function bbp_update_reply_walker( $reply_id, $last_active_time = '', $forum_id = 
    984984                                }
    985985
    986986                                // Counts
    987                                 bbp_update_topic_voice_count       ( $ancestor );
    988                                 bbp_update_topic_reply_count       ( $ancestor );
    989                                 bbp_update_topic_reply_count_hidden( $ancestor );
     987                                bbp_update_topic_voice_count( $ancestor );
     988
     989                                // Only update reply count if we're deleting a reply, or in the dashboard
     990                                if ( in_array( current_action(), array( 'bbp_deleted_reply', 'save_post' ) ) ) {
     991                                        bbp_update_topic_reply_count(        $ancestor );
     992                                        bbp_update_topic_reply_count_hidden( $ancestor );
     993                                }
    990994
    991995                        // Forum meta relating to most recent topic
    992996                        } elseif ( bbp_is_forum( $ancestor ) ) {
    function bbp_update_reply_walker( $reply_id, $last_active_time = '', $forum_id = 
    10101014                                }
    10111015
    10121016                                // Counts
    1013                                 bbp_update_forum_reply_count( $ancestor );
     1017                                // Only update reply count if we're deleting a reply, or in the dashboard
     1018                                if ( in_array( current_action(), array( 'bbp_deleted_reply', 'save_post' ) ) ) {
     1019                                        bbp_update_forum_reply_count( $ancestor );
     1020                                }
    10141021                        }
    10151022                }
    10161023        }
  • src/includes/topics/functions.php

    diff --git src/includes/topics/functions.php src/includes/topics/functions.php
    index c23e4b3..ee3f9aa 100644
    function bbp_bump_topic_reply_count( $topic_id = 0, $difference = 1 ) { 
    23472347}
    23482348
    23492349/**
     2350 * Increase the total reply count of a topic by one
     2351 *
     2352 * @since bbPress ()
     2353 *
     2354 * @param int $topic_id Optional. Forum id.
     2355 * @uses bbp_is_reply() To check if the passed topic id is a reply
     2356 * @uses bbp_get_reply_topic_id() To get the topic id
     2357 * @uses bbp_bump_topic_reply_count() To bump topic reply count
     2358 */
     2359function bbp_increase_topic_reply_count( $topic_id = 0 ) {
     2360        if ( empty( $topic_id ) ) {
     2361                return;
     2362        }
     2363
     2364        if ( bbp_is_reply( $topic_id ) ) {
     2365                $reply_id = $topic_id;
     2366                $topic_id = bbp_get_reply_topic_id( $reply_id );
     2367
     2368                // If this is a new, unpublished, reply, update hidden count and bail
     2369                if ( 'bbp_new_reply' === current_action() && ! bbp_is_reply_published( $reply_id ) ) {
     2370                        bbp_increase_topic_reply_count_hidden( $topic_id );
     2371                        return;
     2372                }
     2373        }
     2374
     2375        bbp_bump_topic_reply_count( $topic_id );
     2376}
     2377
     2378/**
     2379 * Decrease the total reply count of a topic by one
     2380 *
     2381 * @since bbPress ()
     2382 *
     2383 * @param int $topic_id Optional. Topic id.
     2384 * @uses bbp_is_reply() To check if the passed topic id is a reply
     2385 * @uses bbp_get_reply_topic_id() To get the topic id
     2386 * @uses bbp_bump_topic_reply_count() To bump topic reply count
     2387 */
     2388function bbp_decrease_topic_reply_count( $topic_id = 0 ) {
     2389        if ( empty( $topic_id ) ) {
     2390                return;
     2391        }
     2392
     2393        if ( bbp_is_reply( $topic_id ) ) {
     2394                $topic_id = bbp_get_reply_topic_id( $topic_id );
     2395        }
     2396
     2397        bbp_bump_topic_reply_count( $topic_id, -1 );
     2398}
     2399
     2400/**
    23502401 * Bump the total hidden reply count of a topic
    23512402 *
    23522403 * @since bbPress (r3825)
    function bbp_bump_topic_reply_count_hidden( $topic_id = 0, $difference = 1 ) { 
    23732424        return (int) apply_filters( 'bbp_bump_topic_reply_count_hidden', (int) $new_count, $topic_id, (int) $difference );
    23742425}
    23752426
     2427/**
     2428 * Increase the total hidden reply count of a topic by one
     2429 *
     2430 * @since bbPress ()
     2431 *
     2432 * @param int $topic_id Optional. Topic id.
     2433 * @uses bbp_is_reply() To check if the passed topic id is a reply
     2434 * @uses bbp_get_reply_topic_id() To get the topic id
     2435 * @uses bbp_bump_topic_reply_count_hidden() To bump topic hidden reply count
     2436 */
     2437function bbp_increase_topic_reply_count_hidden( $topic_id = 0 ) {
     2438        if ( empty( $topic_id ) ) {
     2439                return;
     2440        }
     2441
     2442        if ( bbp_is_reply( $topic_id ) ) {
     2443                $topic_id = bbp_get_reply_topic_id( $topic_id );
     2444        }
     2445
     2446        bbp_bump_topic_reply_count_hidden( $topic_id );
     2447}
     2448
     2449/**
     2450 * Decrease the total hidden reply count of a topic by one
     2451 *
     2452 * @since bbPress ()
     2453 *
     2454 * @param int $topic_id Optional. Topic id.
     2455 * @uses bbp_is_reply() To check if the passed topic id is a reply
     2456 * @uses bbp_get_reply_topic_id() To get the topic id
     2457 * @uses bbp_bump_topic_reply_count_hidden() To bump topic hidden reply count
     2458 */
     2459function bbp_decrease_topic_reply_count_hidden( $topic_id = 0 ) {
     2460        if ( empty( $topic_id ) ) {
     2461                return;
     2462        }
     2463
     2464        if ( bbp_is_reply( $topic_id ) ) {
     2465                $topic_id = bbp_get_reply_topic_id( $topic_id );
     2466        }
     2467
     2468        bbp_bump_topic_reply_count_hidden( $topic_id, -1 );
     2469}
     2470
    23762471/** Topic Updaters ************************************************************/
    23772472
    23782473/**