| | 1 | <?php |
| | 2 | |
| | 3 | /** |
| | 4 | * phpBB3 Importer |
| | 5 | * |
| | 6 | * Helps in converting your phpBB installation into bbPress |
| | 7 | * |
| | 8 | * @package bbPress |
| | 9 | * @subpackage Importer |
| | 10 | * |
| | 11 | * @todo Docs |
| | 12 | * @todo Role Mapping Options |
| | 13 | */ |
| | 14 | class phpBB_Importer { |
| | 15 | |
| | 16 | /** |
| | 17 | * @var string Path to phpBB3 configuration file (config.php) |
| | 18 | */ |
| | 19 | var $config = ''; |
| | 20 | |
| | 21 | var $db = null; |
| | 22 | |
| | 23 | function init_db() { |
| | 24 | require_once $this->config; |
| | 25 | |
| | 26 | $this->db = new wpdb( $dbuser, $dbpasswd, $dbname, $dbport ? $dbhost . ':' . $dbport : $dbhost ); |
| | 27 | $this->db->tables = array( 'acl_groups', 'acl_options', 'acl_roles', 'acl_roles_data', 'acl_users', |
| | 28 | 'attachments', 'banlist', 'bbcodes', 'bookmarks', 'bots', 'config', 'confirm', 'disallow', 'drafts', 'extensions', |
| | 29 | 'extension_groups', 'forums', 'forums_access', 'forums_track', 'forums_watch', 'groups', 'icons', 'lang', 'log', |
| | 30 | 'moderator_cache', 'modules', 'poll_options', 'poll_votes', 'posts', 'privmsgs', 'privmsgs_folder', 'privmsgs_rules', |
| | 31 | 'privmsgs_to', 'profile_fields', 'profile_fields_data', 'profile_fields_lang', 'profile_lang', 'ranks', 'reports', |
| | 32 | 'reports_reasons', 'search_results', 'search_wordlist', 'search_wordmatch', 'sessions', 'sessions_keys', 'sitelist', |
| | 33 | 'smilies', 'styles', 'styles_imageset', 'styles_imageset_data', 'styles_template', 'styles_template_data', 'styles_theme', |
| | 34 | 'topics', 'topics_posted', 'topics_track', 'topics_watch', 'users', 'user_group', 'warnings', 'words', 'zebra' ); |
| | 35 | $this->db->set_prefix( $table_prefix ); |
| | 36 | } |
| | 37 | |
| | 38 | function header() { ?> |
| | 39 | |
| | 40 | <div class="wrap"> |
| | 41 | |
| | 42 | <?php screen_icon(); ?> |
| | 43 | |
| | 44 | <h2><?php _e( 'phpBB3 Importer', 'bbpress' ); ?></h2> |
| | 45 | |
| | 46 | <?php |
| | 47 | } |
| | 48 | |
| | 49 | /** |
| | 50 | * Output an error message with a button to try again. |
| | 51 | * |
| | 52 | * @param type $error |
| | 53 | * @param type $step |
| | 54 | */ |
| | 55 | function throw_error( $error, $step ) { |
| | 56 | echo '<p><strong>' . $error->get_error_message() . '</strong></p>'; |
| | 57 | echo $this->next_step( $step, __( 'Try Again', 'bbpress' ) ); |
| | 58 | } |
| | 59 | |
| | 60 | /** |
| | 61 | * Returns the HTML for a link to the next page |
| | 62 | * |
| | 63 | * @param type $next_step |
| | 64 | * @param type $label |
| | 65 | * @param type $id |
| | 66 | * @return string |
| | 67 | */ |
| | 68 | function next_step( $next_step, $label, $id = 'phpbb-import-next-form' ) { |
| | 69 | $str = '<form action="admin.php?import=phpbb" method="post" id="' . $id . '">'; |
| | 70 | $str .= wp_nonce_field( 'bbp-phpbb-import', '_wpnonce', true, false ); |
| | 71 | $str .= wp_referer_field( false ); |
| | 72 | $str .= '<input type="hidden" name="step" id="step" value="' . esc_attr( $next_step ) . '" />'; |
| | 73 | $str .= '<p><input type="submit" class="button" value="' . esc_attr( $label ) . '" /> <span id="auto-message"></span></p>'; |
| | 74 | $str .= '</form>'; |
| | 75 | |
| | 76 | return $str; |
| | 77 | } |
| | 78 | |
| | 79 | /** |
| | 80 | * Footer |
| | 81 | */ |
| | 82 | function footer() { ?> |
| | 83 | |
| | 84 | </div> |
| | 85 | |
| | 86 | <?php |
| | 87 | } |
| | 88 | |
| | 89 | /** |
| | 90 | * Dispatch |
| | 91 | */ |
| | 92 | function dispatch() { |
| | 93 | if ( empty( $_REQUEST['step'] ) ) |
| | 94 | $step = 0; |
| | 95 | else |
| | 96 | $step = (int) $_REQUEST['step']; |
| | 97 | |
| | 98 | $this->header(); |
| | 99 | |
| | 100 | switch ( $step ) { |
| | 101 | case -1 : |
| | 102 | $this->cleanup(); |
| | 103 | // Intentional no break |
| | 104 | |
| | 105 | case 0 : |
| | 106 | $this->greet(); |
| | 107 | break; |
| | 108 | |
| | 109 | case 1 : |
| | 110 | case 2 : |
| | 111 | case 3 : |
| | 112 | |
| | 113 | check_admin_referer( 'bbp-phpbb-import' ); |
| | 114 | $result = $this->{ 'step' . $step }(); |
| | 115 | |
| | 116 | break; |
| | 117 | } |
| | 118 | |
| | 119 | $this->footer(); |
| | 120 | } |
| | 121 | |
| | 122 | /** |
| | 123 | * Greet message |
| | 124 | */ |
| | 125 | function greet() { |
| | 126 | global $wpdb, $bbdb; ?> |
| | 127 | |
| | 128 | <div class="narrow"> |
| | 129 | |
| | 130 | <form action="admin.php?import=phpbb" method="post"> |
| | 131 | |
| | 132 | <?php wp_nonce_field( 'bbp-phpbb-import' ); ?> |
| | 133 | |
| | 134 | <?php if ( get_option( '_bbp_import_phpbb_path' ) ) : ?> |
| | 135 | |
| | 136 | <input type="hidden" name="step" value="<?php echo esc_attr( get_option( '_bbp_import_phpbb_step' ) ); ?>" /> |
| | 137 | |
| | 138 | <p><?php _e( 'It looks like you attempted to convert your phpBB installation previously and got interrupted.', 'bbpress' ); ?></p> |
| | 139 | |
| | 140 | <p class="submit"> |
| | 141 | <a href="<?php echo esc_url( add_query_arg( array( 'import' => 'phpbb', 'step' => '-1', '_wpnonce' => wp_create_nonce( 'bbp-phpbb-import' ), '_wp_http_referer' => esc_attr( $_SERVER['REQUEST_URI'] ) ) ) ); ?>" class="button"><?php _e( 'Cancel & start a new import', 'bbpress' ); ?></a> |
| | 142 | <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Continue previous import', 'bbpress' ); ?>" /> |
| | 143 | </p> |
| | 144 | |
| | 145 | <?php else : ?> |
| | 146 | |
| | 147 | <input type="hidden" name="_bbp_import_phpbb_path" value="true" /> |
| | 148 | |
| | 149 | <p><?php _e( 'This importer allows you to convert your phpBB3 installation into bbPress.', 'bbpress' ); ?></p> |
| | 150 | |
| | 151 | <h3><?php _e( 'Instructions', 'bbpress' ); ?></h3> |
| | 152 | <ol> |
| | 153 | <li><?php printf( __( 'Create a <a href="%s">backup</a> of your database and files. If the import process is interrupted for any reason, restore from that backup and re-run the import.', 'bbpress' ), 'http://codex.wordpress.org/WordPress_Backups' ); ?></li> |
| | 154 | <li><?php _e( 'Seriously... Go back everything up, and don\'t come back until that\'s done. If things go awry, it\'s possible this importer will not be able to complete and your forums will be lost in limbo forever. This is serious business. No, we\'re not kidding.', 'bbpress' ); ?></li> |
| | 155 | <li><?php _e( 'To reduce memory overhead and avoid possible conflicts please:', 'bbpress' ); ?> |
| | 156 | <ol> |
| | 157 | <li> |
| | 158 | <?php _e( 'Disable all plugins (except bbPress) on both your WordPress and phpBB3 installations.', 'bbpress' ); ?> |
| | 159 | </li> |
| | 160 | <li> |
| | 161 | <?php _e( 'Switch to a default WordPress theme.', 'bbpress' ); ?> |
| | 162 | </li> |
| | 163 | </ol> |
| | 164 | </li> |
| | 165 | <li><?php _e( 'Notes on compatibility:', 'bbpress' ); ?> |
| | 166 | <ol> |
| | 167 | <li> |
| | 168 | <?php _e( 'No plugins can currently be converted.', 'bbpress' ); ?> |
| | 169 | </li> |
| | 170 | </ol> |
| | 171 | </li> |
| | 172 | <li><?php _e( 'This converter can be a drag on large forums with lots of existing topics and replies. If possible, do this import in a safe place (like a local installation.)', 'bbpress' ); ?></li> |
| | 173 | </ol> |
| | 174 | |
| | 175 | <h3><?php _e( 'Configuration', 'bbpress' ); ?></h3> |
| | 176 | <p><?php _e( 'Enter the full path to your phpBB configuration file i.e. <code>config.php</code>:', 'bbpress' ); ?></p> |
| | 177 | |
| | 178 | <table class="form-table"> |
| | 179 | <tr> |
| | 180 | <th scope="row"><label for="_bbp_import_phpbb_path"><?php _e( 'phpBB Path:', 'bbpress' ); ?></label></th> |
| | 181 | <td><input type="text" name="_bbp_import_phpbb_path" id="_bbp_import_phpbb_path" class="regular-text" value="<?php echo untrailingslashit( ABSPATH ) . DIRECTORY_SEPARATOR . 'forums' . DIRECTORY_SEPARATOR . 'config.php'; ?>" /></td> |
| | 182 | </tr> |
| | 183 | </table> |
| | 184 | |
| | 185 | <p class="submit"> |
| | 186 | <input type="hidden" name="step" value="1" /> |
| | 187 | <input type="submit" class="button" value="<?php esc_attr_e( 'Proceed', 'bbpress' ); ?>" /> |
| | 188 | </p> |
| | 189 | |
| | 190 | <?php endif; ?> |
| | 191 | |
| | 192 | </form> |
| | 193 | |
| | 194 | </div> |
| | 195 | <?php |
| | 196 | } |
| | 197 | |
| | 198 | /** |
| | 199 | * Cleanups all the options used by the importer |
| | 200 | */ |
| | 201 | function cleanup() { |
| | 202 | global $wpdb; |
| | 203 | |
| | 204 | delete_option( '_bbp_import_phpbb_path' ); |
| | 205 | delete_option( '_bbp_import_phpbb_step' ); |
| | 206 | |
| | 207 | $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = '_bbp_phpbb_user'" ); |
| | 208 | |
| | 209 | do_action( 'import_end' ); |
| | 210 | } |
| | 211 | |
| | 212 | /** |
| | 213 | * Technically the first half of step 1, this is separated to allow for AJAX |
| | 214 | * calls. Sets up some variables and options and confirms authentication. |
| | 215 | * |
| | 216 | * @return type |
| | 217 | */ |
| | 218 | function setup() { |
| | 219 | |
| | 220 | // Get details from _POST |
| | 221 | if ( !empty( $_POST['_bbp_import_phpbb_path'] ) ) { |
| | 222 | |
| | 223 | // Store details for later |
| | 224 | $this->config = realpath( $_POST['_bbp_import_phpbb_path'] ); |
| | 225 | |
| | 226 | // Update path |
| | 227 | update_option( '_bbp_import_phpbb_path', $this->config ); |
| | 228 | |
| | 229 | // Get details from DB |
| | 230 | } else { |
| | 231 | $this->config = get_option( '_bbp_import_phpbb_path' ); |
| | 232 | } |
| | 233 | |
| | 234 | // No config file found |
| | 235 | if ( empty( $this->config ) ) { ?> |
| | 236 | |
| | 237 | <p><?php _e( 'Please enter the path to your phpBB configuration file - <code>config.php</code>.', 'bbpress' ); ?></p> |
| | 238 | <p><a href="<?php echo esc_url( add_query_arg( array( 'import' => 'phpbb', 'step' => '-1', '_wpnonce' => wp_create_nonce( 'bbp-phpbb-import' ), '_wp_http_referer' => esc_attr( remove_query_arg( 'step', $_SERVER['REQUEST_URI'] ) ) ) ) ); ?>" class="button"><?php _e( 'Go Back', 'bbpress' ); ?></a></p> |
| | 239 | |
| | 240 | <?php |
| | 241 | |
| | 242 | return false; |
| | 243 | } |
| | 244 | |
| | 245 | // Check if the user submitted a directory as the path by mistake |
| | 246 | if ( is_dir( $this->config ) && file_exists( trailingslashit( $this->config ) . 'config.php' ) ) { |
| | 247 | $this->config = trailingslashit( $this->config ) . 'config.php'; |
| | 248 | } |
| | 249 | |
| | 250 | // Check if the file exists |
| | 251 | if ( !file_exists( $this->config ) || is_dir( $this->config ) ) { |
| | 252 | |
| | 253 | delete_option( '_bbp_import_phpbb_path' ); ?> |
| | 254 | |
| | 255 | <p><?php _e( 'phpBB configuration file <code>config.php</code> doesn\'t exist in the path specified! Please check the path and try again.', 'bbpress' ); ?></p> |
| | 256 | <p><a href="<?php echo esc_url( add_query_arg( array( 'import' => 'phpbb', 'step' => '-1', '_wpnonce' => wp_create_nonce( 'bbp-phpbb-import' ), '_wp_http_referer' => esc_attr( remove_query_arg( 'step', $_SERVER['REQUEST_URI'] ) ) ) ) ); ?>" class="button"><?php _e( 'Go Back', 'bbpress' ); ?></a></p> |
| | 257 | |
| | 258 | <?php |
| | 259 | |
| | 260 | return false; |
| | 261 | } |
| | 262 | |
| | 263 | $this->init_db(); |
| | 264 | |
| | 265 | return true; |
| | 266 | } |
| | 267 | |
| | 268 | /** |
| | 269 | * Convert users |
| | 270 | */ |
| | 271 | function step1() { |
| | 272 | |
| | 273 | update_option( '_bbp_import_phpbb_step', 1 ); |
| | 274 | |
| | 275 | // Set time limit to 0 to avoid time out errors |
| | 276 | set_time_limit( 0 ); |
| | 277 | |
| | 278 | if ( is_callable( 'ob_implicit_flush' ) ) |
| | 279 | ob_implicit_flush( true ); |
| | 280 | |
| | 281 | $setup = $this->setup(); |
| | 282 | if ( empty( $setup ) ) { |
| | 283 | return false; |
| | 284 | } elseif ( is_wp_error( $setup ) ) { |
| | 285 | $this->throw_error( $setup, 1 ); |
| | 286 | return false; |
| | 287 | } |
| | 288 | |
| | 289 | $radio = 'user'; |
| | 290 | |
| | 291 | global $wpdb; ?> |
| | 292 | |
| | 293 | <div id="bbpress-import-status"> |
| | 294 | |
| | 295 | <h3><?php _e( 'Importing Users', 'bbpress' ); ?></h3> |
| | 296 | <p><?php _e( 'We’re in the process of migrating your users...', 'bbpress' ); ?></p> |
| | 297 | |
| | 298 | <ol> |
| | 299 | |
| | 300 | <?php |
| | 301 | $have_more = true; |
| | 302 | $page = 0; |
| | 303 | while ( $have_more ) { |
| | 304 | $users = $this->db->get_results( $this->db->prepare( |
| | 305 | "SELECT user_id, user_regdate, username, user_email, user_password, |
| | 306 | user_aim, user_yim, user_jabber, user_website |
| | 307 | FROM {$this->db->users} WHERE (user_id = 2 OR user_id > 53) |
| | 308 | ORDER BY user_id ASC LIMIT %d, 200", $page * 200 ) ); |
| | 309 | |
| | 310 | echo '<li>'; |
| | 311 | printf( __( 'Importing users #%1$d to #%2$d...', 'bbpress' ), $page * 200 + 1, $page * 200 + count( $users ) ); |
| | 312 | |
| | 313 | foreach ( $users as $user ) { |
| | 314 | if ( !$id = email_exists( $user->user_email ) ) |
| | 315 | $id = wp_insert_user( array( |
| | 316 | 'user_login' => $user->username, |
| | 317 | 'user_pass' => $user->user_password, |
| | 318 | 'user_url' => $user->user_website, |
| | 319 | 'user_registered' => date( 'Y-m-d H:i:s', $user->user_regdate ), |
| | 320 | 'user_email' => $user->user_email, |
| | 321 | 'jabber' => $user->user_jabber, |
| | 322 | 'yim' => $user->user_yim, |
| | 323 | 'aim' => $user->user_aim |
| | 324 | ) ); |
| | 325 | |
| | 326 | add_user_meta( $id, '_bbp_phpbb_user', $user->user_id, true ); |
| | 327 | } |
| | 328 | |
| | 329 | _e( '... Done!', 'bbpress' ); |
| | 330 | echo '</li>'; |
| | 331 | |
| | 332 | if ( count( $users ) < 200 ) |
| | 333 | $have_more = false; |
| | 334 | $page++; |
| | 335 | } |
| | 336 | ?> |
| | 337 | |
| | 338 | </ol> |
| | 339 | |
| | 340 | <p><?php _e( 'Your users have all been imported, but wait – there’s more! Now we need to import your forums, topics and posts!', 'bbpress' ); ?></p> |
| | 341 | <?php |
| | 342 | |
| | 343 | echo $this->next_step( 2, __( 'Import forums, topics and posts »', 'bbpress' ) ); ?> |
| | 344 | |
| | 345 | </div> |
| | 346 | |
| | 347 | <?php |
| | 348 | } |
| | 349 | |
| | 350 | /** |
| | 351 | * Import forums, topics and posts |
| | 352 | */ |
| | 353 | function step2() { |
| | 354 | do_action( 'import_start' ); |
| | 355 | |
| | 356 | set_time_limit( 0 ); |
| | 357 | update_option( '_bbp_import_phpbb_step', 2 ); |
| | 358 | |
| | 359 | $setup = $this->setup(); |
| | 360 | if ( empty( $setup ) ) { |
| | 361 | return false; |
| | 362 | } elseif ( is_wp_error( $setup ) ) { |
| | 363 | $this->throw_error( $setup, 3 ); |
| | 364 | return false; |
| | 365 | } |
| | 366 | |
| | 367 | global $wpdb, $bbp; ?> |
| | 368 | |
| | 369 | <div id="bbpress-import-status"> |
| | 370 | |
| | 371 | <h3><?php _e( 'Importing Forums, Topics And Posts', 'bbpress' ); ?></h3> |
| | 372 | <p><?php _e( 'We’re importing your phpBB forums, topics and replies...', 'bbpress' ); ?></p> |
| | 373 | |
| | 374 | <ol> |
| | 375 | |
| | 376 | <?php |
| | 377 | |
| | 378 | if ( !$forums = $this->db->get_results( "SELECT forum_id, parent_id, forum_name, forum_desc, forum_password, forum_type, left_id FROM {$this->db->forums} WHERE forum_type IN (0, 1)" ) ) { |
| | 379 | echo "<li><strong>" . __( 'No forums were found!', 'bbpress' ) . "</strong></li></ol>\n"; |
| | 380 | return; |
| | 381 | } |
| | 382 | |
| | 383 | echo "<li>" . sprintf( __( 'Total number of forums: %s', 'bbpress' ), count( $forums ) ) . "</li>\n"; |
| | 384 | |
| | 385 | $forum_map = array(); |
| | 386 | $user_map = array(); |
| | 387 | |
| | 388 | $users = $wpdb->get_results( "SELECT user_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = '_bbp_phpbb_user'" ); |
| | 389 | foreach ( $users as $user ) { |
| | 390 | $user_map[$user->meta_value] = $user->user_id; |
| | 391 | } |
| | 392 | unset( $users ); // Allow PHP to free up some memory |
| | 393 | |
| | 394 | foreach ( (array) $forums as $forum ) { |
| | 395 | echo "<li>" . sprintf( __( 'Processing forum #%1$s (%2$s)', 'bbpress' ), $forum->forum_id, esc_html( $forum->forum_name ) ) . "\n<ul>\n"; |
| | 396 | |
| | 397 | // Insert the forum and add it to the map. |
| | 398 | $inserted_forum = wp_insert_post( array( |
| | 399 | 'post_author' => get_current_user_id(), |
| | 400 | 'post_content' => $forum->forum_desc, |
| | 401 | 'post_title' => $forum->forum_name, |
| | 402 | 'post_name' => sanitize_title_with_dashes( $forum->forum_name ), |
| | 403 | 'post_excerpt' => '', |
| | 404 | 'post_status' => 'publish', |
| | 405 | 'comment_status' => 'closed', |
| | 406 | 'ping_status' => 'closed', |
| | 407 | 'post_parent' => !empty( $forum->parent_id ) ? $forum_map[$forum->parent_id] : 0, |
| | 408 | 'post_type' => bbp_get_forum_post_type(), |
| | 409 | 'menu_order' => $forum->left_id |
| | 410 | ) ); |
| | 411 | |
| | 412 | $forum_map[$forum->forum_id] = $inserted_forum; |
| | 413 | |
| | 414 | if ( !empty( $inserted_forum ) && !is_wp_error( $inserted_forum ) ) { |
| | 415 | echo "<li>" . sprintf( __( 'Added the forum as forum #<a href="%1$s">%2$s</a>', 'bbpress' ), get_permalink( $inserted_forum ), $inserted_forum ) . "</li>\n"; |
| | 416 | } else { |
| | 417 | echo "<li><em>" . __( 'There was a problem in adding the forum.', 'bbpress' ) . "</em></li></ul></li>\n"; |
| | 418 | continue; |
| | 419 | } |
| | 420 | |
| | 421 | $topics = $this->db->get_results( $this->db->prepare( |
| | 422 | "SELECT topic_id, topic_title, topic_poster, topic_time, topic_status, topic_type |
| | 423 | FROM {$this->db->topics} WHERE forum_id = %d AND topic_status IN (0, 1)", $forum->forum_id ) ); |
| | 424 | |
| | 425 | // In standalone, categories can have topics, but this is not the case in plugin |
| | 426 | // So make the forum category if it doesn't have topics |
| | 427 | // Else close it if it's a category and has topics |
| | 428 | if ( $forum->forum_type == 0 ) { |
| | 429 | |
| | 430 | if ( count( $topics ) == 0 ) { |
| | 431 | bbp_categorize_forum( $inserted_forum ); |
| | 432 | echo "<li>" . __( 'The forum is a category and has no topics.', 'bbpress' ) . "</li>\n</ul>\n</li>"; |
| | 433 | |
| | 434 | continue; |
| | 435 | } else { |
| | 436 | bbp_close_forum( $inserted_forum ); |
| | 437 | echo "<li>" . __( 'The forum is a category but has topics, so it has been set as closed on the new board.', 'bbpress' ) . "</li>\n"; |
| | 438 | } |
| | 439 | |
| | 440 | } |
| | 441 | |
| | 442 | echo "<li>" . sprintf( __( 'Total number of topics in the forum: %s', 'bbpress' ), count( $topics ) ) . "</li>\n"; |
| | 443 | |
| | 444 | foreach ( (array) $topics as $topic ) { |
| | 445 | $posts = $this->db->get_results( $this->db->prepare( |
| | 446 | "SELECT post_id, poster_id, poster_ip, post_time, post_username, post_subject, post_text |
| | 447 | FROM {$this->db->posts} WHERE topic_id = %d ORDER BY post_time ASC", $topic->topic_id ) ); |
| | 448 | |
| | 449 | $first_post = array_shift( $posts ); |
| | 450 | |
| | 451 | // If the topic is public, check if it's open and set the status accordingly |
| | 452 | $topic_status = $topic->topic_status == 0 ? 'publish' : $bbp->closed_status_id; |
| | 453 | |
| | 454 | $inserted_topic = wp_insert_post( array( |
| | 455 | 'post_parent' => $inserted_forum, |
| | 456 | 'post_author' => $user_map[$topic->topic_poster], |
| | 457 | 'post_content' => $first_post->post_text, |
| | 458 | 'post_title' => $topic->topic_title, |
| | 459 | 'post_name' => sanitize_title_with_dashes( $topic->topic_title ), |
| | 460 | 'post_status' => $topic_status, |
| | 461 | 'post_date_gmt' => gmdate( 'Y-m-d H:i:s', $topic->topic_time ), |
| | 462 | 'post_date' => get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $topic->topic_time ) ), |
| | 463 | 'post_type' => bbp_get_topic_post_type() |
| | 464 | ) ); |
| | 465 | |
| | 466 | if ( !empty( $inserted_topic ) && !is_wp_error( $inserted_topic ) ) { |
| | 467 | |
| | 468 | // Loginless Posting |
| | 469 | if ( $topic->topic_poster == 1 ) { |
| | 470 | update_post_meta( $inserted_topic, '_bbp_anonymous_name', $first_post->post_username ); |
| | 471 | update_post_meta( $inserted_topic, '_bbp_anonymous_email', '' ); |
| | 472 | update_post_meta( $inserted_topic, '_bbp_anonymous_website', '' ); |
| | 473 | } |
| | 474 | |
| | 475 | // Author IP |
| | 476 | update_post_meta( $inserted_topic, '_bbp_author_ip', $first_post->poster_ip ); |
| | 477 | |
| | 478 | // Forum topic meta |
| | 479 | update_post_meta( $inserted_topic, '_bbp_forum_id', $inserted_forum ); |
| | 480 | update_post_meta( $inserted_topic, '_bbp_topic_id', $inserted_topic ); |
| | 481 | |
| | 482 | $replies = 0; |
| | 483 | $last_reply = 0; |
| | 484 | $post = null; |
| | 485 | |
| | 486 | foreach ( (array) $posts as $post ) { |
| | 487 | |
| | 488 | $last_reply = wp_insert_post( array( |
| | 489 | 'post_parent' => $inserted_topic, |
| | 490 | 'post_author' => $user_map[$post->poster_id], |
| | 491 | 'post_date_gmt' => gmdate( 'Y-m-d H:i:s', $post->post_time ), |
| | 492 | 'post_date' => get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $post->post_time ) ), |
| | 493 | 'post_title' => $post->post_subject, |
| | 494 | 'post_name' => sanitize_title_with_dashes( $post->post_subject ), |
| | 495 | 'post_status' => 0, |
| | 496 | 'post_type' => bbp_get_reply_post_type(), |
| | 497 | 'post_content' => $post->post_text |
| | 498 | ) ); |
| | 499 | |
| | 500 | // Loginless |
| | 501 | if ( $post->poster_id == 1 ) { |
| | 502 | update_post_meta( $last_reply, '_bbp_anonymous_name', $post->post_username ); |
| | 503 | update_post_meta( $last_reply, '_bbp_anonymous_email', '' ); |
| | 504 | update_post_meta( $last_reply, '_bbp_anonymous_website', '' ); |
| | 505 | } |
| | 506 | |
| | 507 | // Author IP |
| | 508 | update_post_meta( $last_reply, '_bbp_author_ip', $post->poster_ip ); |
| | 509 | |
| | 510 | // Reply Parents |
| | 511 | update_post_meta( $last_reply, '_bbp_forum_id', $inserted_forum ); |
| | 512 | update_post_meta( $last_reply, '_bbp_topic_id', $inserted_topic ); |
| | 513 | |
| | 514 | bbp_update_reply_walker( $last_reply ); |
| | 515 | |
| | 516 | $replies++; |
| | 517 | } |
| | 518 | |
| | 519 | // Topic stickiness |
| | 520 | switch ( $topic->topic_type ) { |
| | 521 | |
| | 522 | // Sticky |
| | 523 | case 1 : |
| | 524 | // Announce |
| | 525 | case 2 : |
| | 526 | bbp_stick_topic( $inserted_topic ); |
| | 527 | break; |
| | 528 | |
| | 529 | // Global |
| | 530 | case 3 : |
| | 531 | bbp_stick_topic( $inserted_topic, true ); |
| | 532 | break; |
| | 533 | } |
| | 534 | |
| | 535 | // Last active |
| | 536 | $last_active_id = !empty( $last_reply ) ? $last_reply : $inserted_topic; |
| | 537 | $last_active_time = gmdate( 'Y-m-d H:i:s', !empty( $post ) ? $post->post_time : $first_post->post_time ); |
| | 538 | |
| | 539 | // Reply topic meta |
| | 540 | update_post_meta( $inserted_topic, '_bbp_last_reply_id', $last_reply ); |
| | 541 | update_post_meta( $inserted_topic, '_bbp_last_active_id', $last_active_id ); |
| | 542 | update_post_meta( $inserted_topic, '_bbp_last_active_time', $last_active_time ); |
| | 543 | update_post_meta( $inserted_topic, '_bbp_reply_count', $replies ); |
| | 544 | update_post_meta( $inserted_topic, '_bbp_hidden_reply_count', 0 ); |
| | 545 | |
| | 546 | // Voices will be done by recount |
| | 547 | |
| | 548 | bbp_update_topic_walker( $inserted_topic ); |
| | 549 | |
| | 550 | echo "<li>" . sprintf( __( 'Added topic #%1$s (%2$s) as topic #<a href="%3$s">%4$s</a> with %5$s replies.', 'bbpress' ), $topic->topic_id, esc_html( $topic->topic_title ), get_permalink( $inserted_topic ), $inserted_topic, $replies ) . "</li>\n"; |
| | 551 | } else { |
| | 552 | echo "<li><em>" . sprintf( __( 'There was a problem in adding topic #1$s (%2$s).', 'bbpress' ), $topic->topic_id, esc_html( $topic->topic_title ) ) . "</em></li></ul></li>\n"; |
| | 553 | continue; |
| | 554 | } |
| | 555 | } |
| | 556 | |
| | 557 | echo "</ul>\n</li>\n"; |
| | 558 | |
| | 559 | } ?> |
| | 560 | |
| | 561 | </ol> |
| | 562 | |
| | 563 | <?php |
| | 564 | |
| | 565 | // Clean up database and we're out |
| | 566 | $this->cleanup(); |
| | 567 | do_action( 'import_done', 'phpbb' ); |
| | 568 | |
| | 569 | ?> |
| | 570 | |
| | 571 | <p><strong><?php printf( __( 'Your forums, topics and posts have all been imported, but wait – there’s more! Now we need to do a <a href="%s">recount</a> to get the counts in sync! Yes, we’re bad at Math.', 'bbpress' ), add_query_arg( array( 'page' => 'bbp-recount' ), get_admin_url( 0, 'tools.php' ) ) ); ?></strong></p> |
| | 572 | |
| | 573 | <h4><?php printf( __( 'After that it\'s all done. <a href="%s">Have fun!</a> :)', 'bbpress' ), home_url() ); ?></h4> |
| | 574 | |
| | 575 | </div> |
| | 576 | |
| | 577 | <?php |
| | 578 | } |
| | 579 | |
| | 580 | } // class phpBB_Importer |
| | 581 | |
| | 582 | $phpbb_import = new phpBB_Importer(); |
| | 583 | |
| | 584 | register_importer( 'phpbb', __( 'phpBB3', 'bbpress' ), __( 'Import your phpBB3 board.', 'bbpress' ), array( $phpbb_import, 'dispatch' ) ); |