Changeset 2790
- Timestamp:
- 01/10/2011 04:23:18 AM (14 years ago)
- Location:
- branches/plugin
- Files:
-
- 5 added
- 2 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-includes/bbp-forum-template.php
r2788 r2790 996 996 997 997 /** 998 * Closes a forum999 *1000 * @since bbPress (r2746)1001 *1002 * @param int $forum_id forum id1003 * @uses wp_get_single_post() To get the forum1004 * @uses do_action() Calls 'bbp_close_forum' with the forum id1005 * @uses add_post_meta() To add the previous status to a meta1006 * @uses wp_insert_post() To update the forum with the new status1007 * @uses do_action() Calls 'bbp_opened_forum' with the forum id1008 * @return mixed False or {@link WP_Error} on failure, forum id on success1009 */1010 function bbp_close_forum( $forum_id = 0 ) {1011 global $bbp;1012 1013 if ( !$forum = wp_get_single_post( $forum_id, ARRAY_A ) )1014 return $forum;1015 1016 do_action( 'bbp_close_forum', $forum_id );1017 1018 update_post_meta( $forum_id, '_bbp_forum_status', 'closed' );1019 1020 do_action( 'bbp_closed_forum', $forum_id );1021 1022 return $forum_id;1023 }1024 1025 /**1026 * Opens a forum1027 *1028 * @since bbPress (r2746)1029 *1030 * @param int $forum_id forum id1031 * @uses wp_get_single_post() To get the forum1032 * @uses do_action() Calls 'bbp_open_forum' with the forum id1033 * @uses get_post_meta() To get the previous status1034 * @uses delete_post_meta() To delete the previous status meta1035 * @uses wp_insert_post() To update the forum with the new status1036 * @uses do_action() Calls 'bbp_opened_forum' with the forum id1037 * @return mixed False or {@link WP_Error} on failure, forum id on success1038 */1039 function bbp_open_forum( $forum_id = 0 ) {1040 global $bbp;1041 1042 if ( !$forum = wp_get_single_post( $forum_id, ARRAY_A ) )1043 return $forum;1044 1045 do_action( 'bbp_open_forum', $forum_id );1046 1047 update_post_meta( $forum_id, '_bbp_forum_status', 'open' );1048 1049 do_action( 'bbp_opened_forum', $forum_id );1050 1051 return $forum_id;1052 }1053 1054 /**1055 * Make the forum a category1056 *1057 * @since bbPress (r2746)1058 *1059 * @param int $forum_id Optional. Forum id1060 * @uses update_post_meta() To update the forum category meta1061 * @return bool False on failure, true on success1062 */1063 function bbp_categorize_forum( $forum_id = 0 ) {1064 return update_post_meta( $forum_id, '_bbp_forum_type', 'category' );1065 }1066 1067 /**1068 * Remove the category status from a forum1069 *1070 * @since bbPress (r2746)1071 *1072 * @param int $forum_id Optional. Forum id1073 * @uses delete_post_meta() To delete the forum category meta1074 * @return bool False on failure, true on success1075 */1076 function bbp_normalize_forum( $forum_id = 0 ) {1077 return update_post_meta( $forum_id, '_bbp_forum_type', 'forum' );1078 }1079 1080 /**1081 * Mark the forum as private1082 *1083 * @since bbPress (r2746)1084 *1085 * @param int $forum_id Optional. Forum id1086 * @uses update_post_meta() To update the forum private meta1087 * @return bool False on failure, true on success1088 */1089 function bbp_privatize_forum( $forum_id = 0 ) {1090 return update_post_meta( $forum_id, '_bbp_forum_visibility', 'private' );1091 }1092 1093 /**1094 * Unmark the forum as private1095 *1096 * @since bbPress (r2746)1097 *1098 * @param int $forum_id Optional. Forum id1099 * @uses delete_post_meta() To delete the forum private meta1100 * @return bool False on failure, true on success1101 */1102 function bbp_publicize_forum( $forum_id = 0 ) {1103 return update_post_meta( $forum_id, '_bbp_forum_visibility', 'public' );1104 }1105 1106 /**1107 998 * Is the forum a category? 1108 999 * … … 1239 1130 } 1240 1131 1241 /** Forum Updaters ************************************************************/1242 1243 /**1244 * Update the forum last topic id1245 *1246 * @since bbPress (r2625)1247 *1248 * @param int $forum_id Optional. Forum id1249 * @param int $topic_id Optional. Topic id1250 * @uses bbp_get_forum_id() To get the forum id1251 * @uses bbp_get_topic_id() To get the topic id1252 * @uses update_post_meta() To update the forum's last topic id meta1253 * @return bool True on success, false on failure1254 */1255 function bbp_update_forum_last_topic_id( $forum_id = 0, $topic_id = 0 ) {1256 $forum_id = bbp_get_forum_id( $forum_id );1257 $topic_id = bbp_get_topic_id( $topic_id );1258 1259 // Update the last topic ID1260 if ( !empty( $topic_id ) )1261 return update_post_meta( $forum_id, '_bbp_forum_last_topic_id', $topic_id );1262 1263 return false;1264 }1265 1266 /**1267 * Update the forum last reply id1268 *1269 * @since bbPress (r2625)1270 *1271 * @param int $forum_id Optional. Forum id1272 * @param int $reply_id Optional. Reply id1273 * @uses bbp_get_forum_id() To get the forum id1274 * @uses bbp_get_reply_id() To get the reply id1275 * @uses update_post_meta() To update the forum's last reply id meta1276 * @return bool True on success, false on failure1277 */1278 function bbp_update_forum_last_reply_id( $forum_id = 0, $reply_id = 0 ) {1279 $forum_id = bbp_get_forum_id( $forum_id );1280 $reply_id = bbp_get_reply_id( $reply_id );1281 1282 // Update the last reply ID1283 if ( !empty( $reply_id ) )1284 return update_post_meta( $forum_id, '_bbp_forum_last_reply_id', $reply_id );1285 1286 return false;1287 }1288 1289 /**1290 * Update the forums last active date/time (aka freshness)1291 *1292 * @since bbPress (r2680)1293 *1294 * @param int $forum_id Optional. Forum id1295 * @param string $new_time Optional. New time in mysql format1296 * @uses bbp_get_forum_id() To get the forum id1297 * @uses current_time() To get the current time1298 * @uses update_post_meta() To update the forum's last active meta1299 * @return bool True on success, false on failure1300 */1301 function bbp_update_forum_last_active( $forum_id = 0, $new_time = '' ) {1302 $forum_id = bbp_get_forum_id( $forum_id );1303 1304 // Check time and use current if empty1305 if ( empty( $new_time ) )1306 $new_time = current_time( 'mysql' );1307 1308 // Update last active1309 if ( !empty( $forum_id ) )1310 return update_post_meta( $forum_id, '_bbp_forum_last_active', $new_time );1311 1312 return false;1313 }1314 1315 /**1316 * Update the forum sub-forum count1317 *1318 * @todo Make this work.1319 *1320 * @since bbPress (r2625)1321 *1322 * @param int $forum_id Optional. Forum id1323 * @uses bbp_get_forum_id() To get the forum id1324 * @return bool True on success, false on failure1325 */1326 function bbp_update_forum_subforum_count( $forum_id = 0 ) {1327 $forum_id = bbp_get_forum_id( $forum_id );1328 1329 return false;1330 }1331 1332 /**1333 * Adjust the total topic count of a forum1334 *1335 * @since bbPress (r2464)1336 *1337 * @param int $forum_id Optional. Forum id or topic id. It is checked whether it1338 * is a topic or a forum. If it's a topic, its parent,1339 * i.e. the forum is automatically retrieved.1340 * @uses get_post_field() To check whether the supplied id is a topic1341 * @uses bbp_get_topic_forum_id() To get the topic's forum id1342 * @uses wpdb::prepare() To prepare the sql statement1343 * @uses wpdb::get_col() To execute the query and get the column back1344 * @uses update_post_meta() To update the forum's topic count meta1345 * @uses apply_filters() Calls 'bbp_update_forum_topic_count' with the topic1346 * count and forum id1347 * @return int Forum topic count1348 */1349 function bbp_update_forum_topic_count( $forum_id = 0 ) {1350 global $wpdb, $bbp;1351 1352 $forum_id = bbp_get_forum_id( $forum_id );1353 1354 // If it's a reply, then get the parent (topic id)1355 if ( $bbp->topic_id == get_post_field( 'post_type', $forum_id ) )1356 $forum_id = bbp_get_topic_forum_id( $forum_id );1357 1358 // Get topics count1359 $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 ) ) );1360 1361 // Update the count1362 update_post_meta( $forum_id, '_bbp_forum_topic_count', (int) $topics );1363 1364 return apply_filters( 'bbp_update_forum_topic_count', (int) $topics, $forum_id );1365 }1366 1367 /**1368 * Adjust the total reply count of a forum1369 *1370 * @todo Make this work1371 *1372 * @since bbPress (r2464)1373 *1374 * @param int $forum_id Optional. Forum id or reply id. It is checked whether it1375 * is a reply or a forum. If it's a reply, its forum is1376 * automatically retrieved.1377 * @uses get_post_field() To check whether the supplied id is a reply1378 * @uses bbp_get_reply_topic_id() To get the reply's topic id1379 * @uses bbp_get_topic_forum_id() To get the topic's forum id1380 * @uses wpdb::prepare() To prepare the sql statement1381 * @uses wpdb::get_col() To execute the query and get the column back1382 * @uses update_post_meta() To update the forum's reply count meta1383 * @uses apply_filters() Calls 'bbp_update_forum_reply_count' with the reply1384 * count and forum id1385 * @return int Forum reply count1386 */1387 function bbp_update_forum_reply_count( $forum_id = 0 ) {1388 global $wpdb, $bbp;1389 1390 $forum_id = bbp_get_forum_id( $forum_id );1391 1392 // If it's a reply, then get the parent (topic id)1393 if ( $bbp->reply_id == get_post_field( 'post_type', $forum_id ) ) {1394 $topic_id = bbp_get_reply_topic_id( $forum_id );1395 $forum_id = bbp_get_topic_forum_id( $topic_id );1396 }1397 1398 // There should always be at least 1 voice1399 $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 ) ) );1400 1401 // Update the count1402 update_post_meta( $forum_id, '_bbp_forum_reply_count', (int) $replies );1403 1404 return apply_filters( 'bbp_update_forum_reply_count', (int) $replies, $forum_id );1405 }1406 1407 /**1408 * Adjust the total voice count of a forum1409 *1410 * @since bbPress (r2567)1411 *1412 * @param int $forum_id Optional. Forum, topic or reply id. The forum is1413 * automatically retrieved based on the input.1414 * @uses get_post_field() To check whether the supplied id is a reply1415 * @uses bbp_get_reply_topic_id() To get the reply's topic id1416 * @uses bbp_get_topic_forum_id() To get the topic's forum id1417 * @uses wpdb::prepare() To prepare the sql statement1418 * @uses wpdb::get_col() To execute the query and get the column back1419 * @uses update_post_meta() To update the forum's voice count meta1420 * @uses apply_filters() Calls 'bbp_update_forum_voice_count' with the voice1421 * count and forum id1422 * @return int Forum voice count1423 */1424 function bbp_update_forum_voice_count( $forum_id = 0 ) {1425 global $wpdb, $bbp;1426 1427 $forum_id = bbp_get_forum_id( $forum_id );1428 1429 // If it's a reply, then get the parent (topic id)1430 if ( $bbp->reply_id == get_post_field( 'post_type', $forum_id ) )1431 $forum_id = bbp_get_reply_topic_id( $forum_id );1432 1433 // If it's a topic, then get the parent (forum id)1434 if ( $bbp->topic_id == get_post_field( 'post_type', $forum_id ) )1435 $forum_id = bbp_get_topic_forum_id( $forum_id );1436 1437 // There should always be at least 1 voice1438 if ( !$voices = count( $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE ( post_parent = %d AND post_status = 'publish' AND post_type = '" . $bbp->reply_id . "' ) OR ( ID = %d AND post_type = '" . $bbp->forum_id . "' );", $forum_id, $forum_id ) ) ) )1439 $voices = 1;1440 1441 // Update the count1442 update_post_meta( $forum_id, '_bbp_forum_voice_count', (int) $voices );1443 1444 return apply_filters( 'bbp_update_forum_voice_count', (int) $voices, $forum_id );1445 }1446 1447 /** END - Forum Loop Functions ************************************************/1448 1449 1132 ?> -
branches/plugin/bbp-includes/bbp-general-template.php
r2789 r2790 564 564 * @uses wp_referer_field() To generate a hidden referer field 565 565 */ 566 function bbp_edit_user_form_fields() { ?> 566 function bbp_edit_user_form_fields() { 567 ?> 567 568 568 569 <input type="hidden" name="action" id="bbp_post_action" value="bbp-update-user" /> … … 584 585 */ 585 586 function bbp_merge_topic_form_fields() { 586 587 ?> 587 ?> 588 588 589 589 <input type="hidden" name="action" id="bbp_post_action" value="bbp-merge-topic" /> … … 603 603 */ 604 604 function bbp_split_topic_form_fields() { 605 606 ?> 605 ?> 607 606 608 607 <input type="hidden" name="action" id="bbp_post_action" value="bbp-split-topic" /> -
branches/plugin/bbp-includes/bbp-options.php
r2789 r2790 17 17 * 18 18 * @uses add_option() Adds default options 19 * @uses do_action() Calls 'bbp_add_options' 19 20 */ 20 21 function bbp_add_options() { … … 82 83 } 83 84 85 /** Active? *******************************************************************/ 86 87 /** 88 * Checks if favorites feature is enabled. 89 * 90 * @since bbPress (r2658) 91 * 92 * @uses get_option() To get the favorites option 93 * @return bool Is favorites enabled or not 94 */ 95 function bbp_is_favorites_active() { 96 return (bool) get_option( '_bbp_enable_favorites', true ); 97 } 98 99 /** 100 * Checks if subscription feature is enabled. 101 * 102 * @since bbPress (r2658) 103 * 104 * @uses get_option() To get the subscriptions option 105 * @return bool Is subscription enabled or not 106 */ 107 function bbp_is_subscriptions_active() { 108 return (bool) get_option( '_bbp_enable_subscriptions' ); 109 } 110 111 /** 112 * Is the anonymous posting allowed? 113 * 114 * @since bbPress (r2659) 115 * 116 * @uses get_option() To get the allow anonymous option 117 * @return bool Is anonymous posting allowed? 118 */ 119 function bbp_allow_anonymous() { 120 return apply_filters( 'bbp_allow_anonymous', get_option( '_bbp_allow_anonymous', false ) ); 121 } 122 84 123 ?> -
branches/plugin/bbp-includes/bbp-reply-template.php
r2788 r2790 1509 1509 /** END Reply Loop Functions **************************************************/ 1510 1510 1511 /** Reply Actions *************************************************************/1512 1513 /**1514 * Marks a reply as spam1515 *1516 * @since bbPress (r2740)1517 *1518 * @param int $reply_id Reply id1519 * @uses wp_get_single_post() To get the reply1520 * @uses do_action() Calls 'bbp_spam_reply' with the reply id before marking1521 * the reply as spam1522 * @uses add_post_meta() To add the previous status to a meta1523 * @uses wp_insert_post() To insert the updated post1524 * @uses do_action() Calls 'bbp_spammed_reply' with the reply id after marking1525 * the reply as spam1526 * @return mixed False or {@link WP_Error} on failure, reply id on success1527 */1528 function bbp_spam_reply( $reply_id = 0 ) {1529 global $bbp;1530 1531 if ( !$reply = wp_get_single_post( $reply_id, ARRAY_A ) )1532 return $reply;1533 1534 if ( $reply['post_status'] == $bbp->spam_status_id )1535 return false;1536 1537 do_action( 'bbp_spam_reply', $reply_id );1538 1539 add_post_meta( $reply_id, '_bbp_spam_meta_status', $reply['post_status'] );1540 1541 $reply['post_status'] = $bbp->spam_status_id;1542 $reply_id = wp_insert_post( $reply );1543 1544 do_action( 'bbp_spammed_reply', $reply_id );1545 1546 return $reply_id;1547 }1548 1549 /**1550 * Unspams a reply1551 *1552 * @since bbPress (r2740)1553 *1554 * @param int $reply_id Reply id1555 * @uses wp_get_single_post() To get the reply1556 * @uses do_action() Calls 'bbp_unspam_reply' with the reply id before unmarking1557 * the reply as spam1558 * @uses get_post_meta() To get the previous status meta1559 * @uses delete_post_meta() To delete the previous status meta1560 * @uses wp_insert_post() To insert the updated post1561 * @uses do_action() Calls 'bbp_unspammed_reply' with the reply id after1562 * unmarking the reply as spam1563 * @return mixed False or {@link WP_Error} on failure, reply id on success1564 */1565 function bbp_unspam_reply( $reply_id = 0 ) {1566 global $bbp;1567 1568 if ( !$reply = wp_get_single_post( $reply_id, ARRAY_A ) )1569 return $reply;1570 1571 if ( $reply['post_status'] != $bbp->spam_status_id )1572 return false;1573 1574 do_action( 'bbp_unspam_reply', $reply_id );1575 1576 $reply_status = get_post_meta( $reply_id, '_bbp_spam_meta_status', true );1577 $reply['post_status'] = $reply_status;1578 1579 delete_post_meta( $reply_id, '_bbp_spam_meta_status' );1580 1581 $reply_id = wp_insert_post( $reply );1582 1583 do_action( 'bbp_unspammed_reply', $reply_id );1584 1585 return $reply_id;1586 }1587 1588 1511 ?> -
branches/plugin/bbp-includes/bbp-topic-template.php
r2789 r2790 2054 2054 } 2055 2055 2056 /** Topic Updaters ************************************************************/2057 2058 /**2059 * Adjust the total reply count of a topic2060 *2061 * @since bbPress (r2467)2062 *2063 * @param int $topic_id Optional. Topic id to update2064 * @uses bbp_get_topic_id() To get the topic id2065 * @uses get_post_field() To get the post type of the supplied id2066 * @uses bbp_get_reply_topic_id() To get the reply topic id2067 * @uses wpdb::prepare() To prepare our sql query2068 * @uses wpdb::get_col() To execute our query and get the column back2069 * @uses update_post_meta() To update the topic reply count meta2070 * @uses apply_filters() Calls 'bbp_update_topic_reply_count' with the reply2071 * count and topic id2072 * @return int Topic reply count2073 */2074 function bbp_update_topic_reply_count( $topic_id = 0 ) {2075 global $wpdb, $bbp;2076 2077 $topic_id = bbp_get_topic_id( $topic_id );2078 2079 // If it's a reply, then get the parent (topic id)2080 if ( $bbp->reply_id == get_post_field( 'post_type', $topic_id ) )2081 $topic_id = bbp_get_reply_topic_id( $topic_id );2082 2083 // Get replies of topic2084 $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 . "';", $topic_id ) ) );2085 2086 // Update the count2087 update_post_meta( $topic_id, '_bbp_topic_reply_count', (int) $replies );2088 2089 return apply_filters( 'bbp_update_topic_reply_count', (int) $replies, $topic_id );2090 }2091 2092 /**2093 * Adjust the total hidden reply count of a topic (hidden includes trashed and spammed replies)2094 *2095 * @since bbPress (r2740)2096 *2097 * @param int $topic_id Optional. Topic id to update2098 * @uses bbp_get_topic_id() To get the topic id2099 * @uses get_post_field() To get the post type of the supplied id2100 * @uses bbp_get_reply_topic_id() To get the reply topic id2101 * @uses wpdb::prepare() To prepare our sql query2102 * @uses wpdb::get_col() To execute our query and get the column back2103 * @uses update_post_meta() To update the topic hidden reply count meta2104 * @uses apply_filters() Calls 'bbp_update_topic_hidden_reply_count' with the2105 * hidden reply count and topic id2106 * @return int Topic hidden reply count2107 */2108 function bbp_update_topic_hidden_reply_count( $topic_id = 0 ) {2109 global $wpdb, $bbp;2110 2111 $topic_id = bbp_get_topic_id( $topic_id );2112 2113 // If it's a reply, then get the parent (topic id)2114 if ( $bbp->reply_id == get_post_field( 'post_type', $topic_id ) )2115 $topic_id = bbp_get_reply_topic_id( $topic_id );2116 2117 // Get replies of topic2118 $replies = count( $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( '" . join( '\',\'', array( $bbp->trash_status_id, $bbp->spam_status_id ) ) . "') AND post_type = '" . $bbp->reply_id . "';", $topic_id ) ) );2119 2120 // Update the count2121 update_post_meta( $topic_id, '_bbp_topic_hidden_reply_count', (int) $replies );2122 2123 return apply_filters( 'bbp_update_topic_hidden_reply_count', (int) $replies, $topic_id );2124 }2125 2126 /**2127 * Update the topics last active date/time (aka freshness)2128 *2129 * @since bbPress (r2680)2130 *2131 * @param int $topic_id Optional. Topic id2132 * @param string $new_time Optional. New time in mysql format2133 * @uses bbp_get_topic_id() To get the topic id2134 * @uses bbp_get_reply_topic_id() To get the reply topic id2135 * @uses current_time() To get the current time2136 * @uses update_post_meta() To update the topic last active meta2137 * @return bool True on success, false on failure2138 */2139 function bbp_update_topic_last_active( $topic_id = 0, $new_time = '' ) {2140 $topic_id = bbp_get_topic_id( $topic_id );2141 2142 // Check time and use current if empty2143 if ( empty( $new_time ) )2144 $new_time = current_time( 'mysql' );2145 2146 // Update the last reply ID2147 if ( !empty( $topic_id ) )2148 return update_post_meta( $topic_id, '_bbp_topic_last_active', $new_time );2149 2150 return false;2151 }2152 2153 /**2154 * Update the topic with the most recent reply ID2155 *2156 * @since bbPress (r2625)2157 *2158 * @param int $topic_id Optional. Topic id to update2159 * @param int $reply_id Optional. Reply id2160 * @uses bbp_get_topic_id() To get the topic id2161 * @uses bbp_get_reply_id() To get the reply id2162 * @uses update_post_meta() To update the topic last reply id meta2163 * @return bool True on success, false on failure2164 */2165 function bbp_update_topic_last_reply_id( $topic_id = 0, $reply_id = 0 ) {2166 $topic_id = bbp_get_topic_id( $topic_id );2167 $reply_id = bbp_get_reply_id( $reply_id );2168 2169 // Update the last reply ID2170 if ( !empty( $topic_id ) )2171 return update_post_meta( $topic_id, '_bbp_topic_last_reply_id', $reply_id );2172 2173 return false;2174 }2175 2176 /**2177 * Adjust the total voice count of a topic2178 *2179 * @since bbPress (r2567)2180 *2181 * @param int $topic_id Optional. Topic id to update2182 * @uses bbp_get_topic_id() To get the topic id2183 * @uses get_post_field() To get the post type of the supplied id2184 * @uses bbp_get_reply_topic_id() To get the reply topic id2185 * @uses wpdb::prepare() To prepare our sql query2186 * @uses wpdb::get_col() To execute our query and get the column back2187 * @uses update_post_meta() To update the topic voice count meta2188 * @uses apply_filters() Calls 'bbp_update_topic_voice_count' with the voice2189 * count and topic id2190 * @return bool False on failure, voice count on success2191 */2192 function bbp_update_topic_voice_count( $topic_id = 0 ) {2193 global $wpdb, $bbp;2194 2195 $topic_id = bbp_get_topic_id( $topic_id );2196 2197 // If it is not a topic or reply, then we don't need it2198 if ( !in_array( get_post_field( 'post_type', $topic_id ), array( $bbp->topic_id, $bbp->reply_id ) ) )2199 return false;2200 2201 // If it's a reply, then get the parent (topic id)2202 if ( $bbp->reply_id == get_post_field( 'post_type', $topic_id ) )2203 $topic_id = bbp_get_reply_topic_id( $topic_id );2204 2205 // There should always be at least 1 voice2206 if ( !$voices = count( $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE ( post_parent = %d AND post_status = 'publish' AND post_type = '" . $bbp->reply_id . "' ) OR ( ID = %d AND post_type = '" . $bbp->topic_id . "' );", $topic_id, $topic_id ) ) ) )2207 $voices = 1;2208 2209 // Update the count2210 update_post_meta( $topic_id, '_bbp_topic_voice_count', (int) $voices );2211 2212 return apply_filters( 'bbp_update_topic_voice_count', (int) $voices, $topic_id );2213 }2214 2215 2056 /** Topic Pagination **********************************************************/ 2216 2057 … … 2287 2128 return apply_filters( 'bbp_get_forum_pagination_links', $bbp->topic_query->pagination_links ); 2288 2129 } 2289 2290 /** END - Topic Loop Functions ************************************************/2291 2292 /** Topic Actions *************************************************************/2293 2294 /**2295 * Closes a topic2296 *2297 * @since bbPress (r2740)2298 *2299 * @param int $topic_id Topic id2300 * @uses wp_get_single_post() To get the topic2301 * @uses do_action() Calls 'bbp_close_topic' with the topic id2302 * @uses add_post_meta() To add the previous status to a meta2303 * @uses wp_insert_post() To update the topic with the new status2304 * @uses do_action() Calls 'bbp_opened_topic' with the topic id2305 * @return mixed False or {@link WP_Error} on failure, topic id on success2306 */2307 function bbp_close_topic( $topic_id = 0 ) {2308 global $bbp;2309 2310 if ( !$topic = wp_get_single_post( $topic_id, ARRAY_A ) )2311 return $topic;2312 2313 if ( $topic['post_status'] == $bbp->closed_status_id )2314 return false;2315 2316 do_action( 'bbp_close_topic', $topic_id );2317 2318 add_post_meta( $topic_id, '_bbp_topic_status', $topic['post_status'] );2319 2320 $topic['post_status'] = $bbp->closed_status_id;2321 2322 $topic_id = wp_insert_post( $topic );2323 2324 do_action( 'bbp_closed_topic', $topic_id );2325 2326 return $topic_id;2327 }2328 2329 /**2330 * Opens a topic2331 *2332 * @since bbPress (r2740)2333 *2334 * @param int $topic_id Topic id2335 * @uses wp_get_single_post() To get the topic2336 * @uses do_action() Calls 'bbp_open_topic' with the topic id2337 * @uses get_post_meta() To get the previous status2338 * @uses delete_post_meta() To delete the previous status meta2339 * @uses wp_insert_post() To update the topic with the new status2340 * @uses do_action() Calls 'bbp_opened_topic' with the topic id2341 * @return mixed False or {@link WP_Error} on failure, topic id on success2342 */2343 function bbp_open_topic( $topic_id = 0 ) {2344 global $bbp;2345 2346 if ( !$topic = wp_get_single_post( $topic_id, ARRAY_A ) )2347 return $topic;2348 2349 if ( $topic['post_status'] != $bbp->closed_status_id )2350 return false;2351 2352 do_action( 'bbp_open_topic', $topic_id );2353 2354 $topic_status = get_post_meta( $topic_id, '_bbp_topic_status', true );2355 $topic['post_status'] = $topic_status;2356 2357 delete_post_meta( $topic_id, '_bbp_topic_status' );2358 2359 $topic_id = wp_insert_post( $topic );2360 2361 do_action( 'bbp_opened_topic', $topic_id );2362 2363 return $topic_id;2364 }2365 2366 /**2367 * Marks a topic as spam2368 *2369 * @since bbPress (r2740)2370 *2371 * @param int $topic_id Topic id2372 * @uses wp_get_single_post() To get the topic2373 * @uses do_action() Calls 'bbp_spam_topic' with the topic id2374 * @uses add_post_meta() To add the previous status to a meta2375 * @uses wp_insert_post() To update the topic with the new status2376 * @uses do_action() Calls 'bbp_spammed_topic' with the topic id2377 * @return mixed False or {@link WP_Error} on failure, topic id on success2378 */2379 function bbp_spam_topic( $topic_id = 0 ) {2380 global $bbp;2381 2382 if ( !$topic = wp_get_single_post( $topic_id, ARRAY_A ) )2383 return $topic;2384 2385 if ( $topic['post_status'] == $bbp->spam_status_id )2386 return false;2387 2388 do_action( 'bbp_spam_topic', $topic_id );2389 2390 add_post_meta( $topic_id, '_bbp_spam_meta_status', $topic['post_status'] );2391 2392 $topic['post_status'] = $bbp->spam_status_id;2393 2394 $topic_id = wp_insert_post( $topic );2395 2396 do_action( 'bbp_spammed_topic', $topic_id );2397 2398 return $topic_id;2399 }2400 2401 /**2402 * Unspams a topic2403 *2404 * @since bbPress (r2740)2405 *2406 * @param int $topic_id Topic id2407 * @uses wp_get_single_post() To get the topic2408 * @uses do_action() Calls 'bbp_unspam_topic' with the topic id2409 * @uses get_post_meta() To get the previous status2410 * @uses delete_post_meta() To delete the previous status meta2411 * @uses wp_insert_post() To update the topic with the new status2412 * @uses do_action() Calls 'bbp_unspammed_topic' with the topic id2413 * @return mixed False or {@link WP_Error} on failure, topic id on success2414 */2415 function bbp_unspam_topic( $topic_id = 0 ) {2416 global $bbp;2417 2418 if ( !$topic = wp_get_single_post( $topic_id, ARRAY_A ) )2419 return $topic;2420 2421 if ( $topic['post_status'] != $bbp->spam_status_id )2422 return false;2423 2424 do_action( 'bbp_unspam_topic', $topic_id );2425 2426 $topic_status = get_post_meta( $topic_id, '_bbp_spam_meta_status', true );2427 $topic['post_status'] = $topic_status;2428 2429 delete_post_meta( $topic_id, '_bbp_spam_meta_status' );2430 2431 $topic_id = wp_insert_post( $topic );2432 2433 do_action( 'bbp_unspammed_topic', $topic_id );2434 2435 return $topic_id;2436 }2437 2438 /**2439 * Sticks a topic to a forum or front2440 *2441 * @since bbPress (r2754)2442 *2443 * @param int $topic_id Optional. Topic id2444 * @param int $super Should we make the topic a super sticky?2445 * @uses bbp_get_topic_id() To get the topic id2446 * @uses bbp_unstick_topic() To unstick the topic2447 * @uses bbp_get_topic_forum_id() To get the topic forum id2448 * @uses bbp_get_stickies() To get the stickies2449 * @uses do_action() 'bbp_stick_topic' with topic id and bool super2450 * @uses update_option() To update the super stickies option2451 * @uses update_post_meta() To update the forum stickies meta2452 * @uses do_action() Calls 'bbp_sticked_topic' with the topic id, bool super2453 * and success2454 * @return bool True on success, false on failure2455 */2456 function bbp_stick_topic( $topic_id = 0, $super = false ) {2457 $topic_id = bbp_get_topic_id( $topic_id );2458 2459 // We may have a super sticky to which we want to convert into a normal sticky and vice versa2460 // So, unstick the topic first to avoid any possible error2461 bbp_unstick_topic( $topic_id );2462 2463 $forum_id = empty( $super ) ? bbp_get_topic_forum_id( $topic_id ) : 0;2464 $stickies = bbp_get_stickies( $forum_id );2465 2466 do_action( 'bbp_stick_topic', $topic_id, $super );2467 2468 if ( !is_array( $stickies ) )2469 $stickies = array( $topic_id );2470 else2471 $stickies[] = $topic_id;2472 2473 $stickies = array_unique( array_filter( $stickies ) );2474 2475 $success = !empty( $super ) ? update_option( '_bbp_super_sticky_topics', $stickies ) : update_post_meta( $forum_id, '_bbp_sticky_topics', $stickies );2476 2477 do_action( 'bbp_sticked_topic', $topic_id, $super, $success );2478 2479 return $success;2480 }2481 2482 /**2483 * Unsticks a topic both from front and it's forum2484 *2485 * @since bbPress (r2754)2486 *2487 * @param int $topic_id Optional. Topic id2488 * @uses bbp_get_topic_id() To get the topic id2489 * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky2490 * @uses bbp_get_topic_forum_id() To get the topic forum id2491 * @uses bbp_get_stickies() To get the forum stickies2492 * @uses do_action() Calls 'bbp_unstick_topic' with the topic id2493 * @uses delete_option() To delete the super stickies option2494 * @uses update_option() To update the super stickies option2495 * @uses delete_post_meta() To delete the forum stickies meta2496 * @uses update_post_meta() To update the forum stickies meta2497 * @uses do_action() Calls 'bbp_unsticked_topic' with the topic id and success2498 * @return bool Always true.2499 */2500 function bbp_unstick_topic( $topic_id = 0 ) {2501 $topic_id = bbp_get_topic_id( $topic_id );2502 $super = bbp_is_topic_super_sticky( $topic_id );2503 $forum_id = empty( $super ) ? bbp_get_topic_forum_id( $topic_id ) : 0;2504 $stickies = bbp_get_stickies( $forum_id );2505 $offset = array_search( $topic_id, $stickies );2506 2507 do_action( 'bbp_unstick_topic', $topic_id );2508 2509 if ( empty( $stickies ) ) {2510 $success = true;2511 } elseif ( !in_array( $topic_id, $stickies ) ) {2512 $success = true;2513 } elseif ( false === $offset ) {2514 $success = true;2515 } else {2516 array_splice( $stickies, $offset, 1 );2517 if ( empty( $stickies ) )2518 $success = !empty( $super ) ? delete_option( '_bbp_super_sticky_topics' ) : delete_post_meta( $forum_id, '_bbp_sticky_topics' );2519 else2520 $success = !empty( $super ) ? update_option( '_bbp_super_sticky_topics', $stickies ) : update_post_meta( $forum_id, '_bbp_sticky_topics', $stickies );2521 }2522 2523 do_action( 'bbp_unsticked_topic', $topic_id, $success );2524 2525 return true;2526 }2527 2130 2528 2131 /** -
branches/plugin/bbpress.php
r2789 r2790 295 295 296 296 // Load the files 297 require_once( $this->plugin_dir . '/bbp-includes/bbp-loader.php' ); 298 require_once( $this->plugin_dir . '/bbp-includes/bbp-options.php' ); 299 require_once( $this->plugin_dir . '/bbp-includes/bbp-caps.php' ); 300 require_once( $this->plugin_dir . '/bbp-includes/bbp-hooks.php' ); 301 require_once( $this->plugin_dir . '/bbp-includes/bbp-classes.php' ); 302 require_once( $this->plugin_dir . '/bbp-includes/bbp-functions.php' ); 303 require_once( $this->plugin_dir . '/bbp-includes/bbp-widgets.php' ); 304 require_once( $this->plugin_dir . '/bbp-includes/bbp-users.php' ); 305 306 // Load template files 307 require_once( $this->plugin_dir . '/bbp-includes/bbp-general-template.php' ); 308 require_once( $this->plugin_dir . '/bbp-includes/bbp-forum-template.php' ); 309 require_once( $this->plugin_dir . '/bbp-includes/bbp-topic-template.php' ); 310 require_once( $this->plugin_dir . '/bbp-includes/bbp-reply-template.php' ); 311 require_once( $this->plugin_dir . '/bbp-includes/bbp-user-template.php' ); 297 foreach ( array( 'loader', 'options', 'caps', 'hooks', 'classes', 'widgets' ) as $file ) 298 require_once( $this->plugin_dir . '/bbp-includes/bbp-' . $file . '.php' ); 299 300 // Load the function and template files 301 foreach ( array( 'general', 'forum', 'topic', 'reply', 'user' ) as $file ) { 302 require_once( $this->plugin_dir . '/bbp-includes/bbp-' . $file . '-functions.php' ); 303 require_once( $this->plugin_dir . '/bbp-includes/bbp-' . $file . '-template.php' ); 304 } 312 305 313 306 // Quick admin check and load if needed
Note: See TracChangeset
for help on using the changeset viewer.