Changeset 2806
- Timestamp:
- 01/14/2011 07:22:08 PM (13 years ago)
- Location:
- branches/plugin/bbp-includes
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-includes/bbp-forum-functions.php
r2790 r2806 237 237 * is a topic or a forum. If it's a topic, its parent, 238 238 * i.e. the forum is automatically retrieved. 239 * @param bool $total_count Optional. To return the total count or normal 240 * count? 239 241 * @uses get_post_field() To check whether the supplied id is a topic 240 242 * @uses bbp_get_topic_forum_id() To get the topic's forum id 241 243 * @uses wpdb::prepare() To prepare the sql statement 242 244 * @uses wpdb::get_col() To execute the query and get the column back 245 * @uses bbp_get_topic_status() To get the topic status 243 246 * @uses update_post_meta() To update the forum's topic count meta 244 247 * @uses apply_filters() Calls 'bbp_update_forum_topic_count' with the topic 245 * count and forum id248 * count, forum id and total count bool 246 249 * @return int Forum topic count 247 250 */ 248 function bbp_update_forum_topic_count( $forum_id = 0 ) {251 function bbp_update_forum_topic_count( $forum_id = 0, $total_count = true ) { 249 252 global $wpdb, $bbp; 250 253 251 254 $forum_id = bbp_get_forum_id( $forum_id ); 252 255 253 // If it's a reply, then get the parent (topic id) 254 if ( $bbp->topic_id == get_post_field( 'post_type', $forum_id ) ) 256 // If it's a topic, then get the parent (forum id) 257 if ( $bbp->topic_id == get_post_field( 'post_type', $forum_id ) ) { 258 $topic_id = $forum_id; 255 259 $forum_id = bbp_get_topic_forum_id( $forum_id ); 256 257 // Get topics count 258 $topics = count( $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status = 'publish' AND post_type = '" . $bbp->topic_id . "';", $forum_id ) ) ); 260 } 261 262 $topics = $children_topic_count = 0; 263 $children = get_posts( array( 'post_parent' => $forum_id, 'post_type' => $bbp->forum_id, 'meta_key' => '_bbp_forum_visibility', 'meta_value' => 'public' ) ); 264 265 // Loop through children and add together forum topic counts 266 foreach ( (array) $children as $child ) 267 $children_topic_count += (int) bbp_get_forum_topic_count( $child->ID ); 268 269 // Don't count topics if the forum is a category 270 if ( !bbp_is_forum_category( $forum_id ) ) { 271 if ( empty( $topic_id ) || !$topics = (int) get_post_meta( $forum_id, '_bbp_forum_topic_count', true ) ) { 272 $topics = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( '" . join( "', '", array( 'publish', $bbp->closed_status_id ) ) . "' ) AND post_type = '" . $bbp->topic_id . "';", $forum_id ) ); 273 } else { 274 if ( in_array( bbp_get_topic_status( $topic_id ), array( 'publish', $bbp->closed_status_id ) ) ) { 275 $topics++; 276 } else { 277 $topics--; 278 } 279 } 280 } 281 282 // Calculate total topics in this forum 283 $total_topics = $topics + $children_topic_count; 259 284 260 285 // Update the count 261 update_post_meta( $forum_id, '_bbp_forum_topic_count', (int) $topics ); 262 263 return apply_filters( 'bbp_update_forum_topic_count', (int) $topics, $forum_id ); 286 update_post_meta( $forum_id, '_bbp_forum_topic_count', $topics ); 287 update_post_meta( $forum_id, '_bbp_forum_total_topic_count', $total_topics ); 288 289 // Walk up ancestors 290 if ( $parent_id = bbp_get_forum_parent( $forum_id ) ) 291 bbp_update_forum_topic_count( $parent_id ); 292 293 return apply_filters( 'bbp_update_forum_topic_count', empty( $total_count ) ? $topics : $total_topics, $forum_id, $total_count ); 264 294 } 265 295 … … 271 301 * @since bbPress (r2464) 272 302 * 273 * @param int $forum_id Optional. Forum id or reply id. It is checked whether it 274 * is a reply or a forum. If it's a reply, its forum is 275 * automatically retrieved. 303 * @param int $forum_id Optional. Forum id or topic id reply id. It is checked 304 * whether it is a reply or a topic or a forum and the 305 * forum id is automatically retrieved. 306 * @param bool $total_count Optional. To return the total count or normal 307 * count? 276 308 * @uses get_post_field() To check whether the supplied id is a reply 277 * @uses bbp_get_reply_ topic_id() To get the reply's topicid309 * @uses bbp_get_reply_forum_id() To get the reply's forum id 278 310 * @uses bbp_get_topic_forum_id() To get the topic's forum id 279 311 * @uses wpdb::prepare() To prepare the sql statement 280 312 * @uses wpdb::get_col() To execute the query and get the column back 313 * @uses wpdb::get_var() To execute the query and get the var back 314 * @uses bbp_get_reply_status() To get the reply status 281 315 * @uses update_post_meta() To update the forum's reply count meta 282 316 * @uses apply_filters() Calls 'bbp_update_forum_reply_count' with the reply 283 * count and forum id317 * count, forum id and total count bool 284 318 * @return int Forum reply count 285 319 */ 286 function bbp_update_forum_reply_count( $forum_id = 0 ) {320 function bbp_update_forum_reply_count( $forum_id = 0, $total_count = true ) { 287 321 global $wpdb, $bbp; 288 322 289 323 $forum_id = bbp_get_forum_id( $forum_id ); 290 324 291 // If it's a reply, then get the parent (topicid)325 // If it's a reply, then get the grandparent (forum id) 292 326 if ( $bbp->reply_id == get_post_field( 'post_type', $forum_id ) ) { 293 $ topic_id = bbp_get_reply_topic_id( $forum_id );294 $forum_id = bbp_get_ topic_forum_id( $topic_id );327 $reply_id = $forum_id; 328 $forum_id = bbp_get_reply_forum_id( $forum_id ); 295 329 } 296 330 297 // There should always be at least 1 voice 298 $replies = count( $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status = 'publish' AND post_type = '" . $bbp->reply_id . "';", $forum_id ) ) ); 331 // If it's a topic, then get the parent (forum id) 332 if ( $bbp->topic_id == get_post_field( 'post_type', $forum_id ) ) 333 $forum_id = bbp_get_topic_forum_id( $forum_id ); 334 335 $replies = $children_reply_count = 0; 336 $children = get_posts( array( 'post_parent' => $forum_id, 'post_type' => $bbp->forum_id, 'meta_key' => '_bbp_forum_visibility', 'meta_value' => 'public' ) ); 337 338 // Loop through children and add together forum reply counts 339 foreach ( (array) $children as $child ) 340 $children_reply_count += (int) bbp_get_forum_reply_count( $child->ID ); 341 342 // Don't count replies if the forum is a category 343 if ( !bbp_is_forum_category( $forum_id ) ) { 344 if ( empty( $reply_id ) || !$replies = (int) get_post_meta( $forum_id, '_bbp_forum_reply_count', true ) ) { 345 $topics = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status = 'publish' AND post_type = '" . $bbp->topic_id . "';", $forum_id ) ); 346 $replies = (int) !empty( $topics ) ? $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent IN ( " . join( ',', $topics ) . " ) AND post_status = 'publish' AND post_type = '" . $bbp->reply_id . "';" ) : 0; 347 } else { 348 if ( 'publish' == bbp_get_reply_status( $reply_id ) ) { 349 $replies++; 350 } else { 351 $replies--; 352 } 353 } 354 } 355 356 // Calculate total replies in this forum 357 $total_replies = $replies + $children_reply_count; 299 358 300 359 // Update the count 301 update_post_meta( $forum_id, '_bbp_forum_reply_count', (int) $replies ); 302 303 return apply_filters( 'bbp_update_forum_reply_count', (int) $replies, $forum_id ); 360 update_post_meta( $forum_id, '_bbp_forum_reply_count', $replies ); 361 update_post_meta( $forum_id, '_bbp_forum_total_reply_count', $total_replies ); 362 363 // Walk up ancestors 364 if ( $parent = bbp_get_forum_parent( $forum_id ) ) 365 bbp_update_forum_reply_count( $parent ); 366 367 return apply_filters( 'bbp_update_forum_reply_count', empty( $total_count ) ? $replies : $total_replies, $forum_id, $total_count ); 304 368 } 305 369 -
branches/plugin/bbp-includes/bbp-forum-template.php
r2795 r2806 41 41 42 42 // Don't show private forums to normal users 43 if ( !current_user_can( 'read_private_forums' ) && empty( $r['meta_key'] ) && empty( $r['meta_value'] ) && empty( $r['meta_compare'] ) ) { 44 $r['meta_key'] = '_bbp_forum_visibility'; 45 $r['meta_value'] = 'public'; 46 $r['meta_compare'] = '=='; 43 if ( !current_user_can( 'read_private_forums' ) && empty( $r['meta_key'] ) && empty( $r['meta_value'] ) ) { 44 $r['meta_key'] = '_bbp_forum_visibility'; 45 $r['meta_value'] = 'public'; 47 46 } 48 47 … … 435 434 436 435 // Don't show private forums to normal users 437 if ( !current_user_can( 'read_private_forums' ) && empty( $r['meta_key'] ) && empty( $r['meta_value'] ) && empty( $r['meta_compare'] ) ) { 438 $r['meta_key'] = '_bbp_forum_visibility'; 439 $r['meta_value'] = 'public'; 440 $r['meta_compare'] = '=='; 436 if ( !current_user_can( 'read_private_forums' ) && empty( $r['meta_key'] ) && empty( $r['meta_value'] ) ) { 437 $r['meta_key'] = '_bbp_forum_visibility'; 438 $r['meta_value'] = 'public'; 441 439 } 442 440 … … 505 503 $topic_count = ' (' . bbp_get_forum_topic_count( $sub_forum->ID ) . ')'; 506 504 507 //if ( !empty( $show_reply_count ) && !bbp_is_forum_category( $sub_forum->ID ) )508 //$reply_count = ' (' . bbp_get_forum_reply_count( $sub_forum->ID ) . ')';505 if ( !empty( $show_reply_count ) && !bbp_is_forum_category( $sub_forum->ID ) ) 506 $reply_count = ' (' . bbp_get_forum_reply_count( $sub_forum->ID ) . ')'; 509 507 510 508 $output .= $link_before . '<a href="' . $permalink . '" class="bbp-forum-link">' . $title . $topic_count . $reply_count . '</a>' . $show_sep . $link_after; … … 904 902 * 905 903 * @param int $forum_id Optional. Forum id 904 * @param bool $total_count Optional. To get the total count or normal count? 906 905 * @uses bbp_get_forum_topic_count() To get the forum topic count 907 906 */ 908 function bbp_forum_topic_count( $forum_id = 0 ) {907 function bbp_forum_topic_count( $forum_id = 0, $total_count = true ) { 909 908 echo bbp_get_forum_topic_count( $forum_id ); 910 909 } … … 915 914 * 916 915 * @param int $forum_id Optional. Forum id 916 * @param bool $total_count Optional. To get the total count or normal 917 * count? 917 918 * @uses bbp_get_forum_id() To get the forum id 918 919 * @uses get_post_meta() To get the forum topic count … … 923 924 * @return int Forum topic count 924 925 */ 925 function bbp_get_forum_topic_count( $forum_id = 0 ) {926 $forum_id = bbp_get_forum_id( $forum_id ); 927 $topics = get_post_meta( $forum_id, '_bbp_forum_topic_count', true );926 function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true ) { 927 $forum_id = bbp_get_forum_id( $forum_id ); 928 $topics = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_forum_topic_count' : '_bbp_forum_total_topic_count', true ); 928 929 929 930 if ( '' === $topics ) 930 $topics = bbp_update_forum_topic_count( $forum_id );931 $topics = bbp_update_forum_topic_count( $forum_id, $total_count ); 931 932 932 933 return apply_filters( 'bbp_get_forum_topic_count', (int) $topics, $forum_id ); … … 939 940 * 940 941 * @param int $forum_id Optional. Forum id 942 * @param bool $total_count Optional. To get the total count or normal count? 941 943 * @uses bbp_get_forum_reply_count() To get the forum reply count 942 944 */ 943 function bbp_forum_reply_count( $forum_id = 0 ) {944 echo bbp_get_forum_reply_count( $forum_id );945 function bbp_forum_reply_count( $forum_id = 0, $total_count = true ) { 946 echo bbp_get_forum_reply_count( $forum_id, $total_count ); 945 947 } 946 948 /** … … 950 952 * 951 953 * @param int $forum_id Optional. Forum id 954 * @param bool $total_count Optional. To get the total count or normal 955 * count? 952 956 * @uses bbp_get_forum_id() To get the forum id 953 957 * @uses get_post_meta() To get the forum reply count … … 958 962 * @return int Forum reply count 959 963 */ 960 function bbp_get_forum_reply_count( $forum_id = 0 ) {961 $forum_id = bbp_get_forum_id( $forum_id ); 962 $replies = get_post_meta( $forum_id, '_bbp_forum_reply_count', true );964 function bbp_get_forum_reply_count( $forum_id = 0, $total_count = true ) { 965 $forum_id = bbp_get_forum_id( $forum_id ); 966 $replies = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_forum_reply_count' : '_bbp_forum_total_reply_count', true ); 963 967 964 968 if ( '' === $replies ) 965 $replies = bbp_update_forum_reply_count( $forum_id );969 $replies = bbp_update_forum_reply_count( $forum_id, $total_count ); 966 970 967 971 return apply_filters( 'bbp_get_forum_reply_count', (int) $replies, $forum_id ); -
branches/plugin/bbp-includes/bbp-hooks.php
r2789 r2806 153 153 add_action( 'deleted_post', 'bbp_update_forum_reply_count' ); 154 154 add_action( 'bbp_new_reply', 'bbp_update_forum_reply_count' ); 155 add_action( 'bbp_edit_ relpy', 'bbp_update_forum_reply_count' );155 add_action( 'bbp_edit_topic', 'bbp_update_forum_reply_count' ); 156 156 add_action( 'bbp_move_topic', 'bbp_update_forum_reply_count' ); 157 157 add_action( 'bbp_spammed_reply', 'bbp_update_forum_reply_count' ); -
branches/plugin/bbp-includes/bbp-reply-template.php
r2796 r2806 494 494 $since = bbp_get_time_since( bbp_convert_date( $revision->post_modified ) ); 495 495 496 $r .= "\t" . '<li id="bbp-reply-revision-log-' . $reply_id . '-item " class="bbp-reply-revision-log-item">' . "\n";496 $r .= "\t" . '<li id="bbp-reply-revision-log-' . $reply_id . '-item-' . $revision->ID . '" class="bbp-reply-revision-log-item">' . "\n"; 497 497 $r .= "\t\t" . sprintf( __( empty( $reason ) ? 'This reply was modified %1$s ago by %2$s.' : 'This reply was modified %1$s ago by %2$s. Reason: %3$s', 'bbpress' ), $since, $author, $reason ) . "\n"; 498 498 $r .= "\t" . '</li>' . "\n"; … … 871 871 872 872 if ( empty( $link_text ) ) { 873 if ( bbp_is_topic() || bbp_is_reply() ) 873 if ( bbp_is_topic() || bbp_is_reply() ) { 874 874 $link_text = bbp_get_reply_author_avatar( $reply_id, 80 ); 875 else875 } else { 876 876 $link_text = bbp_get_reply_author( $reply_id ); 877 } 877 878 } 878 879 -
branches/plugin/bbp-includes/bbp-topic-functions.php
r2803 r2806 590 590 // Forum Topic Counts 591 591 bbp_update_forum_topic_count( $source_topic_forum_id ); 592 bbp_update_forum_topic_count( $destination_topic_id );592 // bbp_update_forum_topic_count( $destination_topic_id ); 593 593 594 594 // Forum Reply Counts 595 595 bbp_update_forum_reply_count( $source_topic_forum_id ); 596 bbp_update_forum_reply_count( $destination_topic_id );596 // bbp_update_forum_reply_count( $destination_topic_id ); 597 597 598 598 // Forum Voice Counts … … 808 808 809 809 // Forum Topic Counts 810 bbp_update_forum_topic_count( $source_topic_id );810 // bbp_update_forum_topic_count( $source_topic_id ); 811 811 bbp_update_forum_topic_count( $destination_topic_id ); 812 812 813 813 // Forum Reply Counts 814 bbp_update_forum_reply_count( $source_topic_id );814 // bbp_update_forum_reply_count( $source_topic_id ); 815 815 bbp_update_forum_reply_count( $destination_topic_id ); 816 816 -
branches/plugin/bbp-includes/bbp-topic-template.php
r2796 r2806 530 530 $since = bbp_get_time_since( bbp_convert_date( $revision->post_modified ) ); 531 531 532 $r .= "\t" . '<li id="bbp-topic-revision-log-' . $topic_id . '-item " class="bbp-topic-revision-log-item">' . "\n";532 $r .= "\t" . '<li id="bbp-topic-revision-log-' . $topic_id . '-item-' . $revision->ID . '" class="bbp-topic-revision-log-item">' . "\n"; 533 533 $r .= "\t\t" . sprintf( __( empty( $reason ) ? 'This topic was modified %1$s ago by %2$s.' : 'This topic was modified %1$s ago by %2$s. Reason: %3$s', 'bbpress' ), $since, $author, $reason ) . "\n"; 534 534 $r .= "\t" . '</li>' . "\n";
Note: See TracChangeset
for help on using the changeset viewer.