Changeset 3789 for branches/plugin/bbp-includes/bbp-extend-buddypress.php
- Timestamp:
- 03/03/2012 12:14:56 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-includes/bbp-extend-buddypress.php
r3760 r3789 939 939 $this->name = bbp_get_forum_archive_title(); 940 940 $this->nav_item_name = bbp_get_forum_archive_title(); 941 $this->slug = bbp_get_forum_slug();942 $this->topic_slug = bbp_get_topic_slug();943 $this->reply_slug = bbp_get_reply_slug();941 $this->slug = 'forums'; 942 $this->topic_slug = 'topic'; 943 $this->reply_slug = 'reply'; 944 944 945 945 // Forum component is visible @todo configure? … … 987 987 // Hide breadcrumb 988 988 add_filter( 'bbp_no_breadcrumb', '__return_true' ); 989 990 // Tweak the redirect field 991 add_filter( 'bbp_new_topic_redirect_to', array( $this, 'new_topic_redirect_to' ), 10, 2 ); 992 add_filter( 'bbp_new_reply_redirect_to', array( $this, 'new_reply_redirect_to' ), 10, 2 ); 989 993 990 994 $this->display_forums( 0 ); … … 1189 1193 return false; 1190 1194 1191 // Map forum permalinks to current group 1192 add_filter( 'bbp_get_forum_permalink', array( $this, 'map_forum_permalink_to_group' ), 10, 2 ); 1193 add_filter( 'bbp_get_topic_permalink', array( $this, 'map_topic_permalink_to_group' ), 10, 2 ); 1194 add_filter( 'bbp_get_reply_permalink', array( $this, 'map_reply_permalink_to_group' ), 10, 2 ); 1195 1196 // Add group admin actions to forum row actions 1197 add_action( 'bbp_forum_row_actions', array( $this, 'forum_row_actions' ) ); 1198 add_action( 'bbp_topic_row_actions', array( $this, 'topic_row_actions' ) ); 1199 1200 // Prevent Topic Parent from appearing 1201 add_action( 'bbp_theme_before_topic_form_forum', array( $this, 'ob_start' ) ); 1202 add_action( 'bbp_theme_after_topic_form_forum', array( $this, 'ob_end_clean' ) ); 1203 add_action( 'bbp_theme_after_topic_form_forum', array( $this, 'topic_parent' ) ); 1204 1205 // Prevent Forum Parent from appearing 1206 add_action( 'bbp_theme_before_forum_form_parent', array( $this, 'ob_start' ) ); 1207 add_action( 'bbp_theme_after_forum_form_parent', array( $this, 'ob_end_clean' ) ); 1208 add_action( 'bbp_theme_after_forum_form_parent', array( $this, 'forum_parent' ) ); 1209 1210 // Do not show the new topic form in the moderation area 1211 add_filter( 'bbp_current_user_can_access_create_topic_form', '__return_false' ); 1212 1213 // Hide breadcrumb 1214 add_filter( 'bbp_no_breadcrumb', '__return_true' ); 1215 1216 $this->display_forums( 1 ); 1195 $checked = bp_get_new_group_enable_forum() || groups_get_groupmeta( bp_get_new_group_id(), 'forum_id' ); 1196 ?> 1197 1198 <h4><?php _e( 'Group Forums', 'buddypress' ); ?></h4> 1199 1200 <p><?php _e( 'Create a discussion forum to allow members of this group to communicate in a structured, bulletin-board style fashion.', 'buddypress' ); ?></p> 1201 1202 <div class="checkbox"> 1203 <label><input type="checkbox" name="bbp-create-group-forum" id="bbp-create-group-forum" value="1"<?php checked( $checked ); ?> /> <?php _e( 'Yes. I want this group to have a forum.', 'buddypress' ); ?></label> 1204 </div> 1205 1206 <?php 1217 1207 1218 1208 // Verify intent 1219 wp_nonce_field( ' bbp_group_create_save_' . $this->slug );1209 wp_nonce_field( 'groups_create_save_' . $this->slug ); 1220 1210 } 1221 1211 … … 1229 1219 function create_screen_save() { 1230 1220 1231 // Bail if not a POST action 1232 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 1233 return; 1234 1235 // Bail if action is empty 1236 if ( empty( $_POST['action'] ) ) 1237 return; 1238 1239 // Handle the different actions that can happen here 1240 switch ( $_POST['action'] ) { 1241 1242 // New forum 1243 case 'bbp-new-forum' : 1244 1245 // Redirect back here, not to the new forum 1246 add_filter( 'bbp_new_forum_redirect_to', array( $this, 'create_redirect_to' ) ); 1247 1248 // Add actions to bbp_new_forum 1249 add_action( 'bbp_new_forum', array( $this, 'new_forum' ), 10, 4 ); 1250 1251 // Handle the new forum 1252 bbp_new_forum_handler(); 1221 check_admin_referer( 'groups_create_save_' . $this->slug ); 1222 1223 $create_forum = !empty( $_POST['bbp-create-group-forum'] ) ? true : false; 1224 $forum_id = groups_get_groupmeta( bp_get_new_group_id(), 'forum_id' ); 1225 1226 // Create a forum, or not 1227 switch ( $create_forum ) { 1228 case true : 1229 1230 // Bail if initial content was already created 1231 if ( !empty( $forum_id ) ) 1232 return; 1233 1234 // Set the default forum status 1235 switch ( bp_get_new_group_status() ) { 1236 case 'hidden' : 1237 $status = bbp_get_hidden_status_id(); 1238 break; 1239 case 'private' : 1240 $status = bbp_get_private_status_id(); 1241 break; 1242 case 'public' : 1243 default : 1244 $status = bbp_get_public_status_id(); 1245 break; 1246 } 1247 1248 // Create the initial forum 1249 $forum_id = bbp_insert_forum( array( 1250 'post_parent' => bbp_get_group_forums_root_id(), 1251 'post_title' => bp_get_new_group_name(), 1252 'post_content' => bp_get_new_group_description(), 1253 'post_status' => $status 1254 ) ); 1255 1256 // Create the initial topic 1257 $topic_id = bbp_insert_topic( 1258 array( 1259 'post_parent' => $forum_id, 1260 'post_title' => __( 'Hello World!', 'bbpress' ), 1261 'post_content' => __( 'I am the first topic in your group forum. You can keep me, edit me, trash me, or delete me.', 'bbpress' ) 1262 ), 1263 array( 'forum_id' => $forum_id ) 1264 ); 1265 1266 // Create the initial reply 1267 $reply_id = bbp_insert_reply( 1268 array( 1269 'post_parent' => $topic_id, 1270 'post_title' => __( 'Re: Hello World!', 'bbpress' ), 1271 'post_content' => __( 'Oh, and this is what a reply looks like.', 'bbpress' ) 1272 ), 1273 array( 1274 'forum_id' => $forum_id, 1275 'topic_id' => $topic_id 1276 ) 1277 ); 1278 1279 // Add the ID's to group meta 1280 groups_update_groupmeta( bp_get_new_group_id(), 'forum_id', $forum_id ); 1281 groups_update_groupmeta( bp_get_new_group_id(), 'first_topic_id', $topic_id ); 1282 groups_update_groupmeta( bp_get_new_group_id(), 'first_reply_id', $reply_id ); 1253 1283 1254 1284 break; 1255 1256 // Edit existing forum 1257 case 'bbp-edit-forum' : 1258 1259 // Redirect back here, not to the new forum 1260 add_filter( 'bbp_edit_forum_redirect_to', array( $this, 'create_redirect_to' ) ); 1261 1262 // Handle the forum edit 1263 bbp_edit_forum_handler(); 1264 1265 break; 1266 1267 // Trash a forum 1268 case 'bbp-trash-forum' : 1269 //bbp_trash_forum_handler(); 1270 break; 1271 1272 // Permanently delet a forum 1273 case 'bbp-delete-forum' : 1274 //bbp_delete_forum_handler(); 1285 case false : 1286 1287 // Forum was created but is now being undone 1288 if ( !empty( $forum_id ) ) { 1289 $topic_id = groups_get_groupmeta( bp_get_new_group_id(), 'first_topic_id' ); 1290 $reply_id = groups_get_groupmeta( bp_get_new_group_id(), 'first_reply_id' ); 1291 1292 // Delete initial content 1293 wp_delete_post( $forum_id, true ); 1294 wp_delete_post( $topic_id, true ); 1295 wp_delete_post( $reply_id, true ); 1296 1297 // Remove the forum ID to group meta 1298 groups_delete_groupmeta( bp_get_new_group_id(), 'forum_id' ); 1299 groups_delete_groupmeta( bp_get_new_group_id(), 'first_topic_id' ); 1300 groups_delete_groupmeta( bp_get_new_group_id(), 'first_reply_id' ); 1301 } 1302 1275 1303 break; 1276 1304 } … … 1330 1358 1331 1359 /** 1332 * Output the forums for a group in the edit /createscreens1360 * Output the forums for a group in the edit screens 1333 1361 * 1334 1362 * @since bbPress (r3653) … … 1345 1373 // Forum data 1346 1374 $forum_ids = bbp_get_group_forum_ids( bp_get_current_group_id() ); 1347 $forum_args = array( 'post__in' => $forum_ids ); 1348 1349 ?> 1375 $forum_args = array( 'post__in' => $forum_ids, 'post_parent' => null ); ?> 1350 1376 1351 1377 <div id="bbpress-forums"> … … 1354 1380 1355 1381 // Looking at the group forum root 1356 if ( ! bp_action_variable( $offset ) || bp_is_group_create()) :1382 if ( ! bp_action_variable( $offset ) ) : 1357 1383 1358 1384 // Query forums and show them if … … 1366 1392 <h3><?php _e( 'Forum', 'bbpress' ); ?></h3> 1367 1393 1394 <?php bbp_set_query_name( 'bbp_single_forum' ); ?> 1395 1368 1396 <?php if ( bbp_has_topics( array( 'post_parent' => bbp_get_forum_id() ) ) ) : ?> 1369 1397 … … 1418 1446 </div> 1419 1447 1420 <?php if ( bp_is_group_ create() ) :1448 <?php if ( bp_is_group_admin_screen( $this->slug ) ) : 1421 1449 bbp_get_template_part( 'form', 'forum' ); 1422 1450 endif; … … 1430 1458 </div> 1431 1459 1432 <?php if ( bp_is_group_admin_screen( $this->slug ) || bp_is_group_create()) :1460 <?php if ( bp_is_group_admin_screen( $this->slug ) ) : 1433 1461 bbp_get_template_part( 'form', 'forum' ); 1434 1462 endif; … … 1541 1569 1542 1570 /** 1543 * Redirect to the group admin forum editscreen1571 * Redirect to the group forum screen 1544 1572 * 1545 1573 * @since bbPress (r3653) … … 1551 1579 * @uses bp_get_groups_root_slug() 1552 1580 */ 1581 public function new_topic_redirect_to( $redirect_url = '', $redirect_to = '' ) { 1582 return $redirect_url; 1583 } 1584 1585 /** 1586 * Redirect to the group admin forum edit screen 1587 * 1588 * @since bbPress (r3653) 1589 * 1590 * @uses groups_get_current_group() 1591 * @uses bp_is_group_admin_screen() 1592 * @uses trailingslashit() 1593 * @uses bp_get_root_domain() 1594 * @uses bp_get_groups_root_slug() 1595 */ 1553 1596 public function edit_redirect_to( $redirect_url = '' ) { 1554 1597 … … 1563 1606 } 1564 1607 1565 /**1566 * Redirect to the group creation forum edit screen1567 *1568 * @since bbPress (r3653)1569 *1570 * @uses bp_is_group_creation_step()1571 * @uses bp_is_action_variable()1572 * @uses bp_get_root_domain()1573 * @uses bp_get_groups_root_slug()1574 */1575 public function create_redirect_to( $redirect_url = '' ) {1576 global $bp;1577 1578 // If this is a group of any kind, empty out the redirect URL1579 if ( bp_is_group_creation_step( $this->slug ) ) {1580 1581 // Loop through1582 foreach ( (array) $bp->groups->group_creation_steps as $slug => $name ) {1583 if ( bp_is_action_variable( $slug ) ) {1584 $previous_steps[] = $slug;1585 break;1586 }1587 1588 $previous_steps[] = $slug;1589 }1590 }1591 $redirect_url = trailingslashit( bp_get_root_domain() ) . bp_get_groups_root_slug() . '/create/step/' . array_pop( $previous_steps );1592 1593 return $redirect_url;1594 }1595 1596 1608 public function forum_parent() { 1597 1609 ?> … … 1613 1625 1614 1626 <?php 1615 } 1627 } 1616 1628 } 1617 1629 endif;
Note: See TracChangeset
for help on using the changeset viewer.