Changeset 3505 for branches/plugin/bbp-includes/bbp-common-functions.php
- Timestamp:
- 09/10/2011 10:27:19 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-includes/bbp-common-functions.php
r3499 r3505 440 440 */ 441 441 function bbp_get_statistics( $args = '' ) { 442 global $bbp;443 442 444 443 $defaults = array ( … … 470 469 } 471 470 471 // Post statuses 472 $private = bbp_get_private_status_id(); 473 $spam = bbp_get_spam_status_id(); 474 $trash = bbp_get_trash_status_id(); 475 $closed = bbp_get_closed_status_id(); 476 472 477 // Topics 473 478 if ( !empty( $count_topics ) ) { … … 476 481 477 482 // Published (publish + closed) 478 $topic_count = $all_topics->publish + $all_topics->{$ bbp->closed_status_id};483 $topic_count = $all_topics->publish + $all_topics->{$closed}; 479 484 480 485 if ( current_user_can( 'read_private_topics' ) || current_user_can( 'edit_others_topics' ) || current_user_can( 'view_trash' ) ) { 481 486 482 487 // Private 483 $topics['private'] = ( !empty( $count_private_topics ) && current_user_can( 'read_private_topics' ) ) ? (int) $all_topics-> private: 0;488 $topics['private'] = ( !empty( $count_private_topics ) && current_user_can( 'read_private_topics' ) ) ? (int) $all_topics->{$private} : 0; 484 489 485 490 // Spam 486 $topics['spammed'] = ( !empty( $count_spammed_topics ) && current_user_can( 'edit_others_topics' ) ) ? (int) $all_topics->{$ bbp->spam_status_id}: 0;491 $topics['spammed'] = ( !empty( $count_spammed_topics ) && current_user_can( 'edit_others_topics' ) ) ? (int) $all_topics->{$spam} : 0; 487 492 488 493 // Trash 489 $topics['trashed'] = ( !empty( $count_trashed_topics ) && current_user_can( 'view_trash' ) ) ? (int) $all_topics->{$ bbp->trash_status_id}: 0;494 $topics['trashed'] = ( !empty( $count_trashed_topics ) && current_user_can( 'view_trash' ) ) ? (int) $all_topics->{$trash} : 0; 490 495 491 496 // Total hidden (private + spam + trash) … … 513 518 514 519 // Private 515 $replies['private'] = ( !empty( $count_private_replies ) && current_user_can( 'read_private_replies' ) ) ? (int) $all_replies-> private: 0;520 $replies['private'] = ( !empty( $count_private_replies ) && current_user_can( 'read_private_replies' ) ) ? (int) $all_replies->{$private} : 0; 516 521 517 522 // Spam 518 $replies['spammed'] = ( !empty( $count_spammed_replies ) && current_user_can( 'edit_others_replies' ) ) ? (int) $all_replies->{$ bbp->spam_status_id}: 0;523 $replies['spammed'] = ( !empty( $count_spammed_replies ) && current_user_can( 'edit_others_replies' ) ) ? (int) $all_replies->{$spam} : 0; 519 524 520 525 // Trash 521 $replies['trashed'] = ( !empty( $count_trashed_replies ) && current_user_can( 'view_trash' ) ) ? (int) $all_replies->{$ bbp->trash_status_id}: 0;526 $replies['trashed'] = ( !empty( $count_trashed_replies ) && current_user_can( 'view_trash' ) ) ? (int) $all_replies->{$trash} : 0; 522 527 523 528 // Total hidden (private + spam + trash) … … 714 719 */ 715 720 function bbp_filter_anonymous_post_data( $args = '', $is_edit = false ) { 716 global $bbp;717 721 718 722 // Assign variables … … 769 773 return true; 770 774 771 global $ bbp, $wpdb;775 global $wpdb; 772 776 773 777 extract( $post_data, EXTR_SKIP ); … … 792 796 // Simple duplicate check 793 797 // Expected slashed ($post_type, $post_parent, $post_author, $post_content, $anonymous_data) 794 $dupe = "SELECT ID FROM {$wpdb->posts} {$join} WHERE post_type = '{$post_type}' AND post_status != '{$bbp->trash_status_id}' AND post_author = {$post_author} AND post_content = '{$post_content}' {$where}"; 795 $dupe .= !empty( $post_parent ) ? " AND post_parent = '{$post_parent}'" : ''; 796 $dupe .= " LIMIT 1"; 797 $dupe = apply_filters( 'bbp_check_for_duplicate_query', $dupe, $post_data ); 798 $status = bbp_get_trash_status_id(); 799 $dupe = "SELECT ID FROM {$wpdb->posts} {$join} WHERE post_type = '{$post_type}' AND post_status != '{$status}' AND post_author = {$post_author} AND post_content = '{$post_content}' {$where}"; 800 $dupe .= !empty( $post_parent ) ? " AND post_parent = '{$post_parent}'" : ''; 801 $dupe .= " LIMIT 1"; 802 $dupe = apply_filters( 'bbp_check_for_duplicate_query', $dupe, $post_data ); 798 803 799 804 if ( $wpdb->get_var( $dupe ) ) { … … 855 860 * @since bbPress (r3446) 856 861 * 857 * @global bbPress $bbp858 862 * @param array $anonymous_data Anonymous user data 859 863 * @param int $author_id Topic or reply author ID … … 980 984 */ 981 985 function bbp_notify_subscribers( $reply_id = 0 ) { 982 global $ bbp, $wpdb;986 global $wpdb; 983 987 984 988 // Bail if subscriptions are turned off … … 1158 1162 // The ID of the cached query 1159 1163 $cache_id = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_last_id'; 1160 $post_status = array( 'publish');1164 $post_status = array( bbp_get_public_status_id() ); 1161 1165 1162 1166 // Add closed status if topic post type 1163 1167 if ( $post_type == bbp_get_topic_post_type() ) 1164 $post_status[] = $bbp->closed_status_id;1168 $post_status[] = bbp_get_closed_status_id(); 1165 1169 1166 1170 // Join post statuses together … … 1192 1196 */ 1193 1197 function bbp_get_public_child_count( $parent_id = 0, $post_type = 'post' ) { 1194 global $wpdb , $bbp;1198 global $wpdb; 1195 1199 1196 1200 // Bail if nothing passed … … 1200 1204 // The ID of the cached query 1201 1205 $cache_id = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_count'; 1202 $post_status = array( 'publish');1206 $post_status = array( bbp_get_public_status_id() ); 1203 1207 1204 1208 // Add closed status if topic post type 1205 1209 if ( $post_type == bbp_get_topic_post_type() ) 1206 $post_status[] = $bbp->closed_status_id;1210 $post_status[] = bbp_get_closed_status_id(); 1207 1211 1208 1212 // Join post statuses together … … 1234 1238 */ 1235 1239 function bbp_get_public_child_ids( $parent_id = 0, $post_type = 'post' ) { 1236 global $wpdb , $bbp;1240 global $wpdb; 1237 1241 1238 1242 // Bail if nothing passed … … 1242 1246 // The ID of the cached query 1243 1247 $cache_id = 'bbp_parent_public_' . $parent_id . '_type_' . $post_type . '_child_ids'; 1244 $post_status = array( 'publish');1248 $post_status = array( bbp_get_public_status_id() ); 1245 1249 1246 1250 // Add closed status if topic post type 1247 1251 if ( $post_type == bbp_get_topic_post_type() ) 1248 $post_status[] = $bbp->closed_status_id;1252 $post_status[] = bbp_get_closed_status_id(); 1249 1253 1250 1254 // Join post statuses together … … 1275 1279 */ 1276 1280 function bbp_get_all_child_ids( $parent_id = 0, $post_type = 'post' ) { 1277 global $wpdb , $bbp;1281 global $wpdb; 1278 1282 1279 1283 // Bail if nothing passed … … 1283 1287 // The ID of the cached query 1284 1288 $cache_id = 'bbp_parent_all_' . $parent_id . '_type_' . $post_type . '_child_ids'; 1285 $post_status = array( 'publish');1289 $post_status = array( bbp_get_public_status_id() ); 1286 1290 1287 1291 // Extra post statuses based on post type … … 1290 1294 // Forum 1291 1295 case bbp_get_forum_post_type() : 1292 $post_status[] = 'private';1293 $post_status[] = $bbp->hidden_status_id;1296 $post_status[] = bbp_get_private_status_id(); 1297 $post_status[] = bbp_get_hidden_status_id(); 1294 1298 break; 1295 1299 1296 1300 // Topic 1297 1301 case bbp_get_topic_post_type() : 1298 $post_status[] = $bbp->closed_status_id;1299 $post_status[] = $bbp->trash_status_id;1300 $post_status[] = $bbp->spam_status_id;1302 $post_status[] = bbp_get_closed_status_id(); 1303 $post_status[] = bbp_get_trash_status_id(); 1304 $post_status[] = bbp_get_spam_status_id(); 1301 1305 break; 1302 1306 1303 1307 // Reply 1304 1308 case bbp_get_reply_post_type() : 1305 $post_status[] = $bbp->trash_status_id;1306 $post_status[] = $bbp->spam_status_id;1309 $post_status[] = bbp_get_trash_status_id(); 1310 $post_status[] = bbp_get_spam_status_id(); 1307 1311 break; 1308 1312 } … … 1331 1335 * 1332 1336 * @global WP_Query $wp_query 1333 * @global bbPress $bbp1334 1337 * @param array $query_vars 1335 1338 * @return array 1336 1339 */ 1337 1340 function bbp_request_feed_trap( $query_vars ) { 1338 global $wp_query , $bbp;1341 global $wp_query; 1339 1342 1340 1343 // Looking at a feed … … 1349 1352 // Forum 1350 1353 case bbp_get_forum_post_type() : 1354 1355 // Declare local variable(s) 1356 $meta_query = array(); 1351 1357 1352 1358 // Single forum … … 1368 1374 'value' => $forum_id, 1369 1375 'compare' => '=' 1370 ) ); 1371 1372 // No restrictions on forum ID 1373 } else { 1374 $meta_query = array(); 1376 ) ); 1375 1377 } 1376 1378 … … 1383 1385 'post_type' => bbp_get_reply_post_type(), 1384 1386 'post_parent' => 'any', 1385 'post_status' => join( ',', array( 'publish', $bbp->closed_status_id) ),1387 'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ), 1386 1388 'posts_per_page' => get_option( '_bbp_replies_per_rss_page', 25 ), 1387 1389 'order' => 'DESC', … … 1400 1402 'post_type' => bbp_get_topic_post_type(), 1401 1403 'post_parent' => 'any', 1402 'post_status' => join( ',', array( 'publish', $bbp->closed_status_id) ),1404 'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ), 1403 1405 'posts_per_page' => get_option( '_bbp_topics_per_rss_page', 25 ), 1404 1406 'order' => 'DESC', … … 1417 1419 'post_type' => array( bbp_get_reply_post_type(), bbp_get_topic_post_type() ), 1418 1420 'post_parent' => 'any', 1419 'post_status' => join( ',', array( 'publish', $bbp->closed_status_id) ),1421 'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ), 1420 1422 'posts_per_page' => get_option( '_bbp_replies_per_rss_page', 25 ), 1421 1423 'order' => 'DESC', … … 1534 1536 } 1535 1537 1538 /** Post Statuses *************************************************************/ 1539 1540 /** 1541 * Return the public post status ID 1542 * 1543 * @since bbPress (r3504) 1544 * 1545 * @global bbPress $bbp 1546 * @return string 1547 */ 1548 function bbp_get_public_status_id() { 1549 global $bbp; 1550 return $bbp->public_status_id; 1551 } 1552 1553 /** 1554 * Return the private post status ID 1555 * 1556 * @since bbPress (r3504) 1557 * 1558 * @global bbPress $bbp 1559 * @return string 1560 */ 1561 function bbp_get_private_status_id() { 1562 global $bbp; 1563 return $bbp->private_status_id; 1564 } 1565 1566 /** 1567 * Return the hidden post status ID 1568 * 1569 * @since bbPress (r3504) 1570 * 1571 * @global bbPress $bbp 1572 * @return string 1573 */ 1574 function bbp_get_hidden_status_id() { 1575 global $bbp; 1576 return $bbp->hidden_status_id; 1577 } 1578 1579 /** 1580 * Return the closed post status ID 1581 * 1582 * @since bbPress (r3504) 1583 * 1584 * @global bbPress $bbp 1585 * @return string 1586 */ 1587 function bbp_get_closed_status_id() { 1588 global $bbp; 1589 return $bbp->closed_status_id; 1590 } 1591 1592 /** 1593 * Return the spam post status ID 1594 * 1595 * @since bbPress (r3504) 1596 * 1597 * @global bbPress $bbp 1598 * @return string 1599 */ 1600 function bbp_get_spam_status_id() { 1601 global $bbp; 1602 return $bbp->spam_status_id; 1603 } 1604 1605 /** 1606 * Return the trash post status ID 1607 * 1608 * @since bbPress (r3504) 1609 * 1610 * @global bbPress $bbp 1611 * @return string 1612 */ 1613 function bbp_get_trash_status_id() { 1614 global $bbp; 1615 return $bbp->trash_status_id; 1616 } 1617 1618 /** 1619 * Return the orphan post status ID 1620 * 1621 * @since bbPress (r3504) 1622 * 1623 * @global bbPress $bbp 1624 * @return string 1625 */ 1626 function bbp_get_orphan_status_id() { 1627 global $bbp; 1628 return $bbp->orphan_status_id; 1629 } 1630 1536 1631 ?>
Note: See TracChangeset
for help on using the changeset viewer.