' . __( 'Topic not found.', 'bbpress-moderation-suite' ) . '

'; return; } $GLOBALS['bb_posts'] = get_thread( $topic->topic_id, 1 ); bb_admin_list_posts(); ?>

topic_id ); ?>
' . __( 'Topic not found.', 'bbpress-moderation-suite' ) . '

'; return; } global $bb_posts, $bb_post; $bb_posts = get_thread( $topic->topic_id, array( 'per_page' => -1 ) ); ?>
>
' | ', 'each' => array( 'undelete' => array( 'before' => ' ' ) ), 'last_each' => array( 'before' => ' | ' ) ) ); ?>  
H:i:s' ); } else { printf( __( '%s ago' ), bb_get_post_time( 'since' ) ); } ?>
topic_id ); ?>
post_id ) ) { ?>


post_id ); ?>

forum_id != $_POST['forum_id'] ) { // We're moving the post out of this forum $bbdb->query( $bbdb->prepare( 'UPDATE `' . $bbdb->forums . '` SET `posts` = `posts` - 1 WHERE `forum_id` = %d', $post->forum_id ) ); // And into this forum $bbdb->query( $bbdb->prepare( 'UPDATE `' . $bbdb->forums . '` SET `posts` = `posts` + 1 WHERE `forum_id` = %d', $_POST['forum_id'] ) ); } // And out of its original topic $bbdb->query( $bbdb->prepare( 'UPDATE `' . $bbdb->topics . '` SET `topic_posts` = `topic_posts` - 1 WHERE `topic_id` = %d', $post->topic_id ) ); $topic = bb_insert_topic( array( 'topic_title' => $_POST['topicid'], 'forum_id' => $_POST['forum_id'], 'topic_posts' => 1 ) ); $post = bb_insert_post( array( 'post_id' => $post->post_id, 'topic_id' => $topic ) ); if ( function_exists( 'bbmodsuite_modlog_log' ) ) bbmodsuite_modlog_log( sprintf( __( 'moved a post by %1$s to a new topic: %2$s', 'bbpress-moderation-suite' ), '' . get_post_author( $post->post_id ) . '', '' . esc_html( get_topic_title( $topic ) ) . '' ), 'move_movepost' ); } else { $post = bb_get_post( $_POST['post'] ); $topic = get_topic( $_POST['topicid'] ); if ( !$post || !$topic ) bb_die( __( 'Invalid request', 'bbpress-moderation-suite' ) ); if ( $post->forum_id != $topic->forum_id ) { // We're moving the post out of this forum $bbdb->query( $bbdb->prepare( 'UPDATE `' . $bbdb->forums . '` SET `posts` = `posts` - 1 WHERE `forum_id` = %d', $post->forum_id ) ); // And into this forum $bbdb->query( $bbdb->prepare( 'UPDATE `' . $bbdb->forums . '` SET `posts` = `posts` + 1 WHERE `forum_id` = %d', $topic->forum_id ) ); } // We're moving the post out of its original topic $bbdb->query( $bbdb->prepare( 'UPDATE `' . $bbdb->topics . '` SET `topic_posts` = `topic_posts` - 1 WHERE `topic_id` = %d', $post->topic_id ) ); // And into the new one $bbdb->query( $bbdb->prepare( 'UPDATE `' . $bbdb->topics . '` SET `topic_posts` = `topic_posts` + 1 WHERE `topic_id` = %d', $topic->topic_id ) ); bb_insert_post( array( 'post_id' => $post->post_id, 'topic_id' => $topic->topic_id ) ); if ( function_exists( 'bbmodsuite_modlog_log' ) ) bbmodsuite_modlog_log( sprintf( __( 'moved a post by %1$s to topic: %2$s', 'bbpress-moderation-suite' ), '' . get_post_author( $post->post_id ) . '', '' . esc_html( get_topic_title( $topic->topic_id ) ) . '' ), 'move_movepost' ); } break; case 'merge': bb_check_admin_referer( 'bbmodsuite_move-mergetopic_' . $_POST['topic'] ); $old_topic = get_topic( $_POST['topic'] ); $new_topic = get_topic( $_POST['topicid'] ); // Sanity check... if ( !$old_topic || !$new_topic || $old_topic->topic_id == $new_topic->topic_id ) bb_die( __( 'Invalid request', 'bbpress-moderation-suite' ) ); if ( $post->forum_id != $topic->forum_id ) { // We're moving the posts out of this forum $bbdb->query( $bbdb->prepare( 'UPDATE `' . $bbdb->forums . '` SET `posts` = `posts` - %d WHERE `forum_id` = %d', $old_topic->topic_posts, $old_topic->forum_id ) ); // And into this forum $bbdb->query( $bbdb->prepare( 'UPDATE `' . $bbdb->forums . '` SET `posts` = `posts` + %d WHERE `forum_id` = %d', $old_topic->topic_posts, $new_topic->forum_id ) ); } // Move the post count first $bbdb->query( $bbdb->prepare( 'UPDATE `' . $bbdb->topics . '` SET `topic_posts` = %d WHERE `topic_id` = %d', $old_topic->topic_posts + $new_topic->topic_posts, $new_topic->topic_id ) ); // Then move the posts $bbdb->query( $bbdb->prepare( 'UPDATE `' . $bbdb->posts . '` SET `topic_id` = %d, `forum_id` = %d WHERE `topic_id` = %d', $new_topic->topic_id, $new_topic->forum_id, $old_topic->topic_id ) ); // And finally, delete the old topic $bbdb->query( $bbdb->prepare( 'DELETE FROM `' . $bbdb->topics . '` WHERE `topic_id` = %d', $old_topic->topic_id ) ); // Now that the topic no longer exists, we can remove it from the count $bbdb->query( $bbdb->prepare( 'UPDATE `' . $bbdb->forums . '` SET `topics` = `topics` - 1 WHERE `forum_id` = %d', $old_topic->forum_id ) ); if ( function_exists( 'bbmodsuite_modlog_log' ) ) bbmodsuite_modlog_log( sprintf( __( 'merged %1$d post(s) from %2$s to topic: %3$s', 'bbpress-moderation-suite' ), $old_topic->topic_posts, esc_html( $old_topic->topic_title ), '' . esc_html( get_topic_title( $new_topic->topic_id ) ) . '' ), 'move_mergetopic' ); break; case 'split': bb_check_admin_referer( 'bbmodsuite_move-splittopic_' . $_POST['topic'] ); $old_topic = get_topic( $_POST['topic'] ); // Sanity check... if ( empty( $_POST['post'] ) ) return; if ( !$old_topic ) bb_die( __( 'Invalid request', 'bbpress-moderation-suite' ) ); $posts = array_map( 'intval', array_keys( $_POST['post'] ) ); if ( $bbdb->get_var( 'SELECT COUNT(*) FROM `' . $bbdb->posts . '` WHERE `topic_id` = ' . $old_topic->topic_id . ' AND `post_id` IN (' . implode( ',', $posts ) . ')' ) != count( $posts ) ) bb_die( __( 'Invalid request', 'bbpress-moderation-suite' ) ); $new_topic = get_topic( bb_insert_topic( array( 'topic_title' => $_POST['topicid'], 'forum_id' => $_POST['forum_id'] ) ) ); if ( $old_topic->forum_id != $new_topic->forum_id ) { // We're moving the posts out of this forum $bbdb->query( $bbdb->prepare( 'UPDATE `' . $bbdb->forums . '` SET `posts` = `posts` - %d WHERE `forum_id` = %d', count( $posts ), $old_topic->forum_id ) ); // And into this forum $bbdb->query( $bbdb->prepare( 'UPDATE `' . $bbdb->forums . '` SET `posts` = `posts` + %d WHERE `forum_id` = %d', count( $posts ), $new_topic->forum_id ) ); } // Move the post count first $bbdb->query( $bbdb->prepare( 'UPDATE `' . $bbdb->topics . '` SET `topic_posts` = `topic_posts` - %d WHERE `topic_id` = %d', count( $posts ), $old_topic->topic_id ) ); $bbdb->query( $bbdb->prepare( 'UPDATE `' . $bbdb->topics . '` SET `topic_posts` = %d WHERE `topic_id` = %d', count( $posts ), $new_topic->topic_id ) ); // Then move the posts $bbdb->query( $bbdb->prepare( 'UPDATE `' . $bbdb->posts . '` SET `topic_id` = %d, `forum_id` = %d WHERE `post_id` IN (' . implode( ',', $posts ) . ')', $new_topic->topic_id, $new_topic->forum_id ) ); if ( function_exists( 'bbmodsuite_modlog_log' ) ) bbmodsuite_modlog_log( sprintf( __( 'splitted %1$d post(s) from %2$s to topic: %3$s', 'bbpress-moderation-suite' ), count( $posts ), esc_html( $old_topic->topic_title ), '' . esc_html( get_topic_title( $new_topic->topic_id ) ) . '' ), 'move_splittopic' ); break; } break; case 'ajax-topic': header( 'Content-Type: application/json' ); if ( !bb_verify_nonce( $_POST['_wpnonce'], 'bbmodsuite_move-gettopic_ajax' ) ) exit; $name = stripslashes( $_POST['text'] ); $name = str_replace( array( '%', '?' ), array( '\\%', '\\?' ), substr( $_POST['text'], 0, $_POST['pos'] ) ) . '%' . str_replace( array( '%', '?' ), array( '\\%', '\\?' ), substr( $_POST['text'], $_POST['pos'] ) ); global $bbdb; $results = $bbdb->get_results( $bbdb->prepare( 'SELECT `topic_title`, `topic_slug` FROM `' . $bbdb->topics . '` WHERE ( `topic_slug` LIKE %s OR `topic_title` LIKE %s OR `topic_id` = %d ) AND `topic_id` != %d ORDER BY LENGTH(`topic_slug`) ASC LIMIT 15', $name, $name, $_POST['text'], $_POST['topic'] ) ); $ret = '['; foreach ( $results as $i => $result ) { if ( $i ) $ret .= ','; $ret .= '["' . addslashes( $result->topic_slug ) . '","' . addslashes( $result->topic_title ) . '"]'; } exit( $ret . ']' ); break; case 'move': wp_enqueue_script( 'jquery' ); break; } } add_action( 'bbpress_moderation_suite_move_pre_head', 'bbmodsuite_move_pre_header' ); function bbmodsuite_move_can_view() { return 'moderate'; } function bbmodsuite_move_admin_add() { bb_admin_add_submenu( __( 'Move!', 'bbpress-moderation-suite' ), bbmodsuite_move_can_view(), 'bbpress_moderation_suite_move', 'bbpress_moderation_suite' ); } add_action( 'bb_admin_menu_generator', 'bbmodsuite_move_admin_add' ); function bbmodsuite_move_post_admin( $a, $args ) { if ( bb_current_user_can( 'delete_post', get_post_id( $args['post_id'] ) ) ) { $a['move'] = $args['before_each'] . '' . __( 'Move', 'bbpress-moderation-suite' ) . '' . $args['after_each']; } return $a; } add_filter( 'bb_post_admin', 'bbmodsuite_move_post_admin', 10, 2 ); function bbmodsuite_move_topic_admin( $a, $args = null ) { $defaults = array( 'topic_id' => 0, 'before' => '[', 'after' => ']' ); $args = wp_parse_args( $args, $defaults ); if ( !empty( $a['move'] ) ) { $a['merge'] = $args['before'] . '' . __( 'Merge topic', 'bbpress-moderation-suite' ) . '' . $args['after']; $a['split'] = $args['before'] . '' . __( 'Split topic', 'bbpress-moderation-suite' ) . '' . $args['after']; } return $a; } add_filter( 'bb_topic_admin', 'bbmodsuite_move_topic_admin', 10, 2 ); function bbmodsuite_move_modlog_descriptions( $a ) { $a['move_movepost'] = __( 'Post moving', 'bbpress-moderation-suite' ); $a['move_mergetopic'] = __( 'Topic merging', 'bbpress-moderation-suite' ); $a['move_splittopic'] = __( 'Topic splitting', 'bbpress-moderation-suite' ); } add_filter( 'bbmodsuite_modlog_get_type_description', 'bbmodsuite_move_modlog_descriptions' );