Skip to:
Content

bbPress.org

Ticket #1900: 1900.1.diff

File 1900.1.diff, 28.7 KB (added by jmdodd, 14 years ago)

First pass at move reply.

  • includes/topics/template-tags.php

     
    133133        // Set post_parent back to 0 if originally set to 'any'
    134134        if ( 'any' == $r['post_parent'] )
    135135                $r['post_parent'] = $post_parent = 0;
     136        else
     137                $post_parent = $r['post_parent'];
    136138
    137139        // Limited the number of pages shown
    138140        if ( !empty( $r['max_num_pages'] ) )
  • includes/topics/functions.php

     
    16631663function bbp_split_topic_count( $from_reply_id, $source_topic_id, $destination_topic_id ) {
    16641664
    16651665        // Forum Topic Counts
    1666         bbp_update_forum_topic_count( $destination_topic_id );
     1666        bbp_update_forum_topic_count( bbp_get_topic_forum_id( $destination_topic_id ) );
    16671667
    16681668        // Forum Reply Counts
    1669         bbp_update_forum_reply_count( $destination_topic_id );
     1669        bbp_update_forum_reply_count( bbp_get_topic_forum_id( $destination_topic_id ) );
    16701670
    16711671        // Topic Reply Counts
    16721672        bbp_update_topic_reply_count( $source_topic_id      );
  • includes/replies/template-tags.php

     
    14101410         *  - after: HTML after the links. Defaults to '</span>'
    14111411         *  - sep: Separator. Defaults to ' | '
    14121412         *  - links: Array of the links to display. By default, edit, trash,
    1413          *            spam and topic split links are displayed
     1413         *            spam, reply move, and topic split links are displayed
    14141414         * @uses bbp_is_topic() To check if it's the topic page
    14151415         * @uses bbp_is_reply() To check if it's the reply page
    14161416         * @uses bbp_get_reply_id() To get the reply id
    14171417         * @uses bbp_get_reply_edit_link() To get the reply edit link
    14181418         * @uses bbp_get_reply_trash_link() To get the reply trash link
    14191419         * @uses bbp_get_reply_spam_link() To get the reply spam link
     1420         * @uses bbp_get_reply_move_link() To get the reply move link
    14201421         * @uses bbp_get_topic_split_link() To get the topic split link
    14211422         * @uses current_user_can() To check if the current user can edit or
    14221423         *                           delete the reply
     
    14571458                if ( empty( $r['links'] ) ) {
    14581459                        $r['links'] = array (
    14591460                                'edit'  => bbp_get_reply_edit_link ( $r ),
     1461                                'move'  => bbp_get_reply_move_link ( $r ),
    14601462                                'split' => bbp_get_topic_split_link( $r ),
    14611463                                'trash' => bbp_get_reply_trash_link( $r ),
    14621464                                'spam'  => bbp_get_reply_spam_link ( $r ),
     
    17391741        }
    17401742
    17411743/**
     1744 * Move reply link
     1745 *
     1746 * Output the move link of the reply
     1747 *
     1748 * @param mixed $args See {@link bbp_get_reply_move_link()}
     1749 * @uses bbp_get_reply_move_link() To get the reply move link
     1750 */
     1751function bbp_reply_move_link( $args = '' ) {
     1752        echo bbp_get_reply_move_link( $args );
     1753}
     1754
     1755        /**
     1756         * Get move reply link
     1757         *
     1758         * Return the move link of the reply
     1759         *
     1760         * @param mixed $args This function supports these arguments:
     1761         *  - id: Reply id
     1762         *  - link_before: HTML before the link
     1763         *  - link_after: HTML after the link
     1764         *  - move_text: Move text
     1765         *  - move_title: Move title attribute
     1766         * @uses bbp_get_reply_id() To get the reply id
     1767         * @uses bbp_get_reply() To get the reply
     1768         * @uses current_user_can() To check if the current user can edit the
     1769         *                           topic
     1770         * @uses bbp_get_reply_topic_id() To get the reply topic id
     1771         * @uses bbp_get_reply_edit_url() To get the reply edit url
     1772         * @uses add_query_arg() To add custom args to the url
     1773         * @uses wp_nonce_url() To nonce the url
     1774         * @uses esc_url() To escape the url
     1775         * @uses apply_filters() Calls 'bbp_get_reply_move_link' with the reply
     1776         *                        move link and args
     1777         * @return string Reply move link
     1778         */
     1779        function bbp_get_reply_move_link( $args = '' ) {
     1780
     1781                // Parse arguments against default values
     1782                $r = bbp_parse_args( $args, array(
     1783                        'id'          => 0,
     1784                        'link_before' => '',
     1785                        'link_after'  => '',
     1786                        'split_text'  => __( 'Move',            'bbpress' ),
     1787                        'split_title' => __( 'Move this reply', 'bbpress' )
     1788                ), 'get_reply_move_link' );
     1789
     1790                $reply_id = bbp_get_reply_id( $r['id'] );
     1791                $topic_id = bbp_get_reply_topic_id( $reply_id );
     1792
     1793                if ( empty( $reply_id ) || !current_user_can( 'moderate', $topic_id ) )
     1794                        return;
     1795
     1796                $uri = esc_url(
     1797                        add_query_arg(
     1798                                array(
     1799                                        'action'   => 'move',
     1800                                        'reply_id' => $reply_id
     1801                                ),
     1802                        bbp_get_reply_edit_url( $reply_id )
     1803                ) );
     1804
     1805                $retval = $r['link_before'] . '<a href="' . $uri . '" title="' . esc_attr( $r['split_title'] ) . '">' . esc_html( $r['split_text'] ) . '</a>' . $r['link_after'];
     1806
     1807                return apply_filters( 'bbp_get_reply_move_link', $retval, $r );
     1808        }
     1809
     1810
     1811/**
    17421812 * Split topic link
    17431813 *
    1744  * Output the split link of the topic (but is bundled with each topic)
     1814 * Output the split link of the topic (but is bundled with each reply)
    17451815 *
    17461816 * @since bbPress (r2756)
    17471817 *
     
    17761846         * @uses esc_url() To escape the url
    17771847         * @uses apply_filters() Calls 'bbp_get_topic_split_link' with the topic
    17781848         *                        split link and args
    1779          * @return string Reply spam link
     1849         * @return string Topic split link
    17801850         */
    17811851        function bbp_get_topic_split_link( $args = '' ) {
    17821852
  • includes/replies/functions.php

     
    10101010        return apply_filters( 'bbp_update_reply_revision_log', $revision_log, $r['reply_id'] );
    10111011}
    10121012
     1013/**
     1014 * Move reply handler
     1015 *
     1016 * Handles the front end move reply submission
     1017 *
     1018 * @uses bbPress:errors::add() To log various error messages
     1019 * @uses bbp_get_reply() To get the reply
     1020 * @uses bbp_get_topic() To get the topics
     1021 * @uses bbp_verify_nonce_request() To verify the nonce and check the request
     1022 * @uses current_user_can() To check if the current user can edit the reply and topics
     1023 * @uses bbp_get_topic_post_type() To get the topic post type
     1024 * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
     1025 * @uses do_action() Calls 'bbp_pre_move_reply' with the from reply id, source
     1026 *                    and destination topic ids
     1027 * @uses bbp_get_reply_post_type() To get the reply post type
     1028 * @uses wpdb::prepare() To prepare our sql query
     1029 * @uses wpdb::get_results() To execute the sql query and get results
     1030 * @uses wp_update_post() To update the replies
     1031 * @uses bbp_update_reply_topic_id() To update the reply topic id
     1032 * @uses bbp_get_topic_forum_id() To get the topic forum id
     1033 * @uses bbp_update_reply_forum_id() To update the reply forum id
     1034 * @uses do_action() Calls 'bbp_split_topic_reply' with the reply id and
     1035 *                    destination topic id
     1036 * @uses bbp_update_topic_last_reply_id() To update the topic last reply id
     1037 * @uses bbp_update_topic_last_active_time() To update the topic last active meta
     1038 * @uses do_action() Calls 'bbp_post_split_topic' with the destination and
     1039 *                    source topic ids and source topic's forum id
     1040 * @uses bbp_get_topic_permalink() To get the topic permalink
     1041 * @uses wp_safe_redirect() To redirect to the topic link
     1042 */
     1043function bbp_move_reply_handler() {
     1044
     1045        // Bail if not a POST action
     1046        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     1047                return;
     1048
     1049        // Bail if action is not 'bbp-move-reply'
     1050        if ( empty( $_POST['action'] ) || ( 'bbp-move-reply' !== $_POST['action'] ) )
     1051                return;
     1052
     1053        global $wpdb;
     1054
     1055        // Prevent debug notices
     1056        $move_reply_id = $destination_topic_id = 0;
     1057        $destination_topic_title = '';
     1058        $destination_topic = $move_reply = $source_topic = '';
     1059        $split_option = false;
     1060
     1061        /** Move Reply ***********************************************************/
     1062
     1063        if ( empty( $_POST['bbp_reply_id'] ) )
     1064                bbp_add_error( 'bbp_move_reply_reply_id', __( '<strong>ERROR</strong>: Reply ID to move not found!', 'bbpress' ) );
     1065        else
     1066                $move_reply_id = (int) $_POST['bbp_reply_id'];
     1067
     1068        $move_reply = bbp_get_reply( $move_reply_id );
     1069
     1070        // Reply exists
     1071        if ( empty( $move_reply ) )
     1072                bbp_add_error( 'bbp_mover_reply_r_not_found', __( '<strong>ERROR</strong>: The reply you want to move was not found.', 'bbpress' ) );
     1073
     1074        /** Topic to Move From ***************************************************/
     1075
     1076        // Get the reply's current topic
     1077        $source_topic = bbp_get_topic( $move_reply->post_parent );
     1078
     1079        // No topic
     1080        if ( empty( $source_topic ) )
     1081                bbp_add_error( 'bbp_move_reply_source_not_found', __( '<strong>ERROR</strong>: The topic you want to move from was not found.', 'bbpress' ) );
     1082
     1083        // Nonce check failed
     1084        if ( ! bbp_verify_nonce_request( 'bbp-move-reply_' . $move_reply->ID ) ) {
     1085                bbp_add_error( 'bbp_move_reply_nonce', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress' ) );
     1086                return;
     1087        }
     1088
     1089        // Use cannot edit topic
     1090        if ( !current_user_can( 'edit_topic', $source_topic->ID ) )
     1091                bbp_add_error( 'bbp_move_reply_source_permission', __( '<strong>ERROR</strong>: You do not have the permissions to edit the source topic.', 'bbpress' ) );
     1092
     1093        // How to move
     1094        if ( !empty( $_POST['bbp_reply_move_option'] ) )
     1095                $move_option = (string) trim( $_POST['bbp_reply_move_option'] );
     1096
     1097        // Invalid move option
     1098        if ( empty( $move_option ) || !in_array( $move_option, array( 'existing', 'topic' ) ) ) {
     1099                bbp_add_error( 'bbp_move_reply_option', __( '<strong>ERROR</strong>: You need to choose a valid move option.', 'bbpress' ) );
     1100
     1101        // Valid move option
     1102        } else {
     1103
     1104                // What kind of move
     1105                switch ( $move_option ) {
     1106
     1107                        // Into an existing topic
     1108                        case 'existing' :
     1109
     1110                                // Get destination topic id
     1111                                if ( empty( $_POST['bbp_destination_topic'] ) )
     1112                                        bbp_add_error( 'bbp_move_reply_destination_id', __( '<strong>ERROR</strong>: Destination topic ID not found!', 'bbpress' ) );
     1113                                else
     1114                                        $destination_topic_id = (int) $_POST['bbp_destination_topic'];
     1115
     1116                                // Get the destination topic
     1117                                $destination_topic = bbp_get_topic( $destination_topic_id );
     1118
     1119                                // No destination topic
     1120                                if ( empty( $destination_topic ) )
     1121                                        bbp_add_error( 'bbp_move_reply_destination_not_found', __( '<strong>ERROR</strong>: The topic you want to move to was not found!', 'bbpress' ) );
     1122
     1123                                // User cannot edit the destination topic
     1124                                if ( !current_user_can( 'edit_topic', $destination_topic->ID ) )
     1125                                        bbp_add_error( 'bbp_move_reply_destination_permission', __( '<strong>ERROR</strong>: You do not have the permissions to edit the destination topic!', 'bbpress' ) );
     1126
     1127                                // Reply position
     1128                                $reply_position = bbp_get_topic_reply_count( $destination_topic->ID ) + 1;
     1129
     1130                                // New reply data
     1131                                $postarr = array(
     1132                                        'ID'            => $move_reply->ID,
     1133                                        'post_title'    => sprintf( __( 'Reply To: %s', 'bbpress' ), $destination_topic->post_title ),
     1134                                        'post_name'     => false, // will be automatically generated
     1135                                        'post_parent'   => $destination_topic->ID,
     1136                                        'post_position' => $reply_position,
     1137                                        'guid'          => ''
     1138                                );
     1139
     1140                                // Update the reply
     1141                                wp_update_post( $postarr );
     1142
     1143                                // Adjust reply meta values
     1144                                bbp_update_reply_topic_id( $move_reply->ID, $destination_topic->ID );
     1145                                bbp_update_reply_forum_id( $move_reply->ID, bbp_get_topic_forum_id( $destination_topic->ID ) );
     1146
     1147                                break;
     1148
     1149                        // Move reply to a new topic
     1150                        case 'topic' :
     1151                        default :
     1152
     1153                                // User needs to be able to publish topics
     1154                                if ( current_user_can( 'publish_topics' ) ) {
     1155
     1156                                        // Use the new title that was passed
     1157                                        if ( !empty( $_POST['bbp_reply_move_destination_title'] ) ) {
     1158                                                $destination_topic_title = esc_attr( strip_tags( $_POST['bbp_reply_move_destination_title'] ) );
     1159
     1160                                        // Use the source topic title
     1161                                        } else {
     1162                                                $destination_topic_title = $source_topic->post_title;
     1163                                        }
     1164
     1165                                        // Setup the updated topic parameters
     1166                                        $postarr = array(
     1167                                                'ID'          => $move_reply->ID,
     1168                                                'post_title'  => $destination_topic_title,
     1169                                                'post_name'   => false,
     1170                                                'post_type'   => bbp_get_topic_post_type(),
     1171                                                'post_parent' => $source_topic->post_parent,
     1172                                                'guid'        => ''
     1173                                        );
     1174
     1175                                        // Update the topic
     1176                                        $destination_topic_id = wp_update_post( $postarr );
     1177                                        $destination_topic    = bbp_get_topic( $destination_topic_id );
     1178
     1179                                        // Make sure the new topic knows its a topic
     1180                                        bbp_update_topic_topic_id( $move_reply->ID );
     1181
     1182                                        // Shouldn't happen
     1183                                        if ( false == $destination_topic_id || is_wp_error( $destination_topic_id ) || empty( $destination_topic ) ) {
     1184                                                bbp_add_error( 'bbp_move_reply_destination_reply', __( '<strong>ERROR</strong>: There was a problem converting the reply into the topic. Please try again.', 'bbpress' ) );
     1185                                        }
     1186
     1187                                // User cannot publish posts
     1188                                } else {
     1189                                        bbp_add_error( 'bbp_move_reply_destination_permission', __( '<strong>ERROR</strong>: You do not have the permissions to create new topics. The reply could not be converted into a topic.', 'bbpress' ) );
     1190                                }
     1191
     1192                                break;
     1193                }
     1194        }
     1195
     1196        // Bail if there are errors
     1197        if ( bbp_has_errors() )
     1198                return;
     1199
     1200        /** No Errors - Clean Up **************************************************/
     1201
     1202        // Update counts, etc...
     1203        do_action( 'bbp_pre_move_reply', $move_reply->ID, $source_topic->ID, $destination_topic->ID );
     1204
     1205        /** Date Check ************************************************************/
     1206
     1207        // Check if the destination topic is older than the move reply
     1208        if ( strtotime( $move_reply->post_date ) < strtotime( $destination_topic->post_date ) ) {
     1209
     1210                // Set destination topic post_date to 1 second before from reply
     1211                $destination_post_date = date( 'Y-m-d H:i:s', strtotime( $move_reply->post_date ) - 1 );
     1212
     1213                $postarr = array(
     1214                        'ID'            => $destination_topic_id,
     1215                        'post_date'     => $destination_post_date,
     1216                        'post_date_gmt' => get_gmt_from_date( $destination_post_date )
     1217                );
     1218       
     1219                // Update destination topic
     1220                wp_update_post( $postarr );
     1221        }
     1222       
     1223        // Set the last reply ID and freshness to the move_reply
     1224        $last_reply_id = $move_reply->ID;
     1225        $freshness     = $move_reply->post_date;
     1226       
     1227        // It is a new topic and we need to set some default metas to make
     1228        // the topic display in bbp_has_topics() list
     1229        if ( 'topic' == $move_option ) {
     1230                bbp_update_topic_last_reply_id   ( $destination_topic->ID, $last_reply_id );
     1231                bbp_update_topic_last_active_id  ( $destination_topic->ID, $last_reply_id );
     1232                bbp_update_topic_last_active_time( $destination_topic->ID, $freshness     );
     1233
     1234        // Otherwise update the existing destination topic
     1235        } else {
     1236                bbp_update_topic_last_reply_id   ( $destination_topic->ID );
     1237                bbp_update_topic_last_active_id  ( $destination_topic->ID );
     1238                bbp_update_topic_last_active_time( $destination_topic->ID );
     1239        }
     1240
     1241        // Update source topic ID last active
     1242        bbp_update_topic_last_reply_id   ( $source_topic->ID );
     1243        bbp_update_topic_last_active_id  ( $source_topic->ID );
     1244        bbp_update_topic_last_active_time( $source_topic->ID );
     1245       
     1246        /** Successful Move ******************************************************/
     1247
     1248        // Update counts, etc...
     1249        do_action( 'bbp_post_move_reply', $move_reply->ID, $source_topic->ID, $destination_topic->ID );
     1250
     1251        // Redirect back to the topic
     1252        wp_safe_redirect( bbp_get_topic_permalink( $destination_topic->ID ) );
     1253
     1254        // For good measure
     1255        exit();
     1256}
     1257
     1258/**
     1259 * Fix counts on reply move
     1260 *
     1261 * When a reply is moved, update the counts of source and destination topic
     1262 * and their forums.
     1263 *
     1264 * @param int $move_reply_id Move reply id
     1265 * @param int $source_topic_id Source topic id
     1266 * @param int $destination_topic_id Destination topic id
     1267 * @uses bbp_update_forum_topic_count() To update the forum topic counts
     1268 * @uses bbp_update_forum_reply_count() To update the forum reply counts
     1269 * @uses bbp_update_topic_reply_count() To update the topic reply counts
     1270 * @uses bbp_update_topic_voice_count() To update the topic voice counts
     1271 * @uses bbp_update_topic_reply_count_hidden() To update the topic hidden reply
     1272 *                                              count
     1273 * @uses do_action() Calls 'bbp_move_reply_count' with the move reply id,
     1274 *                    source topic id & destination topic id
     1275 */
     1276function bbp_move_reply_count( $move_reply_id, $source_topic_id, $destination_topic_id ) {
     1277
     1278        // Forum topic counts
     1279        bbp_update_forum_topic_count( bbp_get_topic_forum_id( $destination_topic_id ) );
     1280
     1281        // Forum reply counts
     1282        bbp_update_forum_reply_count( bbp_get_topic_forum_id( $destination_topic_id ) );
     1283
     1284        // Topic reply counts
     1285        bbp_update_topic_reply_count( $source_topic_id      );
     1286        bbp_update_topic_reply_count( $destination_topic_id );
     1287
     1288        // Topic hidden reply counts
     1289        bbp_update_topic_reply_count_hidden( $source_topic_id      );
     1290        bbp_update_topic_reply_count_hidden( $destination_topic_id );
     1291
     1292        // Topic voice counts
     1293        bbp_update_topic_voice_count( $source_topic_id      );
     1294        bbp_update_topic_voice_count( $destination_topic_id );
     1295
     1296        do_action( 'bbp_move_reply_count', $move_reply_id, $source_topic_id, $destination_topic_id );
     1297}
     1298
    10131299/** Reply Actions *************************************************************/
    10141300
    10151301/**
  • includes/common/template-tags.php

     
    479479}
    480480
    481481/**
     482 * Check if current page is a reply move page
     483 *
     484 * @uses bbp_is_reply_move() To check if it's a reply move page
     485 * @return bool True if it's the reply move page, false if not
     486 */
     487function bbp_is_reply_move() {
     488
     489        // Assume false
     490        $retval = false;
     491
     492        // Check reply edit and GET params
     493        if ( bbp_is_reply_edit() && !empty( $_GET['action'] ) && ( 'move' == $_GET['action'] ) )
     494                $retval = true;
     495
     496        return (bool) apply_filters( 'bbp_is_reply_move', $retval );
     497}
     498
     499/**
    482500 * Viewing a single reply
    483501 *
    484502 * @since bbPress (r3344)
     
    800818 * @uses bbp_is_topic_split()
    801819 * @uses bbp_is_single_reply()
    802820 * @uses bbp_is_reply_edit()
    803  * @uses bbp_is_reply_edit()
     821 * @uses bbp_is_reply_move()
    804822 * @uses bbp_is_single_view()
    805823 * @uses bbp_is_single_user_edit()
    806824 * @uses bbp_is_single_user()
     
    865883
    866884        if ( bbp_is_reply_edit() )
    867885                $bbp_classes[] = bbp_get_reply_post_type() . '-edit';
     886               
     887        if ( bbp_is_reply_move() )
     888                $bbp_classes[] = bbp_get_reply_post_type() . '-move';
    868889
    869890        if ( bbp_is_single_view() )
    870891                $bbp_classes[] = 'bbp-view';
     
    937958 * @uses bbp_is_topic_split()
    938959 * @uses bbp_is_single_reply()
    939960 * @uses bbp_is_reply_edit()
    940  * @uses bbp_is_reply_edit()
     961 * @uses bbp_is_reply_move()
    941962 * @uses bbp_is_single_view()
    942963 * @uses bbp_is_single_user_edit()
    943964 * @uses bbp_is_single_user()
     
    9911012        elseif ( bbp_is_reply_edit() )
    9921013                $retval = true;
    9931014
     1015        elseif ( bbp_is_reply_move() )
     1016                $retval = true;
     1017
    9941018        elseif ( bbp_is_single_view() )
    9951019                $retval = true;
    9961020
     
    15501574 *
    15511575 * @since bbPress (r2756)
    15521576 *
    1553  * @uses wp_nonce_field() To generete a hidden nonce field
     1577 * @uses wp_nonce_field() To generate a hidden nonce field
    15541578 */
    15551579function bbp_split_topic_form_fields() {
    15561580?>
     
    15621586}
    15631587
    15641588/**
     1589 * Move reply form fields
     1590 *
     1591 * Output the required hidden fields when moving a reply
     1592 *
     1593 * @uses wp_nonce_field() To generate a hidden nonce field
     1594 */
     1595function bbp_move_reply_form_fields() {
     1596?>
     1597
     1598        <input type="hidden" name="action"       id="bbp_post_action" value="bbp-move-reply" />
     1599        <input type="hidden" name="bbp_reply_id" id="bbp_reply_id"    value="<?php echo absint( $_GET['reply_id'] ); ?>" />
     1600
     1601        <?php wp_nonce_field( 'bbp-move-reply_' . bbp_get_reply_id() );
     1602}
     1603
     1604/**
    15651605 * Output a textarea or TinyMCE if enabled
    15661606 *
    15671607 * @since bbPress (r3586)
  • includes/core/template-loader.php

     
    3838 * @uses bbp_get_topic_split_template() To get topic split template
    3939 * @uses bbp_is_topic_edit() To check if page is topic edit
    4040 * @uses bbp_get_topic_edit_template() To get topic edit template
     41 * @uses bbp_is_reply_move() To check if page is reply move
     42 * @uses bbp_get_reply_move_template() To get reply move template
    4143 * @uses bbp_is_reply_edit() To check if page is reply edit
    4244 * @uses bbp_get_reply_edit_template() To get reply edit template
    4345 * @uses bbp_set_theme_compat_template() To set the global theme compat template
     
    8587        // Topic Archive
    8688        elseif ( bbp_is_topic_archive()    && ( $new_template = bbp_get_topic_archive_template()    ) ) :
    8789
     90        // Reply move
     91        elseif ( bbp_is_reply_move()       && ( $new_template = bbp_get_reply_move_template()       ) ) :
     92
    8893        // Editing a reply
    8994        elseif ( bbp_is_reply_edit()       && ( $new_template = bbp_get_reply_edit_template()       ) ) :
    9095
     
    406411}
    407412
    408413/**
     414 * Get the reply move template
     415 *
     416 * @uses bbp_get_reply_post_type()
     417 * @uses bbp_get_query_template()
     418 * @return string Path to template file
     419 */
     420function bbp_get_reply_move_template() {
     421        $templates = array(
     422                'single-' . bbp_get_reply_post_type() . '-move.php', // Reply move
     423        );
     424        return bbp_get_query_template( 'reply_move', $templates );
     425}
     426
     427/**
    409428 * Get the topic template
    410429 *
    411430 * @since bbPress (r3311)
  • includes/core/actions.php

     
    203203add_action( 'bbp_merged_topic',     'bbp_merge_topic_count', 1, 3 );
    204204add_action( 'bbp_post_split_topic', 'bbp_split_topic_count', 1, 3 );
    205205
     206// Move Reply
     207add_action( 'bbp_post_move_reply', 'bbp_move_reply_count', 1, 3 );
     208
    206209// Before Delete/Trash/Untrash Topic
    207210add_action( 'wp_trash_post', 'bbp_trash_topic'   );
    208211add_action( 'trash_post',    'bbp_trash_topic'   );
     
    281284add_action( 'bbp_template_redirect', 'bbp_merge_topic_handler',     1  );
    282285add_action( 'bbp_template_redirect', 'bbp_split_topic_handler',     1  );
    283286add_action( 'bbp_template_redirect', 'bbp_toggle_topic_handler',    1  );
     287add_action( 'bbp_template_redirect', 'bbp_move_reply_handler',      1  );
    284288add_action( 'bbp_template_redirect', 'bbp_toggle_reply_handler',    1  );
    285289add_action( 'bbp_template_redirect', 'bbp_favorites_handler',       1  );
    286290add_action( 'bbp_template_redirect', 'bbp_subscriptions_handler',   1  );
  • includes/core/theme-compat.php

     
    443443 * @uses bbp_get_topic_split_template() To get topic split template
    444444 * @uses bbp_is_topic_edit() To check if page is topic edit
    445445 * @uses bbp_get_topic_edit_template() To get topic edit template
     446 * @uses bbp_is_reply_move() To check if page is reply move
     447 * @uses bbp_get_reply_move_template() To get reply move template
    446448 * @uses bbp_is_reply_edit() To check if page is reply edit
    447449 * @uses bbp_get_reply_edit_template() To get reply edit template
    448450 * @uses bbp_set_theme_compat_template() To set the global theme compat template
     
    793795
    794796        // Reply Edit
    795797        } elseif ( bbp_is_reply_edit() ) {
    796                 $new_content = $bbp->shortcodes->display_reply_form();
     798       
     799                // Move
     800                if ( bbp_is_reply_move() ) {
     801                        ob_start();
    797802
     803                        bbp_get_template_part( 'form', 'reply-move' );
     804
     805                        $new_content = ob_get_contents();
     806
     807                        ob_end_clean();
     808       
     809                // Edit
     810                } else {
     811                        $new_content = $bbp->shortcodes->display_reply_form();
     812                }
     813
    798814        // Single Reply
    799815        } elseif ( bbp_is_single_reply() ) {
    800816                $new_content = $bbp->shortcodes->display_reply( array( 'id' => get_the_ID() ) );
  • includes/core/filters.php

     
    182182add_filter( 'bbp_get_topicmerge_template',   'bbp_add_template_locations' );
    183183add_filter( 'bbp_get_topictag_template',     'bbp_add_template_locations' );
    184184add_filter( 'bbp_get_topictagedit_template', 'bbp_add_template_locations' );
     185add_filter( 'bbp_get_replymove_template',    'bbp_add_template_locations' );
    185186
    186187/**
    187188 * Add filters to anonymous post author data
  • templates/default/bbpress/form-reply-move.php

     
     1<?php
     2
     3/**
     4 * Move Reply
     5 *
     6 * @package bbPress
     7 * @subpackage Theme
     8 */
     9
     10?>
     11
     12<div id="bbpress-forums">
     13
     14        <?php bbp_breadcrumb(); ?>
     15
     16        <?php if ( is_user_logged_in() && current_user_can( 'edit_topic', bbp_get_topic_id() ) ) : ?>
     17
     18                <div id="move-reply-<?php bbp_topic_id(); ?>" class="bbp-reply-move">
     19
     20                        <form id="move_reply" name="move_reply" method="post" action="<?php the_permalink(); ?>">
     21
     22                                <fieldset class="bbp-form">
     23
     24                                        <legend><?php printf( __( 'Move reply "%s"', 'bbpress' ), bbp_get_reply_title() ); ?></legend>
     25
     26                                        <div>
     27
     28                                                <div class="bbp-template-notice info">
     29                                                        <p><?php _e( 'When you move a reply, you can choose to use that reply as a new topic with a new title, or merge it into an existing topic.', 'bbpress' ); ?></p>
     30                                                </div>
     31
     32                                                <div class="bbp-template-notice">
     33                                                        <p><?php _e( 'If you use the existing topic option, replies within both topics will be merged chronologically. The order of the merged reply is based on the time and date it was posted.', 'bbpress' ); ?></p>
     34                                                </div>
     35
     36                                                <fieldset class="bbp-form">
     37                                                        <legend><?php _e( 'Move Method', 'bbpress' ); ?></legend>
     38
     39                                                        <div>
     40                                                                <input name="bbp_reply_move_option" id="bbp_reply_move_option_reply" type="radio" checked="checked" value="topic" tabindex="<?php bbp_tab_index(); ?>" />
     41                                                                <label for="bbp_reply_move_option_reply"><?php printf( __( 'New topic in <strong>%s</strong> titled:', 'bbpress' ), bbp_get_forum_title( bbp_get_reply_forum_id( bbp_get_reply_id() ) ) ); ?></label>
     42                                                                <input type="text" id="bbp_reply_move_destination_title" value="<?php printf( __( 'Moved: %s', 'bbpress' ), bbp_get_reply_title() ); ?>" tabindex="<?php bbp_tab_index(); ?>" size="35" name="bbp_reply_move_destination_title" />
     43                                                        </div>
     44
     45                                                        <?php if ( bbp_has_topics( array( 'show_stickies' => false, 'post_parent' => bbp_get_reply_forum_id( bbp_get_reply_id() ), 'post__not_in' => array( bbp_get_reply_topic_id( bbp_get_reply_id() ) ) ) ) ) : ?>
     46
     47                                                                <div>
     48                                                                        <input name="bbp_reply_move_option" id="bbp_reply_move_option_existing" type="radio" value="existing" tabindex="<?php bbp_tab_index(); ?>" />
     49                                                                        <label for="bbp_reply_move_option_existing"><?php _e( 'Use an existing topic in this forum:', 'bbpress' ); ?></label>
     50
     51                                                                        <?php
     52                                                                                bbp_dropdown( array(
     53                                                                                        'post_type'   => bbp_get_topic_post_type(),
     54                                                                                        'post_parent' => bbp_get_reply_forum_id( bbp_get_reply_id() ),
     55                                                                                        'selected'    => -1,
     56                                                                                        'exclude'     => bbp_get_reply_topic_id( bbp_get_reply_id() ),
     57                                                                                        'select_id'   => 'bbp_destination_topic',
     58                                                                                        'none_found'  => __( 'No other topics found!', 'bbpress' )
     59                                                                                ) );
     60                                                                        ?>
     61
     62                                                                </div>
     63
     64                                                        <?php endif; ?>
     65
     66                                                </fieldset>
     67
     68                                                <div class="bbp-template-notice error">
     69                                                        <p><?php _e( '<strong>WARNING:</strong> This process cannot be undone.', 'bbpress' ); ?></p>
     70                                                </div>
     71
     72                                                <div class="bbp-submit-wrapper">
     73                                                        <button type="submit" tabindex="<?php bbp_tab_index(); ?>" id="bbp_move_reply_submit" name="bbp_move_reply_submit" class="button submit"><?php _e( 'Submit', 'bbpress' ); ?></button>
     74                                                </div>
     75                                        </div>
     76
     77                                        <?php bbp_move_reply_form_fields(); ?>
     78
     79                                </fieldset>
     80                        </form>
     81                </div>
     82
     83        <?php else : ?>
     84
     85                <div id="no-reply-<?php bbp_reply_id(); ?>" class="bbp-no-reply">
     86                        <div class="entry-content"><?php is_user_logged_in() ? _e( 'You do not have the permissions to edit this reply!', 'bbpress' ) : _e( 'You cannot edit this reply.', 'bbpress' ); ?></div>
     87                </div>
     88
     89        <?php endif; ?>
     90
     91</div>
  • templates/default/extras/single-reply-move.php

     
     1<?php
     2
     3/**
     4 * Move reply page
     5 *
     6 * @package bbPress
     7 * @subpackage Theme
     8 */
     9
     10get_header(); ?>
     11
     12        <?php do_action( 'bbp_before_main_content' ); ?>
     13
     14        <?php do_action( 'bbp_template_notices' ); ?>
     15
     16        <?php while ( have_posts() ) : the_post(); ?>
     17
     18                <div id="bbp-edit-page" class="bbp-edit-page">
     19                        <h1 class="entry-title"><?php the_title(); ?></h1>
     20                        <div class="entry-content">
     21
     22                                <?php bbp_get_template_part( 'form', 'reply-move' ); ?>
     23
     24                        </div>
     25                </div><!-- #bbp-edit-page -->
     26
     27        <?php endwhile; ?>
     28
     29        <?php do_action( 'bbp_after_main_content' ); ?>
     30
     31<?php get_sidebar(); ?>
     32<?php get_footer(); ?>