Changeset 2970 for branches/plugin/bbp-includes/bbp-general-functions.php
- Timestamp:
- 04/01/2011 01:33:09 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-includes/bbp-general-functions.php
r2957 r2970 116 116 /** 117 117 * The plugin version of bbPress comes with two topic display options: 118 * ~ Traditional -Topics are included in the reply loop (default)119 * ~ New Style -Topics appear as "lead" posts, ahead of replies118 * - Traditional: Topics are included in the reply loop (default) 119 * - New Style: Topics appear as "lead" posts, ahead of replies 120 120 * 121 121 * @since bbPress (r2954) 122 122 * 123 * @global obj $bbp124 123 * @param $show_lead Optional. Default false 125 * @return bool 124 * @return bool Yes if the topic appears as a lead, otherwise false 126 125 */ 127 126 function bbp_show_lead_topic( $show_lead = false ) { … … 158 157 * Append 'view=all' to query string if it's already there from referer 159 158 * 160 * @param string $original_link 161 * @return <type> 159 * @param string $original_link Original Link to be modified 160 * @uses current_user_can() To check if the current user can moderate 161 * @uses add_query_arg() To add args to the url 162 * @uses apply_filters() Calls 'bbp_add_view_all' with the link and original link 163 * @return string The link with 'view=all' appended if necessary 162 164 */ 163 165 function bbp_add_view_all( $original_link ) { … … 202 204 * @param array $data Post data 203 205 * @param array $postarr Original post array (includes post id) 206 * @uses bbp_get_topic_post_type() To get the topic post type 207 * @uses bbp_get_reply_post_type() To get the reply post type 204 208 * @uses bbp_is_topic_anonymous() To check if the topic is by an anonymous user 205 209 * @uses bbp_is_reply_anonymous() To check if the reply is by an anonymous user … … 259 263 * - count_empty_tags: Count empty tags? 260 264 * @uses bbp_count_users() To count the number of registered users 265 * @uses bbp_get_forum_post_type() To get the forum post type 266 * @uses bbp_get_topic_post_type() To get the topic post type 267 * @uses bbp_get_reply_post_type() To get the reply post type 261 268 * @uses wp_count_posts() To count the number of forums, topics and replies 262 269 * @uses wp_count_terms() To count the number of topic tags … … 537 544 // Assign variables 538 545 $defaults = array ( 539 'bbp_anonymous_name' => $_POST['bbp_anonymous_name'],540 'bbp_anonymous_email' => $_POST['bbp_anonymous_email'],541 'bbp_anonymous_website' => $_POST['bbp_anonymous_website'],542 'bbp_anonymous_ip' => $_SERVER['REMOTE_ADDR']546 'bbp_anonymous_name' => !empty( $_POST['bbp_anonymous_name'] ) ? $_POST['bbp_anonymous_name'] : false, 547 'bbp_anonymous_email' => !empty( $_POST['bbp_anonymous_email'] ) ? $_POST['bbp_anonymous_email'] : false, 548 'bbp_anonymous_website' => !empty( $_POST['bbp_anonymous_website'] ) ? $_POST['bbp_anonymous_website'] : false, 549 'bbp_anonymous_ip' => !empty( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : false 543 550 ); 544 551 … … 680 687 * 681 688 * @uses bbp_is_user_profile_page() To check if it's a profile page 689 * @uses apply_filters() Calls 'bbp_profile_templates' with the profile 690 * templates array 682 691 * @uses bbp_is_user_profile_edit() To check if it's a profile edit page 692 * @uses apply_filters() Calls 'bbp_profile_edit_templates' with the profile 693 * edit templates array 694 * @uses bbp_is_view() To check if it's a view page 695 * @uses bbp_get_view_id() To get the view id 696 * @uses apply_filters() Calls 'bbp_view_templates' with the view templates array 683 697 * @uses bbp_is_topic_edit() To check if it's a topic edit page 698 * @uses bbp_get_topic_post_type() To get the topic post type 699 * @uses apply_filters() Calls 'bbp_topic_edit_templates' with the topic edit 700 * templates array 684 701 * @uses bbp_is_reply_edit() To check if it's a reply edit page 702 * @uses bbp_get_reply_post_type() To get the reply post type 703 * @uses apply_filters() Calls 'bbp_reply_edit_templates' with the reply edit 704 * templates array 685 705 * @uses apply_filters() Calls 'bbp_custom_template' with the template array 686 706 * @uses bbp_load_template() To load the template … … 707 727 'bbpress/user-edit.php', 708 728 'user-edit.php', 729 'forums/user.php', 709 730 'bbpress/user.php', 710 731 'user.php', … … 717 738 $template = apply_filters( 'bbp_view_templates', array( 718 739 'forums/view-' . bbp_get_view_id(), 740 'bbpress/view-' . bbp_get_view_id(), 719 741 'forums/view.php', 720 'bbpress/view-' . bbp_get_view_id(),721 742 'bbpress/view.php', 722 743 'view-' . bbp_get_view_id(), … … 729 750 $template = array( 730 751 'forums/action-edit.php', 752 'bbpress/action-edit.php', 731 753 'forums/single-' . bbp_get_topic_post_type(), 732 'bbpress/action-edit.php',733 754 'bbpress/single-' . bbp_get_topic_post_type(), 734 755 'action-bbp-edit.php', … … 740 761 // Add split/merge to front of array if present in _GET 741 762 if ( !empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'merge', 'split' ) ) ) { 742 array_unshift( $template, array(763 array_unshift( $template, 743 764 'forums/action-split-merge.php', 744 765 'bbpress/action-split-merge.php', 745 'action- bbp-split-merge.php'746 ) );766 'action-split-merge.php' 767 ); 747 768 } 748 769 … … 753 774 $template = apply_filters( 'bbp_reply_edit_templates', array( 754 775 'forums/action-edit.php', 776 'bbpress/action-edit.php', 755 777 'forums/single-' . bbp_get_reply_post_type(), 756 'bbpress/action-edit.php',757 778 'bbpress/single-' . bbp_get_reply_post_type(), 758 779 'action-bbp-edit.php', … … 778 799 */ 779 800 function bbp_load_template( $files ) { 801 802 // Bail if nothing passed 780 803 if ( empty( $files ) ) 781 804 return; … … 788 811 if ( locate_template( $files, true ) ) 789 812 exit(); 790 791 return;792 813 } 793 814 … … 811 832 * 812 833 * @uses get_query_var() To get {@link WP_Query} query var 834 * @uses is_email() To check if the string is an email 835 * @uses get_user_by() To try to get the user by email and nicename 813 836 * @uses WP_User to get the user data 814 837 * @uses WP_Query::set_404() To set a 404 status 815 * @uses is_multisite() To check if it's a multisite816 838 * @uses current_user_can() To check if the current user can edit the user 817 839 * @uses apply_filters() Calls 'enable_edit_any_user_configuration' with true 818 840 * @uses wp_die() To die 841 * @uses bbp_get_query_name() To get the query name and check if it's 'bbp_widget' 842 * @uses bbp_get_view_query_args() To get the view query args 843 * @uses bbp_get_topic_post_type() To get the topic post type 844 * @uses bbp_get_reply_post_type() To get the reply post type 845 * @uses is_multisite() To check if it's a multisite 846 * @uses remove_action() To remove the auto save post revision action 819 847 */ 820 848 function bbp_pre_get_posts( $wp_query ) { 821 849 global $bbp, $wp_version; 822 850 851 // Bail if $wp_query is empty or of incorrect class 852 if ( empty( $wp_query ) || ( 'WP_Query' != get_class( $wp_query ) ) ) 853 return $wp_query; 854 855 // Get query variables 823 856 $bbp_user = get_query_var( 'bbp_user' ); 824 857 $bbp_view = get_query_var( 'bbp_view' ); … … 930 963 * @uses bbp_is_user_profile_page() To check if it's a user profile page 931 964 * @uses bbp_is_user_profile_edit() To check if it's a user profile edit page 965 * @uses bbp_is_user_home() To check if the profile page is of the current user 932 966 * @uses get_query_var() To get the user id 933 967 * @uses get_userdata() To get the user data 968 * @uses bbp_is_forum() To check if it's a forum 969 * @uses bbp_get_forum_title() To get the forum title 970 * @uses bbp_is_topic() To check if it's a topic 971 * @uses bbp_get_topic_title() To get the topic title 972 * @uses bbp_is_reply() To check if it's a reply 973 * @uses bbp_get_reply_title() To get the reply title 974 * @uses is_tax() To check if it's the tag page 975 * @uses get_queried_object() To get the queried object 976 * @uses bbp_is_view() To check if it's a view 977 * @uses bbp_get_view_title() To get the view title 934 978 * @uses apply_filters() Calls 'bbp_raw_title' with the title 935 979 * @uses apply_filters() Calls 'bbp_profile_page_wp_title' with the title, … … 1015 1059 } 1016 1060 1017 $title = apply_filters( 'bbp_title', $title, $sep, $seplocation ); 1018 1019 return $title; 1061 // Filter and return 1062 return apply_filters( 'bbp_title', $title, $sep, $seplocation ); 1020 1063 } 1021 1064 … … 1070 1113 return false; 1071 1114 1072 $reply_id = $reply->ID; 1073 $topic_id = $topic->ID; 1074 1075 do_action( 'bbp_pre_notify_subscribers', $reply_id, $topic_id ); 1115 do_action( 'bbp_pre_notify_subscribers', $reply->ID, $topic->ID ); 1076 1116 1077 1117 // Get the users who have favorited the topic and have subscriptions on 1078 if ( !$user_ids = bbp_get_topic_subscribers( $topic_id, true ) ) 1079 return false; 1080 1118 if ( !$user_ids = bbp_get_topic_subscribers( $topic->ID, true ) ) 1119 return false; 1120 1121 // Loop through users 1081 1122 foreach ( (array) $user_ids as $user_id ) { 1082 1123 … … 1086 1127 1087 1128 // For plugins 1088 if ( !$message = apply_filters( 'bbp_subscription_mail_message', __( "%1\$s wrote:\n\n%2\$s\n\nPost Link: %3\$s\n\nYou're getting this mail because you subscribed to the topic, visit the topic and login to unsubscribe." ), $reply _id, $topic_id, $user_id ) )1129 if ( !$message = apply_filters( 'bbp_subscription_mail_message', __( "%1\$s wrote:\n\n%2\$s\n\nPost Link: %3\$s\n\nYou're getting this mail because you subscribed to the topic, visit the topic and login to unsubscribe." ), $reply->ID, $topic->ID, $user_id ) ) 1089 1130 continue; 1090 1131 1132 // Get user data of this user 1091 1133 $user = get_userdata( $user_id ); 1092 1134 1135 // Send notification email 1093 1136 wp_mail( 1094 1137 $user->user_email, 1095 apply_filters( 'bbp_subscription_mail_title', '[' . get_option( 'blogname' ) . '] ' . $topic->post_title, $reply _id, $topic_id),1096 sprintf( $message, $poster_name, strip_tags( $reply->post_content ), bbp_get_reply_permalink( $reply _id) )1138 apply_filters( 'bbp_subscription_mail_title', '[' . get_option( 'blogname' ) . '] ' . $topic->post_title, $reply->ID, $topic->ID ), 1139 sprintf( $message, $poster_name, strip_tags( $reply->post_content ), bbp_get_reply_permalink( $reply->ID ) ) 1097 1140 ); 1098 1141 } 1099 1142 1100 do_action( 'bbp_post_notify_subscribers', $reply _id, $topic_id);1143 do_action( 'bbp_post_notify_subscribers', $reply->ID, $topic->ID ); 1101 1144 1102 1145 return true; … … 1133 1176 */ 1134 1177 function bbp_logout_url( $url = '', $redirect_to = '' ) { 1135 if ( !isset( $_SERVER['REDIRECT_URL'] ) || !$redirect_to = home_url( $_SERVER['REDIRECT_URL'] ) ) 1178 1179 // Rejig the $redirect_to 1180 if ( !isset( $_SERVER['REDIRECT_URL'] ) || ( !$redirect_to = home_url( $_SERVER['REDIRECT_URL'] ) ) ) 1136 1181 $redirect_to = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : ''; 1137 1182 1183 // Make sure we are directing somewhere 1138 1184 if ( empty( $redirect_to ) ) 1139 1185 $redirect_to = home_url( isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '' ); 1140 1186 1141 $url = add_query_arg( array( 'redirect_to' => esc_url( $redirect_to ) ), $url ); 1142 1187 // Sanitize $redirect_to and add it to full $url 1188 $redirect_to = esc_url( add_query_arg( array( 'loggedout' => 'true' ), $redirect_to ) ); 1189 $url = add_query_arg( array( 'redirect_to' => $redirect_to ), $url ); 1190 1191 // Filter and return 1143 1192 return apply_filters( 'bbp_logout_url', $url, $redirect_to ); 1144 1193 } … … 1149 1198 * Query the DB and get the last public post_id that has parent_id as post_parent 1150 1199 * 1151 * @global db $wpdb 1152 * @param int $parent_id 1153 * @param string $post_type 1200 * @param int $parent_id Parent id 1201 * @param string $post_type Post type. Defaults to 'post' 1202 * @uses bbp_get_topic_post_type() To get the topic post type 1203 * @uses wp_cache_get() To check if there is a cache of the last child id 1204 * @uses wpdb::prepare() To prepare the query 1205 * @uses wpdb::get_var() To get the result of the query in a variable 1206 * @uses wp_cache_set() To set the cache for future use 1207 * @uses apply_filters() Calls 'bbp_get_public_child_last_id' with the child 1208 * id, parent id and post type 1154 1209 * @return int The last active post_id 1155 1210 */ … … 1157 1212 global $wpdb; 1158 1213 1214 // Bail if nothing passed 1159 1215 if ( empty( $parent_id ) ) 1160 1216 return false; 1161 1217 1162 1218 // The ID of the cached query 1163 $cache_id = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_last_id'; 1164 1219 $cache_id = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_last_id'; 1220 $post_status = array( 'publish' ); 1221 1222 // Add closed status if topic post type 1223 if ( $post_type == bbp_get_topic_post_type() ) 1224 $post_status[] = $bbp->closed_status_id; 1225 1226 // Join post statuses together 1227 $post_status = "'" . join( "', '", $post_status ) . "'"; 1228 1229 // Check for cache and set if needed 1165 1230 if ( !$child_id = wp_cache_get( $cache_id, 'bbpress' ) ) { 1166 $child_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status = 'publish'AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", $parent_id, $post_type ) );1231 $child_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", $parent_id, $post_type ) ); 1167 1232 wp_cache_set( $cache_id, $child_id, 'bbpress' ); 1168 1233 } 1169 1234 1235 // Filter and return 1170 1236 return apply_filters( 'bbp_get_public_child_last_id', (int) $child_id, (int) $parent_id, $post_type ); 1171 1237 } … … 1174 1240 * Query the DB and get a count of public children 1175 1241 * 1176 * @global db $wpdb 1177 * @param int $parent_id 1178 * @param string $post_type 1242 * @param int $parent_id Parent id 1243 * @param string $post_type Post type. Defaults to 'post' 1244 * @uses bbp_get_topic_post_type() To get the topic post type 1245 * @uses wp_cache_get() To check if there is a cache of the children count 1246 * @uses wpdb::prepare() To prepare the query 1247 * @uses wpdb::get_var() To get the result of the query in a variable 1248 * @uses wp_cache_set() To set the cache for future use 1249 * @uses apply_filters() Calls 'bbp_get_public_child_count' with the child 1250 * count, parent id and post type 1179 1251 * @return int The number of children 1180 1252 */ … … 1182 1254 global $wpdb, $bbp; 1183 1255 1256 // Bail if nothing passed 1184 1257 if ( empty( $parent_id ) ) 1185 1258 return false; 1186 1259 1187 1260 // The ID of the cached query 1188 $cache_id = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_count'; 1189 1261 $cache_id = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_count'; 1262 $post_status = array( 'publish' ); 1263 1264 // Add closed status if topic post type 1265 if ( $post_type == bbp_get_topic_post_type() ) 1266 $post_status[] = $bbp->closed_status_id; 1267 1268 // Join post statuses together 1269 $post_status = "'" . join( "', '", $post_status ) . "'"; 1270 1271 // Check for cache and set if needed 1190 1272 if ( !$child_count = wp_cache_get( $cache_id, 'bbpress' ) ) { 1191 $child_count = $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 = '%s';", $parent_id, $post_type ) );1273 $child_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';", $parent_id, $post_type ) ); 1192 1274 wp_cache_set( $cache_id, $child_count, 'bbpress' ); 1193 1275 } 1194 1276 1277 // Filter and return 1195 1278 return apply_filters( 'bbp_get_public_child_count', (int) $child_count, (int) $parent_id, $post_type ); 1196 1279 } 1197 1280 1198 1281 /** 1199 * Query the DB and get a the child ID's of public children 1200 * 1201 * @global db $wpdb 1202 * @param int $parent_id 1203 * @param string $post_type 1204 * @return int The number of children 1282 * Query the DB and get a the child id's of public children 1283 * 1284 * @param int $parent_id Parent id 1285 * @param string $post_type Post type. Defaults to 'post' 1286 * @uses bbp_get_topic_post_type() To get the topic post type 1287 * @uses wp_cache_get() To check if there is a cache of the children 1288 * @uses wpdb::prepare() To prepare the query 1289 * @uses wpdb::get_col() To get the result of the query in an array 1290 * @uses wp_cache_set() To set the cache for future use 1291 * @uses apply_filters() Calls 'bbp_get_public_child_ids' with the child ids, 1292 * parent id and post type 1293 * @return array The array of children 1205 1294 */ 1206 1295 function bbp_get_public_child_ids( $parent_id = 0, $post_type = 'post' ) { 1207 1296 global $wpdb, $bbp; 1208 1297 1298 // Bail if nothing passed 1209 1299 if ( empty( $parent_id ) ) 1210 1300 return false; 1211 1301 1212 1302 // The ID of the cached query 1213 $cache_id = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_ids'; 1214 1303 $cache_id = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_ids'; 1304 $post_status = array( 'publish' ); 1305 1306 // Add closed status if topic post type 1307 if ( $post_type == bbp_get_topic_post_type() ) 1308 $post_status[] = $bbp->closed_status_id; 1309 1310 // Join post statuses together 1311 $post_status = "'" . join( "', '", $post_status ) . "'"; 1312 1313 // Check for cache and set if needed 1215 1314 if ( !$child_ids = wp_cache_get( $cache_id, 'bbpress' ) ) { 1216 $child_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( '" . join( "', '", array( 'publish', $bbp->closed_status_id ) ) . "') AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ) );1315 $child_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ) ); 1217 1316 wp_cache_set( $cache_id, $child_ids, 'bbpress' ); 1218 1317 } 1219 1318 1319 // Filter and return 1220 1320 return apply_filters( 'bbp_get_public_child_ids', $child_ids, (int) $parent_id, $post_type ); 1221 1321 }
Note: See TracChangeset
for help on using the changeset viewer.