Changeset 5827 for trunk/src/includes/topics/functions.php
- Timestamp:
- 07/14/2015 12:31:42 AM (11 years ago)
- File:
-
- 1 edited
-
trunk/src/includes/topics/functions.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/topics/functions.php
r5778 r5827 1472 1472 } 1473 1473 1474 global $wpdb;1475 1476 1474 // Prevent debug notices 1477 1475 $from_reply_id = $destination_topic_id = 0; … … 1678 1676 // get_posts() is not used because it doesn't allow us to use '>=' 1679 1677 // comparision without a filter. 1680 $replies = (array) $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE {$wpdb->posts}.post_date >= %s AND {$wpdb->posts}.post_parent = %d AND {$wpdb->posts}.post_type = %s ORDER BY {$wpdb->posts}.post_date ASC", $from_reply->post_date, $source_topic->ID, bbp_get_reply_post_type() ) ); 1678 $bbp_db = bbp_db(); 1679 $query = $bbp_db->prepare( "SELECT * FROM {$bbp_db->posts} WHERE {$bbp_db->posts}.post_date >= %s AND {$bbp_db->posts}.post_parent = %d AND {$bbp_db->posts}.post_type = %s ORDER BY {$bbp_db->posts}.post_date ASC", $from_reply->post_date, $source_topic->ID, bbp_get_reply_post_type() ); 1680 $replies = (array) $bbp_db->get_results( $query ); 1681 1681 1682 1682 // Make sure there are replies to loop through … … 2509 2509 */ 2510 2510 function bbp_update_topic_reply_count_hidden( $topic_id = 0, $reply_count = 0 ) { 2511 global $wpdb;2512 2511 2513 2512 // If it's a reply, then get the parent (topic id) … … 2520 2519 // Get replies of topic 2521 2520 if ( empty( $reply_count ) ) { 2521 $bbp_db = bbp_db(); 2522 2522 $post_status = "'" . implode( "','", array( bbp_get_trash_status_id(), bbp_get_spam_status_id(), bbp_get_pending_status_id() ) ) . "'"; 2523 $reply_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $topic_id, bbp_get_reply_post_type() ) ); 2523 $query = $bbp_db->prepare( "SELECT COUNT(ID) FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $topic_id, bbp_get_reply_post_type() ); 2524 $reply_count = $bbp_db->get_var( $query ); 2524 2525 } 2525 2526 … … 2673 2674 * @uses bbp_get_topic_post_type() To get the topic post type 2674 2675 * @uses wpdb::prepare() To prepare our sql query 2675 * @uses wpdb::get_ col() To execute our query and get the column back2676 * @uses wpdb::get_var() To execute our query and get the column back 2676 2677 * @uses update_post_meta() To update the topic voice count meta 2677 2678 * @uses apply_filters() Calls 'bbp_update_topic_voice_count' with the voice … … 2680 2681 */ 2681 2682 function bbp_update_topic_voice_count( $topic_id = 0 ) { 2682 global $wpdb;2683 2683 2684 2684 // If it's a reply, then get the parent (topic id) … … 2692 2692 2693 2693 // Query the DB to get voices in this topic 2694 $voices = (int) $wpdb->get_var( $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() ) ); 2694 $bbp_db = bbp_db(); 2695 $query = $bbp_db->prepare( "SELECT COUNT( DISTINCT post_author ) FROM {$bbp_db->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() ); 2696 $voices = (int) $bbp_db->get_var( $query ); 2695 2697 2696 2698 // Update the voice count for this topic id … … 2713 2715 * @uses bbp_get_topic_post_type() To get the topic post type 2714 2716 * @uses wpdb::prepare() To prepare our sql query 2715 * @uses wpdb::get_ col() To execute our query and get the column back2717 * @uses wpdb::get_var() To execute our query and get the column back 2716 2718 * @uses update_post_meta() To update the topic anonymous reply count meta 2717 2719 * @uses apply_filters() Calls 'bbp_update_topic_anonymous_reply_count' with the … … 2720 2722 */ 2721 2723 function bbp_update_topic_anonymous_reply_count( $topic_id = 0 ) { 2722 global $wpdb;2723 2724 2724 2725 // If it's a reply, then get the parent (topic id) … … 2731 2732 } 2732 2733 2733 $anonymous_replies = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( ID ) FROM {$wpdb->posts} WHERE ( post_parent = %d AND post_status = '%s' AND post_type = '%s' AND post_author = 0 ) OR ( ID = %d AND post_type = '%s' AND post_author = 0 );", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ) ); 2734 2735 update_post_meta( $topic_id, '_bbp_anonymous_reply_count', $anonymous_replies ); 2736 2737 return (int) apply_filters( 'bbp_update_topic_anonymous_reply_count', $anonymous_replies, $topic_id ); 2734 // Query the DB to get anonymous replies in this topic 2735 $bbp_db = bbp_db(); 2736 $query = $bbp_db->prepare( "SELECT COUNT( ID ) FROM {$bbp_db->posts} WHERE ( post_parent = %d AND post_status = '%s' AND post_type = '%s' AND post_author = 0 ) OR ( ID = %d AND post_type = '%s' AND post_author = 0 );", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ); 2737 $replies = (int) $bbp_db->get_var( $query ); 2738 2739 update_post_meta( $topic_id, '_bbp_anonymous_reply_count', $replies ); 2740 2741 return (int) apply_filters( 'bbp_update_topic_anonymous_reply_count', $replies, $topic_id ); 2738 2742 } 2739 2743
Note: See TracChangeset
for help on using the changeset viewer.