Skip to:
Content

bbPress.org

Changeset 2790


Ignore:
Timestamp:
01/10/2011 04:23:18 AM (14 years ago)
Author:
johnjamesjacoby
Message:

Split apart bbp-functions.php into smaller, more manageable files. Also fix missing global on subscription removal. Props GautamGupta via Google Code-in

Location:
branches/plugin
Files:
5 added
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-forum-template.php

    r2788 r2790  
    996996
    997997/**
    998  * Closes a forum
    999  *
    1000  * @since bbPress (r2746)
    1001  *
    1002  * @param int $forum_id forum id
    1003  * @uses wp_get_single_post() To get the forum
    1004  * @uses do_action() Calls 'bbp_close_forum' with the forum id
    1005  * @uses add_post_meta() To add the previous status to a meta
    1006  * @uses wp_insert_post() To update the forum with the new status
    1007  * @uses do_action() Calls 'bbp_opened_forum' with the forum id
    1008  * @return mixed False or {@link WP_Error} on failure, forum id on success
    1009  */
    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 forum
    1027  *
    1028  * @since bbPress (r2746)
    1029  *
    1030  * @param int $forum_id forum id
    1031  * @uses wp_get_single_post() To get the forum
    1032  * @uses do_action() Calls 'bbp_open_forum' with the forum id
    1033  * @uses get_post_meta() To get the previous status
    1034  * @uses delete_post_meta() To delete the previous status meta
    1035  * @uses wp_insert_post() To update the forum with the new status
    1036  * @uses do_action() Calls 'bbp_opened_forum' with the forum id
    1037  * @return mixed False or {@link WP_Error} on failure, forum id on success
    1038  */
    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 category
    1056  *
    1057  * @since bbPress (r2746)
    1058  *
    1059  * @param int $forum_id Optional. Forum id
    1060  * @uses update_post_meta() To update the forum category meta
    1061  * @return bool False on failure, true on success
    1062  */
    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 forum
    1069  *
    1070  * @since bbPress (r2746)
    1071  *
    1072  * @param int $forum_id Optional. Forum id
    1073  * @uses delete_post_meta() To delete the forum category meta
    1074  * @return bool False on failure, true on success
    1075  */
    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 private
    1082  *
    1083  * @since bbPress (r2746)
    1084  *
    1085  * @param int $forum_id Optional. Forum id
    1086  * @uses update_post_meta() To update the forum private meta
    1087  * @return bool False on failure, true on success
    1088  */
    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 private
    1095  *
    1096  * @since bbPress (r2746)
    1097  *
    1098  * @param int $forum_id Optional. Forum id
    1099  * @uses delete_post_meta() To delete the forum private meta
    1100  * @return bool False on failure, true on success
    1101  */
    1102 function bbp_publicize_forum( $forum_id = 0 ) {
    1103     return update_post_meta( $forum_id, '_bbp_forum_visibility', 'public' );
    1104 }
    1105 
    1106 /**
    1107998 * Is the forum a category?
    1108999 *
     
    12391130    }
    12401131
    1241 /** Forum Updaters ************************************************************/
    1242 
    1243 /**
    1244  * Update the forum last topic id
    1245  *
    1246  * @since bbPress (r2625)
    1247  *
    1248  * @param int $forum_id Optional. Forum id
    1249  * @param int $topic_id Optional. Topic id
    1250  * @uses bbp_get_forum_id() To get the forum id
    1251  * @uses bbp_get_topic_id() To get the topic id
    1252  * @uses update_post_meta() To update the forum's last topic id meta
    1253  * @return bool True on success, false on failure
    1254  */
    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 ID
    1260     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 id
    1268  *
    1269  * @since bbPress (r2625)
    1270  *
    1271  * @param int $forum_id Optional. Forum id
    1272  * @param int $reply_id Optional. Reply id
    1273  * @uses bbp_get_forum_id() To get the forum id
    1274  * @uses bbp_get_reply_id() To get the reply id
    1275  * @uses update_post_meta() To update the forum's last reply id meta
    1276  * @return bool True on success, false on failure
    1277  */
    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 ID
    1283     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 id
    1295  * @param string $new_time Optional. New time in mysql format
    1296  * @uses bbp_get_forum_id() To get the forum id
    1297  * @uses current_time() To get the current time
    1298  * @uses update_post_meta() To update the forum's last active meta
    1299  * @return bool True on success, false on failure
    1300  */
    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 empty
    1305     if ( empty( $new_time ) )
    1306         $new_time = current_time( 'mysql' );
    1307 
    1308     // Update last active
    1309     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 count
    1317  *
    1318  * @todo Make this work.
    1319  *
    1320  * @since bbPress (r2625)
    1321  *
    1322  * @param int $forum_id Optional. Forum id
    1323  * @uses bbp_get_forum_id() To get the forum id
    1324  * @return bool True on success, false on failure
    1325  */
    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 forum
    1334  *
    1335  * @since bbPress (r2464)
    1336  *
    1337  * @param int $forum_id Optional. Forum id or topic id. It is checked whether it
    1338  *                       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 topic
    1341  * @uses bbp_get_topic_forum_id() To get the topic's forum id
    1342  * @uses wpdb::prepare() To prepare the sql statement
    1343  * @uses wpdb::get_col() To execute the query and get the column back
    1344  * @uses update_post_meta() To update the forum's topic count meta
    1345  * @uses apply_filters() Calls 'bbp_update_forum_topic_count' with the topic
    1346  *                        count and forum id
    1347  * @return int Forum topic count
    1348  */
    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 count
    1359     $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 count
    1362     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 forum
    1369  *
    1370  * @todo Make this work
    1371  *
    1372  * @since bbPress (r2464)
    1373  *
    1374  * @param int $forum_id Optional. Forum id or reply id. It is checked whether it
    1375  *                       is a reply or a forum. If it's a reply, its forum is
    1376  *                       automatically retrieved.
    1377  * @uses get_post_field() To check whether the supplied id is a reply
    1378  * @uses bbp_get_reply_topic_id() To get the reply's topic id
    1379  * @uses bbp_get_topic_forum_id() To get the topic's forum id
    1380  * @uses wpdb::prepare() To prepare the sql statement
    1381  * @uses wpdb::get_col() To execute the query and get the column back
    1382  * @uses update_post_meta() To update the forum's reply count meta
    1383  * @uses apply_filters() Calls 'bbp_update_forum_reply_count' with the reply
    1384  *                        count and forum id
    1385  * @return int Forum reply count
    1386  */
    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 voice
    1399     $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 count
    1402     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 forum
    1409  *
    1410  * @since bbPress (r2567)
    1411  *
    1412  * @param int $forum_id Optional. Forum, topic or reply id. The forum is
    1413  *                                 automatically retrieved based on the input.
    1414  * @uses get_post_field() To check whether the supplied id is a reply
    1415  * @uses bbp_get_reply_topic_id() To get the reply's topic id
    1416  * @uses bbp_get_topic_forum_id() To get the topic's forum id
    1417  * @uses wpdb::prepare() To prepare the sql statement
    1418  * @uses wpdb::get_col() To execute the query and get the column back
    1419  * @uses update_post_meta() To update the forum's voice count meta
    1420  * @uses apply_filters() Calls 'bbp_update_forum_voice_count' with the voice
    1421  *                        count and forum id
    1422  * @return int Forum voice count
    1423  */
    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 voice
    1438     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 count
    1442     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 
    14491132?>
  • branches/plugin/bbp-includes/bbp-general-template.php

    r2789 r2790  
    564564 * @uses wp_referer_field() To generate a hidden referer field
    565565 */
    566 function bbp_edit_user_form_fields() { ?>
     566function bbp_edit_user_form_fields() {
     567?>
    567568
    568569    <input type="hidden" name="action"  id="bbp_post_action" value="bbp-update-user" />
     
    584585 */
    585586function bbp_merge_topic_form_fields() {
    586 
    587     ?>
     587?>
    588588
    589589    <input type="hidden" name="action"       id="bbp_post_action" value="bbp-merge-topic" />
     
    603603 */
    604604function bbp_split_topic_form_fields() {
    605 
    606     ?>
     605?>
    607606
    608607    <input type="hidden" name="action"       id="bbp_post_action" value="bbp-split-topic" />
  • branches/plugin/bbp-includes/bbp-options.php

    r2789 r2790  
    1717 *
    1818 * @uses add_option() Adds default options
     19 * @uses do_action() Calls 'bbp_add_options'
    1920 */
    2021function bbp_add_options() {
     
    8283}
    8384
     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 */
     95function 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 */
     107function 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 */
     119function bbp_allow_anonymous() {
     120    return apply_filters( 'bbp_allow_anonymous', get_option( '_bbp_allow_anonymous', false ) );
     121}
     122
    84123?>
  • branches/plugin/bbp-includes/bbp-reply-template.php

    r2788 r2790  
    15091509/** END Reply Loop Functions **************************************************/
    15101510
    1511 /** Reply Actions *************************************************************/
    1512 
    1513 /**
    1514  * Marks a reply as spam
    1515  *
    1516  * @since bbPress (r2740)
    1517  *
    1518  * @param int $reply_id Reply id
    1519  * @uses wp_get_single_post() To get the reply
    1520  * @uses do_action() Calls 'bbp_spam_reply' with the reply id before marking
    1521  *                    the reply as spam
    1522  * @uses add_post_meta() To add the previous status to a meta
    1523  * @uses wp_insert_post() To insert the updated post
    1524  * @uses do_action() Calls 'bbp_spammed_reply' with the reply id after marking
    1525  *                    the reply as spam
    1526  * @return mixed False or {@link WP_Error} on failure, reply id on success
    1527  */
    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 reply
    1551  *
    1552  * @since bbPress (r2740)
    1553  *
    1554  * @param int $reply_id Reply id
    1555  * @uses wp_get_single_post() To get the reply
    1556  * @uses do_action() Calls 'bbp_unspam_reply' with the reply id before unmarking
    1557  *                    the reply as spam
    1558  * @uses get_post_meta() To get the previous status meta
    1559  * @uses delete_post_meta() To delete the previous status meta
    1560  * @uses wp_insert_post() To insert the updated post
    1561  * @uses do_action() Calls 'bbp_unspammed_reply' with the reply id after
    1562  *                    unmarking the reply as spam
    1563  * @return mixed False or {@link WP_Error} on failure, reply id on success
    1564  */
    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 
    15881511?>
  • branches/plugin/bbp-includes/bbp-topic-template.php

    r2789 r2790  
    20542054    }
    20552055
    2056 /** Topic Updaters ************************************************************/
    2057 
    2058 /**
    2059  * Adjust the total reply count of a topic
    2060  *
    2061  * @since bbPress (r2467)
    2062  *
    2063  * @param int $topic_id Optional. Topic id to update
    2064  * @uses bbp_get_topic_id() To get the topic id
    2065  * @uses get_post_field() To get the post type of the supplied id
    2066  * @uses bbp_get_reply_topic_id() To get the reply topic id
    2067  * @uses wpdb::prepare() To prepare our sql query
    2068  * @uses wpdb::get_col() To execute our query and get the column back
    2069  * @uses update_post_meta() To update the topic reply count meta
    2070  * @uses apply_filters() Calls 'bbp_update_topic_reply_count' with the reply
    2071  *                        count and topic id
    2072  * @return int Topic reply count
    2073  */
    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 topic
    2084     $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 count
    2087     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 update
    2098  * @uses bbp_get_topic_id() To get the topic id
    2099  * @uses get_post_field() To get the post type of the supplied id
    2100  * @uses bbp_get_reply_topic_id() To get the reply topic id
    2101  * @uses wpdb::prepare() To prepare our sql query
    2102  * @uses wpdb::get_col() To execute our query and get the column back
    2103  * @uses update_post_meta() To update the topic hidden reply count meta
    2104  * @uses apply_filters() Calls 'bbp_update_topic_hidden_reply_count' with the
    2105  *                        hidden reply count and topic id
    2106  * @return int Topic hidden reply count
    2107  */
    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 topic
    2118     $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 count
    2121     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 id
    2132  * @param string $new_time Optional. New time in mysql format
    2133  * @uses bbp_get_topic_id() To get the topic id
    2134  * @uses bbp_get_reply_topic_id() To get the reply topic id
    2135  * @uses current_time() To get the current time
    2136  * @uses update_post_meta() To update the topic last active meta
    2137  * @return bool True on success, false on failure
    2138  */
    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 empty
    2143     if ( empty( $new_time ) )
    2144         $new_time = current_time( 'mysql' );
    2145 
    2146     // Update the last reply ID
    2147     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 ID
    2155  *
    2156  * @since bbPress (r2625)
    2157  *
    2158  * @param int $topic_id Optional. Topic id to update
    2159  * @param int $reply_id Optional. Reply id
    2160  * @uses bbp_get_topic_id() To get the topic id
    2161  * @uses bbp_get_reply_id() To get the reply id
    2162  * @uses update_post_meta() To update the topic last reply id meta
    2163  * @return bool True on success, false on failure
    2164  */
    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 ID
    2170     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 topic
    2178  *
    2179  * @since bbPress (r2567)
    2180  *
    2181  * @param int $topic_id Optional. Topic id to update
    2182  * @uses bbp_get_topic_id() To get the topic id
    2183  * @uses get_post_field() To get the post type of the supplied id
    2184  * @uses bbp_get_reply_topic_id() To get the reply topic id
    2185  * @uses wpdb::prepare() To prepare our sql query
    2186  * @uses wpdb::get_col() To execute our query and get the column back
    2187  * @uses update_post_meta() To update the topic voice count meta
    2188  * @uses apply_filters() Calls 'bbp_update_topic_voice_count' with the voice
    2189  *                        count and topic id
    2190  * @return bool False on failure, voice count on success
    2191  */
    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 it
    2198     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 voice
    2206     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 count
    2210     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 
    22152056/** Topic Pagination **********************************************************/
    22162057
     
    22872128        return apply_filters( 'bbp_get_forum_pagination_links', $bbp->topic_query->pagination_links );
    22882129    }
    2289 
    2290 /** END - Topic Loop Functions ************************************************/
    2291 
    2292 /** Topic Actions *************************************************************/
    2293 
    2294 /**
    2295  * Closes a topic
    2296  *
    2297  * @since bbPress (r2740)
    2298  *
    2299  * @param int $topic_id Topic id
    2300  * @uses wp_get_single_post() To get the topic
    2301  * @uses do_action() Calls 'bbp_close_topic' with the topic id
    2302  * @uses add_post_meta() To add the previous status to a meta
    2303  * @uses wp_insert_post() To update the topic with the new status
    2304  * @uses do_action() Calls 'bbp_opened_topic' with the topic id
    2305  * @return mixed False or {@link WP_Error} on failure, topic id on success
    2306  */
    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 topic
    2331  *
    2332  * @since bbPress (r2740)
    2333  *
    2334  * @param int $topic_id Topic id
    2335  * @uses wp_get_single_post() To get the topic
    2336  * @uses do_action() Calls 'bbp_open_topic' with the topic id
    2337  * @uses get_post_meta() To get the previous status
    2338  * @uses delete_post_meta() To delete the previous status meta
    2339  * @uses wp_insert_post() To update the topic with the new status
    2340  * @uses do_action() Calls 'bbp_opened_topic' with the topic id
    2341  * @return mixed False or {@link WP_Error} on failure, topic id on success
    2342  */
    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 spam
    2368  *
    2369  * @since bbPress (r2740)
    2370  *
    2371  * @param int $topic_id Topic id
    2372  * @uses wp_get_single_post() To get the topic
    2373  * @uses do_action() Calls 'bbp_spam_topic' with the topic id
    2374  * @uses add_post_meta() To add the previous status to a meta
    2375  * @uses wp_insert_post() To update the topic with the new status
    2376  * @uses do_action() Calls 'bbp_spammed_topic' with the topic id
    2377  * @return mixed False or {@link WP_Error} on failure, topic id on success
    2378  */
    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 topic
    2403  *
    2404  * @since bbPress (r2740)
    2405  *
    2406  * @param int $topic_id Topic id
    2407  * @uses wp_get_single_post() To get the topic
    2408  * @uses do_action() Calls 'bbp_unspam_topic' with the topic id
    2409  * @uses get_post_meta() To get the previous status
    2410  * @uses delete_post_meta() To delete the previous status meta
    2411  * @uses wp_insert_post() To update the topic with the new status
    2412  * @uses do_action() Calls 'bbp_unspammed_topic' with the topic id
    2413  * @return mixed False or {@link WP_Error} on failure, topic id on success
    2414  */
    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 front
    2440  *
    2441  * @since bbPress (r2754)
    2442  *
    2443  * @param int $topic_id Optional. Topic id
    2444  * @param int $super Should we make the topic a super sticky?
    2445  * @uses bbp_get_topic_id() To get the topic id
    2446  * @uses bbp_unstick_topic() To unstick the topic
    2447  * @uses bbp_get_topic_forum_id() To get the topic forum id
    2448  * @uses bbp_get_stickies() To get the stickies
    2449  * @uses do_action() 'bbp_stick_topic' with topic id and bool super
    2450  * @uses update_option() To update the super stickies option
    2451  * @uses update_post_meta() To update the forum stickies meta
    2452  * @uses do_action() Calls 'bbp_sticked_topic' with the topic id, bool super
    2453  *                    and success
    2454  * @return bool True on success, false on failure
    2455  */
    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 versa
    2460     // So, unstick the topic first to avoid any possible error
    2461     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     else
    2471         $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 forum
    2484  *
    2485  * @since bbPress (r2754)
    2486  *
    2487  * @param int $topic_id Optional. Topic id
    2488  * @uses bbp_get_topic_id() To get the topic id
    2489  * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky
    2490  * @uses bbp_get_topic_forum_id() To get the topic forum id
    2491  * @uses bbp_get_stickies() To get the forum stickies
    2492  * @uses do_action() Calls 'bbp_unstick_topic' with the topic id
    2493  * @uses delete_option() To delete the super stickies option
    2494  * @uses update_option() To update the super stickies option
    2495  * @uses delete_post_meta() To delete the forum stickies meta
    2496  * @uses update_post_meta() To update the forum stickies meta
    2497  * @uses do_action() Calls 'bbp_unsticked_topic' with the topic id and success
    2498  * @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         else
    2520             $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 }
    25272130
    25282131/**
  • branches/plugin/bbpress.php

    r2789 r2790  
    295295
    296296        // 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        }
    312305
    313306        // Quick admin check and load if needed
Note: See TracChangeset for help on using the changeset viewer.