| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * bbPress needs this class for its usermeta manipulation. |
| 5 | */ |
| 6 | class bbPress_Importer_BB_Auth { |
| 7 | function update_meta( $args = '' ) { |
| 8 | $defaults = array( 'id' => 0, 'meta_key' => null, 'meta_value' => null, 'meta_table' => 'usermeta', 'meta_field' => 'user_id', 'cache_group' => 'users' ); |
| 9 | $args = wp_parse_args( $args, $defaults ); |
| 10 | extract( $args, EXTR_SKIP ); |
| 11 | |
| 12 | return update_user_meta( $id, $meta_key, $meta_value ); |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | if ( !class_exists( 'BPDB' ) ) : |
| 17 | |
| 18 | /** |
| 19 | * bbPress needs the DB class to be BPDB, but we want to use WPDB, so we can |
| 20 | * extend it and use this. |
| 21 | */ |
| 22 | class BPDB extends WPDB { |
| 23 | var $db_servers = array(); |
| 24 | |
| 25 | function BPDB( $dbuser, $dbpassword, $dbname, $dbhost ) { |
| 26 | $this->__construct( $dbuser, $dbpassword, $dbname, $dbhost ); |
| 27 | } |
| 28 | |
| 29 | function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) { |
| 30 | parent::__construct( $dbuser, $dbpassword, $dbname, $dbhost ); |
| 31 | |
| 32 | $args = func_get_args(); |
| 33 | $args = call_user_func_array( array( &$this, '_init' ), $args ); |
| 34 | |
| 35 | if ( $args['host'] ) |
| 36 | $this->db_servers['dbh_global'] = $args; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Determine if a database supports a particular feature. |
| 41 | * |
| 42 | * Overriden here to work around differences between bbPress', and WordPress', implementation differences. |
| 43 | * In particular, when BuddyPress tries to run bbPress' SQL installation script, the collation check always |
| 44 | * failed. The capability is long supported by WordPress' minimum required MySQL version, so this is safe. |
| 45 | */ |
| 46 | function has_cap( $db_cap, $_table_name='' ) { |
| 47 | if ( 'collation' == $db_cap ) |
| 48 | return true; |
| 49 | |
| 50 | return parent::has_cap( $db_cap ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Initialises the class variables based on provided arguments. |
| 55 | * Based on, and taken from, the BackPress class in turn taken from the 1.0 branch of bbPress. |
| 56 | */ |
| 57 | function _init( $args ) |
| 58 | { |
| 59 | if ( 4 == func_num_args() ) { |
| 60 | $args = array( |
| 61 | 'user' => $args, |
| 62 | 'password' => func_get_arg( 1 ), |
| 63 | 'name' => func_get_arg( 2 ), |
| 64 | 'host' => func_get_arg( 3 ), |
| 65 | 'charset' => defined( 'BBDB_CHARSET' ) ? BBDB_CHARSET : false, |
| 66 | 'collate' => defined( 'BBDB_COLLATE' ) ? BBDB_COLLATE : false, |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | $defaults = array( |
| 71 | 'user' => false, |
| 72 | 'password' => false, |
| 73 | 'name' => false, |
| 74 | 'host' => 'localhost', |
| 75 | 'charset' => false, |
| 76 | 'collate' => false, |
| 77 | 'errors' => false |
| 78 | ); |
| 79 | |
| 80 | return wp_parse_args( $args, $defaults ); |
| 81 | } |
| 82 | |
| 83 | function escape_deep( $data ) { |
| 84 | if ( is_array( $data ) ) { |
| 85 | foreach ( (array) $data as $k => $v ) { |
| 86 | if ( is_array( $v ) ) { |
| 87 | $data[$k] = $this->_escape( $v ); |
| 88 | } else { |
| 89 | $data[$k] = $this->_real_escape( $v ); |
| 90 | } |
| 91 | } |
| 92 | } else { |
| 93 | $data = $this->_real_escape( $data ); |
| 94 | } |
| 95 | |
| 96 | return $data; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | endif; // class_exists |
| 101 | |
| 102 | if ( !function_exists( 'bb_cache_users' ) ) : |
| 103 | function bb_cache_users( $users ) {} |
| 104 | endif; |
| 105 | |
| 106 | /** |
| 107 | * bbPress Standalone Importer |
| 108 | * |
| 109 | * Helps in converting your bbPress Standalone into the new bbPress Plugin |
| 110 | * |
| 111 | * @package bbPress |
| 112 | * @subpackage Importer |
| 113 | * |
| 114 | * @todo Docs |
| 115 | * @todo User Mapping (ref. MT Importer) |
| 116 | * @todo Role Mapping Options |
| 117 | */ |
| 118 | class bbPress_Importer { |
| 119 | /** |
| 120 | * @var string Path to bbPress standalone |
| 121 | */ |
| 122 | var $bb_path = ''; |
| 123 | |
| 124 | /** |
| 125 | * @var bool Are we debugging? |
| 126 | */ |
| 127 | var $debug = false; |
| 128 | |
| 129 | /** |
| 130 | * Load the bbPress environment |
| 131 | */ |
| 132 | function load_bbpress() { |
| 133 | global $wpdb, $wp_roles, $current_user, $wp_users_object, $wp_taxonomy_object; |
| 134 | global $bb, $bbdb, $bb_table_prefix, $bb_current_user, $bb_roles, $bb_queries; |
| 135 | |
| 136 | /* Return if we've already run this function. */ |
| 137 | if ( is_object( $bbdb ) ) |
| 138 | return; |
| 139 | |
| 140 | if ( !file_exists( $this->bb_path ) ) |
| 141 | return false; |
| 142 | |
| 143 | define( 'BB_PATH', trailingslashit( dirname( $this->bb_path ) ) ); |
| 144 | define( 'BACKPRESS_PATH', BB_PATH . 'bb-includes/backpress/' ); |
| 145 | define( 'BB_INC', 'bb-includes/' ); |
| 146 | |
| 147 | require_once( BB_PATH . BB_INC . 'class.bb-query.php' ); |
| 148 | require_once( BB_PATH . BB_INC . 'class.bb-walker.php' ); |
| 149 | require_once( BB_PATH . BB_INC . 'functions.bb-core.php' ); |
| 150 | require_once( BB_PATH . BB_INC . 'functions.bb-forums.php' ); |
| 151 | require_once( BB_PATH . BB_INC . 'functions.bb-topics.php' ); |
| 152 | require_once( BB_PATH . BB_INC . 'functions.bb-posts.php' ); |
| 153 | require_once( BB_PATH . BB_INC . 'functions.bb-topic-tags.php' ); |
| 154 | require_once( BB_PATH . BB_INC . 'functions.bb-capabilities.php' ); |
| 155 | require_once( BB_PATH . BB_INC . 'functions.bb-meta.php' ); |
| 156 | require_once( BB_PATH . BB_INC . 'functions.bb-pluggable.php' ); |
| 157 | require_once( BB_PATH . BB_INC . 'functions.bb-formatting.php' ); |
| 158 | require_once( BB_PATH . BB_INC . 'functions.bb-template.php' ); |
| 159 | |
| 160 | require_once( BACKPRESS_PATH . 'class.wp-taxonomy.php' ); |
| 161 | require_once( BB_PATH . BB_INC . 'class.bb-taxonomy.php' ); |
| 162 | |
| 163 | $bb = new stdClass(); |
| 164 | require_once( $this->bb_path ); |
| 165 | |
| 166 | // Setup the global database connection |
| 167 | $bbdb = new BPDB( BBDB_USER, BBDB_PASSWORD, BBDB_NAME, BBDB_HOST ); |
| 168 | |
| 169 | /* Set the table names */ |
| 170 | $bbdb->forums = $bb_table_prefix . 'forums'; |
| 171 | $bbdb->meta = $bb_table_prefix . 'meta'; |
| 172 | $bbdb->posts = $bb_table_prefix . 'posts'; |
| 173 | $bbdb->terms = $bb_table_prefix . 'terms'; |
| 174 | $bbdb->term_relationships = $bb_table_prefix . 'term_relationships'; |
| 175 | $bbdb->term_taxonomy = $bb_table_prefix . 'term_taxonomy'; |
| 176 | $bbdb->topics = $bb_table_prefix . 'topics'; |
| 177 | |
| 178 | if ( isset( $bb->custom_user_table ) ) |
| 179 | $bbdb->users = $bb->custom_user_table; |
| 180 | else |
| 181 | $bbdb->users = $bb_table_prefix . 'users'; |
| 182 | |
| 183 | if ( isset( $bb->custom_user_meta_table ) ) |
| 184 | $bbdb->usermeta = $bb->custom_user_meta_table; |
| 185 | else |
| 186 | $bbdb->usermeta = $bb_table_prefix . 'usermeta'; |
| 187 | |
| 188 | $bbdb->prefix = $bb_table_prefix; |
| 189 | |
| 190 | define( 'BB_INSTALLING', false ); |
| 191 | |
| 192 | if ( is_object( $wp_roles ) ) { |
| 193 | $bb_roles = $wp_roles; |
| 194 | bb_init_roles( $bb_roles ); |
| 195 | } |
| 196 | |
| 197 | do_action( 'bb_got_roles' ); |
| 198 | do_action( 'bb_init' ); |
| 199 | do_action( 'init_roles' ); |
| 200 | |
| 201 | $bb_current_user = $current_user; |
| 202 | $wp_users_object = new bbPress_Importer_BB_Auth; |
| 203 | |
| 204 | if ( !isset( $wp_taxonomy_object ) ) |
| 205 | $wp_taxonomy_object = new BB_Taxonomy( $bbdb ); |
| 206 | |
| 207 | $wp_taxonomy_object->register_taxonomy( 'bb_topic_tag', 'bb_topic' ); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Returns the tag name from tag object |
| 212 | * |
| 213 | * @param object $tag Tag Object |
| 214 | * @return string Tag name |
| 215 | */ |
| 216 | function get_tag_name( $tag ) { |
| 217 | return $tag->name; |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Simple check to check if the WP and bb user tables are integrated or not |
| 222 | * |
| 223 | * @return bool True if integrated, false if not |
| 224 | */ |
| 225 | function is_integrated() { |
| 226 | global $bbdb, $wpdb; |
| 227 | |
| 228 | return ( $wpdb->users == $bbdb->users && $wpdb->usermeta == $bbdb->usermeta ); |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Tries to automatically locate the bbPress standalone install path |
| 233 | * |
| 234 | * @return string Path, if found |
| 235 | */ |
| 236 | function autolocate_bb_path() { |
| 237 | |
| 238 | $path = ''; |
| 239 | $dirs = array( 'forum', 'forums', 'board', 'discussion', 'bb', 'bbpress' ); |
| 240 | $base = trailingslashit( ABSPATH ); |
| 241 | $base_dirs = array( $base, dirname( $base ) ); |
| 242 | |
| 243 | foreach ( $dirs as $dir ) { |
| 244 | |
| 245 | foreach ( $base_dirs as $base_dir ) { |
| 246 | $test_path = $base_dir . $dir . '/bb-config.php'; |
| 247 | |
| 248 | if ( file_exists( $test_path ) ) { |
| 249 | $path = $test_path; |
| 250 | break; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | } |
| 255 | |
| 256 | return $path; |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Get the bbPress standalone topic favoriters from topic id |
| 261 | * |
| 262 | * @param int $topic_id Topic id |
| 263 | * @return array Topic Favoriters' IDs |
| 264 | */ |
| 265 | function bb_get_topic_favoriters( $topic_id = 0 ) { |
| 266 | if ( empty( $topic_id ) ) |
| 267 | return array(); |
| 268 | |
| 269 | global $bbdb; |
| 270 | |
| 271 | return (array) $bbdb->get_col( $bbdb->prepare( "SELECT user_id |
| 272 | FROM $bbdb->usermeta |
| 273 | WHERE meta_key = '{$bbdb->prefix}favorites' |
| 274 | AND FIND_IN_SET( %d, meta_value ) > 0", |
| 275 | $topic_id ) ); |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * Get the bbPress standalone topic subscribers from topic id |
| 280 | * |
| 281 | * If the Subscribe to Topic bbPress plugin is active, then subscription |
| 282 | * info is taken from that. Otherwise, if the the user is using |
| 283 | * bbPress >= 1.1 alpha, then get the info from there. |
| 284 | * |
| 285 | * @param int $topic_id Topic id |
| 286 | * @return array Topic Subscribers' IDs |
| 287 | */ |
| 288 | function bb_get_topic_subscribers( $topic_id = 0 ) { |
| 289 | if ( empty( $topic_id ) ) |
| 290 | return array(); |
| 291 | |
| 292 | global $bbdb, $subscribe_to_topic; |
| 293 | |
| 294 | $users = array(); |
| 295 | |
| 296 | // The user is using Subscribe to Topic plugin by _ck_, get the subscribers from there |
| 297 | if ( !empty( $subscribe_to_topic ) && !empty( $subscribe_to_topic['db'] ) ) { |
| 298 | $users = $bbdb->get_col( $bbdb->prepare( "SELECT user |
| 299 | FROM {$subscribe_to_topic['db']} |
| 300 | WHERE topic = %d |
| 301 | AND type = 2", $topic_id ) ); |
| 302 | |
| 303 | // The user is using alpha, get the subscribers from built-in functionality |
| 304 | } elseif ( function_exists( 'bb_notify_subscribers' ) ) { |
| 305 | $users = $bbdb->get_col( $bbdb->prepare( "SELECT `$bbdb->term_relationships`.`object_id` |
| 306 | FROM $bbdb->term_relationships, $bbdb->term_taxonomy, $bbdb->terms |
| 307 | WHERE `$bbdb->term_relationships`.`term_taxonomy_id` = `$bbdb->term_taxonomy`.`term_taxonomy_id` |
| 308 | AND `$bbdb->term_taxonomy`.`term_id` = `$bbdb->terms`.`term_id` |
| 309 | AND `$bbdb->term_taxonomy`.`taxonomy` = 'bb_subscribe' |
| 310 | AND `$bbdb->terms`.`slug` = 'topic-%d'", |
| 311 | $topic_id ) ); |
| 312 | } |
| 313 | |
| 314 | return (array) $users; |
| 315 | } |
| 316 | |
| 317 | function header() { ?> |
| 318 | |
| 319 | <div class="wrap"> |
| 320 | |
| 321 | <?php screen_icon(); ?> |
| 322 | |
| 323 | <h2><?php _e( 'bbPress Standalone Importer', 'bbpress' ); ?></h2> |
| 324 | |
| 325 | <?php |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Output an error message with a button to try again. |
| 330 | * |
| 331 | * @param type $error |
| 332 | * @param type $step |
| 333 | */ |
| 334 | function throw_error( $error, $step ) { |
| 335 | echo '<p><strong>' . $error->get_error_message() . '</strong></p>'; |
| 336 | echo $this->next_step( $step, __( 'Try Again', 'bbpress' ) ); |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * Returns the HTML for a link to the next page |
| 341 | * |
| 342 | * @param type $next_step |
| 343 | * @param type $label |
| 344 | * @param type $id |
| 345 | * @return string |
| 346 | */ |
| 347 | function next_step( $next_step, $label, $id = 'bbpress-import-next-form' ) { |
| 348 | $str = '<form action="admin.php?import=bbpress" method="post" id="' . $id . '">'; |
| 349 | $str .= wp_nonce_field( 'bbp-bbpress-import', '_wpnonce', true, false ); |
| 350 | $str .= wp_referer_field( false ); |
| 351 | $str .= '<input type="hidden" name="step" id="step" value="' . esc_attr( $next_step ) . '" />'; |
| 352 | $str .= '<p><input type="submit" class="button" value="' . esc_attr( $label ) . '" /> <span id="auto-message"></span></p>'; |
| 353 | $str .= '</form>'; |
| 354 | |
| 355 | return $str; |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * Footer |
| 360 | */ |
| 361 | function footer() { ?> |
| 362 | |
| 363 | </div> |
| 364 | |
| 365 | <?php |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * Dispatch |
| 370 | */ |
| 371 | function dispatch() { |
| 372 | if ( empty( $_REQUEST['step'] ) ) |
| 373 | $step = 0; |
| 374 | else |
| 375 | $step = (int) $_REQUEST['step']; |
| 376 | |
| 377 | $this->header(); |
| 378 | |
| 379 | switch ( $step ) { |
| 380 | case -1 : |
| 381 | $this->cleanup(); |
| 382 | // Intentional no break |
| 383 | |
| 384 | case 0 : |
| 385 | $this->greet(); |
| 386 | break; |
| 387 | |
| 388 | case 1 : |
| 389 | case 2 : |
| 390 | case 3 : |
| 391 | |
| 392 | check_admin_referer( 'bbp-bbpress-import' ); |
| 393 | $result = $this->{ 'step' . $step }(); |
| 394 | |
| 395 | break; |
| 396 | } |
| 397 | |
| 398 | $this->footer(); |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * Greet message |
| 403 | */ |
| 404 | function greet() { |
| 405 | global $wpdb, $bbdb; |
| 406 | |
| 407 | $autolocate = $this->autolocate_bb_path(); |
| 408 | |
| 409 | ?> |
| 410 | |
| 411 | <div class="narrow"> |
| 412 | |
| 413 | <form action="admin.php?import=bbpress" method="post"> |
| 414 | |
| 415 | <?php wp_nonce_field( 'bbp-bbpress-import' ); ?> |
| 416 | |
| 417 | <?php if ( get_option( 'bbp_bbpress_path' ) ) : ?> |
| 418 | |
| 419 | <input type="hidden" name="step" value="<?php echo esc_attr( get_option( 'bbp_bbpress_step' ) ); ?>" /> |
| 420 | |
| 421 | <p><?php _e( 'It looks like you attempted to convert your bbPress standalone previously and got interrupted.', 'bbpress' ); ?></p> |
| 422 | |
| 423 | <p class="submit"> |
| 424 | <input type="submit" class="button" value="<?php esc_attr_e( 'Continue previous import', 'bbpress' ); ?>" /> |
| 425 | </p> |
| 426 | |
| 427 | <p class="submitbox"><a href="<?php echo esc_url( add_query_arg( array( 'import' => 'bbpress', 'step' => '-1', '_wpnonce' => wp_create_nonce( 'bbp-bbpress-import' ), '_wp_http_referer' => esc_attr( $_SERVER['REQUEST_URI'] ) ) ) ); ?>" class="deletion submitdelete"><?php _e( 'Cancel & start a new import', 'bbpress' ); ?></a></p> |
| 428 | |
| 429 | <?php else : ?> |
| 430 | |
| 431 | <input type="hidden" name="bbp_bbpress_path" value="true" /> |
| 432 | |
| 433 | <p><?php _e( 'Howdy! This importer allows you to convert your bbPress Standalone into the bbPress Plugin.', 'bbpress' ); ?></p> |
| 434 | <p><?php _e( 'Please enter the path to your bbPress standalone install, where you\'d find your <code>bb-config.php</code>:', 'bbpress' ); ?></p> |
| 435 | |
| 436 | <table class="form-table"> |
| 437 | |
| 438 | <tr> |
| 439 | <th scope="row"><label for="bbp_bbpress_path"><?php _e( 'bbPress Standalone Path', 'bbpress' ); ?></label></th> |
| 440 | <td><input type="text" name="bbp_bbpress_path" id="bbp_bbpress_path" class="regular-text" value="<?php echo $autolocate; ?>" /></td> |
| 441 | </tr> |
| 442 | |
| 443 | </table> |
| 444 | |
| 445 | <?php if ( !empty( $autolocate ) ) : ?> |
| 446 | <p><?php _e( 'We tried to autolocate the path to your bbPress install and were successful. Yes, we\'re smart. ;)', 'bbpress' ); ?></p> |
| 447 | <?php endif; ?> |
| 448 | |
| 449 | <ol> |
| 450 | |
| 451 | <li><?php printf( __( 'Make sure that you\'ve created a <a href="%s">backup</a> of your database and files just in case something goes wrong. If the import process is interrupted for any reason, please restore your backup and re-run the import.', 'bbpress' ), 'http://codex.wordpress.org/WordPress_Backups' ); ?></li> |
| 452 | <li><?php _e( 'This converter is heavy and consumes too much CPU, so it is suggested that you do the process on your local machine. '); ?></li> |
| 453 | <li><?php _e( 'Notes on compatibility:', 'bbpress' ); ?> |
| 454 | <ul> |
| 455 | <li> |
| 456 | <?php printf( __( 'If you have the <a href="%s">Subscribe to Topic</a> plugin active, then the script would migrate the user subscriptions from that plugin. If you\'re using the alpha version of bbPress 1.1 (or later), then subscriptions would be fetched from the built-in functionality, but please disable Subscribe to Topic plugin (if you have that activated) for this to happen.', 'bbpress' ), 'http://bbpress.org/plugins/topic/subscribe-to-topic/' ); ?> |
| 457 | </li> |
| 458 | </ul> |
| 459 | </li> |
| 460 | <li> |
| 461 | <?php _e( 'Disable each and every other plugin, on WordPress and bbPress standalone both. Also, please switch to the default themes to avoid conflicts. You must let the bbPress plugin on WordPress remain active.', 'bbpress' ); ?> |
| 462 | </li> |
| 463 | |
| 464 | </ol> |
| 465 | |
| 466 | <p class="submit"> |
| 467 | <input type="hidden" name="step" value="1" /> |
| 468 | <input type="submit" class="button" value="<?php esc_attr_e( 'Proceed', 'bbpress' ); ?>" /> |
| 469 | </p> |
| 470 | |
| 471 | <?php endif; ?> |
| 472 | |
| 473 | </form> |
| 474 | |
| 475 | </div> |
| 476 | <?php |
| 477 | } |
| 478 | |
| 479 | /** |
| 480 | * Cleanups all the options used by the importer |
| 481 | */ |
| 482 | function cleanup() { |
| 483 | delete_option( 'bbp_bbpress_path' ); |
| 484 | delete_option( 'bbp_bbpress_step' ); |
| 485 | |
| 486 | do_action( 'import_end' ); |
| 487 | } |
| 488 | |
| 489 | /** |
| 490 | * Technically the first half of step 1, this is separated to allow for AJAX |
| 491 | * calls. Sets up some variables and options and confirms authentication. |
| 492 | * |
| 493 | * @return type |
| 494 | */ |
| 495 | function setup() { |
| 496 | // Get details from form or from DB |
| 497 | if ( !empty( $_POST['bbp_bbpress_path'] ) ) { |
| 498 | // Store details for later |
| 499 | $this->bb_path = $_POST['bbp_bbpress_path']; |
| 500 | |
| 501 | update_option( 'bbp_bbpress_path', $this->bb_path ); |
| 502 | } else { |
| 503 | $this->bb_path = get_option( 'bbp_bbpress_path' ); |
| 504 | } |
| 505 | |
| 506 | if ( empty( $this->bb_path ) ) { ?> |
| 507 | |
| 508 | <p><?php _e( 'Please enter the path to your bbPress configuration file (<code>bb-config.php</code>).', 'bbpress' ); ?></p> |
| 509 | <p><a href="<?php echo esc_url( add_query_arg( array( 'import' => 'bbpress', 'step' => '-1', '_wpnonce' => wp_create_nonce( 'bbp-bbpress-import' ), '_wp_http_referer' => esc_attr( remove_query_arg( 'step', $_SERVER['REQUEST_URI'] ) ) ) ) ); ?>"><?php _e( 'Start again', 'bbpress' ); ?></a></p> |
| 510 | |
| 511 | <?php |
| 512 | |
| 513 | return false; |
| 514 | } |
| 515 | |
| 516 | // Check if the user submitted a directory as the path by mistake |
| 517 | if ( is_dir( $this->bb_path ) && file_exists( trailingslashit( $this->bb_path ) . 'bb-config.php' ) ) { |
| 518 | $this->bb_path = trailingslashit( $this->bb_path ) . 'bb-config.php'; |
| 519 | } |
| 520 | |
| 521 | // Check if the file exists |
| 522 | if ( !file_exists( $this->bb_path ) || is_dir( $this->bb_path ) ) { |
| 523 | |
| 524 | delete_option( 'bbp_bbpress_path' ); ?> |
| 525 | |
| 526 | <p><?php _e( 'bbPress configuration file (<code>bb-config.php</code>) doesn\'t exist in the path specified! Please check the path and try again.', 'bbpress' ); ?></p> |
| 527 | <p><a href="<?php echo esc_url( add_query_arg( array( 'import' => 'bbpress', 'step' => '-1', '_wpnonce' => wp_create_nonce( 'bbp-bbpress-import' ), '_wp_http_referer' => esc_attr( remove_query_arg( 'step', $_SERVER['REQUEST_URI'] ) ) ) ) ); ?>"><?php _e( 'Start again', 'bbpress' ); ?></a></p> |
| 528 | <?php |
| 529 | return false; |
| 530 | } |
| 531 | |
| 532 | $this->load_bbpress(); |
| 533 | |
| 534 | remove_filter( 'pre_post_status', 'bb_bozo_pre_post_status', 5, 3 ); |
| 535 | |
| 536 | return true; |
| 537 | } |
| 538 | |
| 539 | /** |
| 540 | * Notes & User Options |
| 541 | */ |
| 542 | function step1() { |
| 543 | |
| 544 | update_option( 'bbp_bbpress_step', 1 ); |
| 545 | |
| 546 | $setup = $this->setup(); |
| 547 | if ( empty( $setup ) ) { |
| 548 | return false; |
| 549 | } elseif ( is_wp_error( $setup ) ) { |
| 550 | $this->throw_error( $setup, 1 ); |
| 551 | return false; |
| 552 | } |
| 553 | |
| 554 | $radio = 'user'; |
| 555 | |
| 556 | global $wpdb, $bbdb; ?> |
| 557 | |
| 558 | <h3><?php _e( 'Choose an option based on your Condition', 'bbpress' ); ?></h3> |
| 559 | |
| 560 | <?php if ( $this->is_integrated() ) : $radio = 'board'; ?> |
| 561 | |
| 562 | <p><?php _e( '<strong>Auto-detected</strong>: It looks like your WordPress and bbPress user tables are integrated, therefore you can directly proceed to <label for="step_board">importing forums, topics and posts section</label> and don\'t need to go through the process of migrating your users. If you feel that you have a bit different setup, then you can choose that option below.', 'bbpress' ); ?></p> |
| 563 | |
| 564 | <?php endif; ?> |
| 565 | |
| 566 | <form action="admin.php?import=bbpress" method="post"> |
| 567 | |
| 568 | <ol> |
| 569 | |
| 570 | <li> |
| 571 | <?php _e( 'Your WordPress blog is <strong>new</strong> and you don\'t have the fear of losing WordPress users:', 'bbpress' ); ?> |
| 572 | <label for="step_user"><?php _e( 'Go to migrating users section.', 'bbpress' ); ?></label> |
| 573 | <?php printf( __( '<strong>Note</strong>: The WordPress %1$s and %2$s tables would be renamed, but not deleted so that you could restore them if something goes wrong.', 'bbpress' ), $wpdb->users, $wpdb->usermeta ); ?> |
| 574 | <?php printf( __( 'Please ensure there are no tables with names %1$s and %2$s so that there is no problem in renaming.', 'bbpress' ), $bbdb->prefix . $wpdb->users . '_tmp', $bbdb->prefix . $wpdb->usermeta . '_tmp' ); ?> |
| 575 | <?php _e( 'Also, your WordPress and bbPress installs must be in the same database.', 'bbpress' ); ?> |
| 576 | </li> |
| 577 | |
| 578 | <li> |
| 579 | <?php _e( 'You\'re done with user migration or have the user tables <strong>integrated</strong>:', 'bbpress' ); ?> |
| 580 | <label for="step_board"><?php _e( 'Proceed to importing forums, topics and posts section.', 'bbpress' ); ?></label> |
| 581 | </li> |
| 582 | |
| 583 | <li> |
| 584 | <?php _e( 'You have a well <strong>established</strong> WordPress user base, the user tables are not integrated and you can\'t lose your users:', 'bbpress' ); ?> |
| 585 | <?php _e( 'This is currently not yet supported, and will likely not be in the future also as it is highly complex to merge two user sets (which might even conflict).', 'bbpress' ); ?> |
| 586 | <?php printf( __( 'But, patches are always <a href="%s" title="The last revision containing the custom user migration code">welcome</a>. :)', 'bbpress' ), 'http://code.google.com/p/bbpress-standalone-to-plugin/source/browse/trunk/bbs2p.php?spec=svn13&r=13' ); ?> |
| 587 | </li> |
| 588 | |
| 589 | </ol> |
| 590 | |
| 591 | <input type="radio" name="step" value="2"<?php checked( $radio, 'user' ); ?> id="step_user" /> |
| 592 | <label for="step_user"><?php _e( 'Migrate Users', 'bbpress' ); ?></label> |
| 593 | |
| 594 | <input type="radio" name="step" value="3"<?php checked( $radio, 'board' ); ?> id="step_board" /> |
| 595 | <label for="step_board"><?php _e( 'Import Forums, Topics & Posts', 'bbpress' ); ?></label> |
| 596 | |
| 597 | <p class="submit"> |
| 598 | <?php wp_nonce_field( 'bbp-bbpress-import' ); ?> |
| 599 | <input type="submit" class="button" value="<?php esc_attr_e( 'Start!', 'bbpress' ); ?>" /> |
| 600 | </p> |
| 601 | |
| 602 | </form> |
| 603 | |
| 604 | <?php |
| 605 | } |
| 606 | |
| 607 | /** |
| 608 | * Check form inputs and start importing users |
| 609 | * |
| 610 | * @return type |
| 611 | */ |
| 612 | function step2() { |
| 613 | do_action( 'import_start' ); |
| 614 | |
| 615 | // Set time limit to 0 to avoid time out errors |
| 616 | set_time_limit( 0 ); |
| 617 | |
| 618 | if ( is_callable( 'ob_implicit_flush' ) ) |
| 619 | ob_implicit_flush( true ); |
| 620 | |
| 621 | update_option( 'bbp_bbpress_step', 2 ); |
| 622 | |
| 623 | $setup = $this->setup(); |
| 624 | if ( empty( $setup ) ) { |
| 625 | return false; |
| 626 | } elseif ( is_wp_error( $setup ) ) { |
| 627 | $this->throw_error( $setup, 2 ); |
| 628 | return false; |
| 629 | } |
| 630 | |
| 631 | global $wpdb, $bbdb; ?> |
| 632 | |
| 633 | <div id="bbpress-import-status"> |
| 634 | |
| 635 | <h3><?php _e( 'Importing Users', 'bbpress' ); ?></h3> |
| 636 | <p><?php _e( 'We’re in the process of migrating your users...', 'bbpress' ); ?></p> |
| 637 | |
| 638 | <ol> |
| 639 | |
| 640 | <?php |
| 641 | |
| 642 | // Drop the old temp tables while debugging |
| 643 | if ( $this->debug == true ) |
| 644 | $wpdb->query( "DROP TABLE IF EXISTS {$bbdb->prefix}{$wpdb->users}_tmp, {$bbdb->prefix}{$wpdb->usermeta}_tmp" ); |
| 645 | |
| 646 | // Rename the WordPress users and usermeta table |
| 647 | |
| 648 | ?> |
| 649 | |
| 650 | <li> |
| 651 | <?php |
| 652 | if ( $wpdb->query( "RENAME TABLE $wpdb->users TO {$bbdb->prefix}{$wpdb->users}_tmp, $wpdb->usermeta TO {$bbdb->prefix}{$wpdb->usermeta}_tmp" ) !== false ) : ?> |
| 653 | <?php printf( __( 'Renamed the <code>%1$s</code> and <code>%2$s</code> tables to <code>%3$s</code> and <code>%4$s</code> respectively.', 'bbpress' ), $wpdb->users, $wpdb->usermeta, $bbdb->prefix . $wpdb->users . '_tmp', $bbdb->prefix . $wpdb->usermeta . '_tmp' ); ?> |
| 654 | <?php else : ?> |
| 655 | <?php printf( __( 'There was a problem dropping the <code>%1$s</code> and <code>%2$s</code> tables. Please check and re-run the script or rename or drop the tables yourself.', 'bbpress' ), $wpdb->users, $wpdb->usermeta ); ?></li></ol> |
| 656 | <?php break; endif; ?> |
| 657 | </li> |
| 658 | |
| 659 | <?php /* Duplicate the WordPress users and usermeta table */ ?> |
| 660 | |
| 661 | <li> |
| 662 | <?php if ( $wpdb->query( "CREATE TABLE $wpdb->users ( `ID` BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `user_activation_key` VARCHAR( 60 ) NOT NULL DEFAULT '', KEY ( `user_login` ), KEY( `user_nicename` ) ) SELECT * FROM $bbdb->users ORDER BY `ID`" ) !== false ) : ?> |
| 663 | <?php printf( __( 'Created the <code>%s</code> table and copied the users from bbPress.', 'bbpress' ), $wpdb->users ); ?> |
| 664 | <?php else : ?> |
| 665 | <?php printf( __( 'There was a problem duplicating the table <code>%1$s</code> to <code>%2$s</code>. Please check and re-run the script or duplicate the table yourself.', 'bbpress' ), $bbdb->users, $wpdb->users ); ?></li></ol> |
| 666 | <?php break; endif; ?> |
| 667 | </li> |
| 668 | |
| 669 | <li> |
| 670 | <?php if ( $wpdb->query( "CREATE TABLE $wpdb->usermeta ( `umeta_id` BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, KEY ( `user_id` ), KEY( `meta_key` ) ) SELECT * FROM $bbdb->usermeta ORDER BY `umeta_id`" ) !== false ) : ?> |
| 671 | <?php printf( __( 'Created the <code>%s</code> table and copied the user information from bbPress.', 'bbpress' ), $wpdb->usermeta ); ?> |
| 672 | <?php else : ?> |
| 673 | <?php printf( __( 'There was a problem duplicating the table <code>%1$s</code> to <code>%2$s</code>. Please check and re-run the script or duplicate the table yourself.', 'bbpress' ), $bbdb->usermeta, $wpdb->usermeta ); ?></li></ol> |
| 674 | <?php break; endif; ?> |
| 675 | </li> |
| 676 | |
| 677 | <?php |
| 678 | |
| 679 | // Map the user roles by our wish |
| 680 | $roles_map = array( |
| 681 | 'keymaster' => 'administrator', |
| 682 | 'administrator' => 'bbp_moderator', |
| 683 | 'moderator' => 'bbp_moderator', |
| 684 | 'member' => get_option( 'default_role' ), |
| 685 | 'inactive' => get_option( 'default_role' ), |
| 686 | 'blocked' => get_option( 'default_role' ), |
| 687 | 'throttle' => 'throttle' |
| 688 | ); |
| 689 | |
| 690 | $wp_user_level_map = array( |
| 691 | 'administrator' => 10, |
| 692 | 'editor' => 7, |
| 693 | 'author' => 2, |
| 694 | 'contributor' => 1, |
| 695 | 'subscriber' => 0, |
| 696 | 'throttle' => 0 |
| 697 | ); |
| 698 | |
| 699 | // Apply the WordPress roles to the new users based on their bbPress roles |
| 700 | wp_cache_flush(); |
| 701 | $users = get_users( array( 'fields' => 'all_with_meta', 'orderby' => 'ID' ) ); |
| 702 | |
| 703 | foreach ( $users as $user ) { |
| 704 | |
| 705 | // Get the bbPress roles |
| 706 | $bb_roles =& $user->{ $bbdb->prefix . 'capabilities' }; |
| 707 | $converted_roles = $converted_level = array(); |
| 708 | |
| 709 | // Loop through each role the user has |
| 710 | foreach ( $bb_roles as $bb_role => $bb_role_value ) { |
| 711 | |
| 712 | // If we have one of those in our roles map, add the WP counterpart in the new roles array |
| 713 | if ( $roles_map[strtolower( $bb_role )] && !empty( $bb_role_value ) ) { |
| 714 | $converted_roles[$roles_map[strtolower( $bb_role )]] = true; |
| 715 | |
| 716 | // Have support for deprecated levels too |
| 717 | $converted_level[] = $wp_user_level_map[$roles_map[strtolower( $bb_role )]]; |
| 718 | |
| 719 | // We need an admin for future use |
| 720 | if ( empty( $admin_user ) && 'administrator' == $roles_map[strtolower( $bb_role )] ) |
| 721 | $admin_user = $user; |
| 722 | } |
| 723 | |
| 724 | } |
| 725 | |
| 726 | // If we have new roles, then update the user meta |
| 727 | if ( count( $converted_roles ) ) { |
| 728 | update_user_meta( $user->ID, $wpdb->prefix . 'capabilities', $converted_roles ); |
| 729 | update_user_meta( $user->ID, $wpdb->prefix . 'user_level', max( $converted_level ) ); |
| 730 | } |
| 731 | |
| 732 | } |
| 733 | |
| 734 | if ( empty( $admin_user ) || is_wp_error( $admin_user ) ) : /* I ask why */ ?> |
| 735 | |
| 736 | <li> |
| 737 | <?php _e( 'There was a problem in getting an administrator of the blog. Now, please go to your blog, set a user as administrator, login as that user and directly go to importing forums, topics and replies section. Note that old logins won\'t work, you would have to edit your database (you can still try logging in as the bbPress keymaster).', 'bbpress' ); ?> |
| 738 | </li> |
| 739 | |
| 740 | </ol> |
| 741 | |
| 742 | <?php |
| 743 | |
| 744 | break; |
| 745 | |
| 746 | endif; |
| 747 | |
| 748 | // Logout the user as it won't have any good privileges for us to do the work |
| 749 | // wp_clear_auth_cookie(); |
| 750 | |
| 751 | // Login the admin so that we have permissions for conversion etc |
| 752 | // wp_set_auth_cookie( $admin_user->ID ); |
| 753 | |
| 754 | // Set the current user |
| 755 | wp_set_current_user( $admin_user->ID, $admin_user->user_login ); |
| 756 | |
| 757 | ?> |
| 758 | |
| 759 | <li> |
| 760 | <?php printf( __( 'User roles have been successfully mapped based. The bbPress keymaster is WordPress administrator, bbPress administrator and moderators are moderators and rest all WordPress roles are %1$s. Now, you can only login into your WordPress blog by the bbPress credentials. For the time being, you have been logged in as the first available administrator (Username: %2$s, User ID: %3$s).', 'bbpress' ), get_option( 'default_role' ), $admin_user->user_login, $admin_user->ID ); ?> |
| 761 | </li> |
| 762 | |
| 763 | </ol> |
| 764 | |
| 765 | <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> |
| 766 | <?php |
| 767 | |
| 768 | echo $this->next_step( 3, __( 'Import by forums, topics and posts »', 'bbpress' ) ); ?> |
| 769 | |
| 770 | </div> |
| 771 | |
| 772 | <?php |
| 773 | } |
| 774 | |
| 775 | /** |
| 776 | * Import forums, topics and posts |
| 777 | */ |
| 778 | function step3() { |
| 779 | do_action( 'import_start' ); |
| 780 | |
| 781 | set_time_limit( 0 ); |
| 782 | update_option( 'bbp_bbpress_step', 3 ); |
| 783 | |
| 784 | $setup = $this->setup(); |
| 785 | if ( empty( $setup ) ) { |
| 786 | return false; |
| 787 | } elseif ( is_wp_error( $setup ) ) { |
| 788 | $this->throw_error( $setup, 3 ); |
| 789 | return false; |
| 790 | } |
| 791 | |
| 792 | global $wpdb, $bbdb, $bbp; ?> |
| 793 | |
| 794 | <div id="bbpress-import-status"> |
| 795 | |
| 796 | <h3><?php _e( 'Importing Forums, Topics And Posts', 'bbpress' ); ?></h3> |
| 797 | <p><?php _e( 'We’re importing your bbPress standalone forums, topics and replies...', 'bbpress' ); ?></p> |
| 798 | |
| 799 | <ol> |
| 800 | |
| 801 | <?php |
| 802 | |
| 803 | if ( !$forums = bb_get_forums() ) { |
| 804 | echo "<li><strong>" . __( 'No forums were found!', 'bbpress' ) . "</strong></li></ol>\n"; |
| 805 | break; |
| 806 | } |
| 807 | |
| 808 | if ( $this->debug == true ) |
| 809 | echo "<li>" . sprintf( __( 'Total number of forums: %s', 'bbpress' ), count( $forums ) ) . "</li>\n"; |
| 810 | |
| 811 | $forum_map = array(); |
| 812 | $post_statuses = array( 'publish', $bbp->trash_status_id, $bbp->spam_status_id ); |
| 813 | |
| 814 | foreach ( (array) $forums as $forum ) { |
| 815 | echo "<li>" . sprintf( __( 'Processing forum #%1$s (<a href="%2$s">%3$s</a>)', 'bbpress' ), $forum->forum_id, get_forum_link( $forum->forum_id ), esc_html( $forum->forum_name ) ) . "\n<ul>\n"; |
| 816 | |
| 817 | // Insert the forum and add it to the map. |
| 818 | $inserted_forum = wp_insert_post( array( |
| 819 | 'post_author' => get_current_user_id(), |
| 820 | 'post_content' => $forum->forum_desc, |
| 821 | 'post_title' => $forum->forum_name, |
| 822 | 'post_excerpt' => '', |
| 823 | 'post_status' => 'publish', |
| 824 | 'comment_status' => 'closed', |
| 825 | 'ping_status' => 'closed', |
| 826 | 'post_name' => $forum->forum_slug, |
| 827 | 'post_parent' => !empty( $forum->forum_parent ) ? $forum_map[$forum->forum_parent] : 0, |
| 828 | 'post_type' => bbp_get_forum_post_type(), |
| 829 | 'menu_order' => $forum->forum_order |
| 830 | ) ); |
| 831 | |
| 832 | $forum_map[$forum->forum_id] = $inserted_forum; |
| 833 | |
| 834 | if ( !empty( $inserted_forum ) && !is_wp_error( $inserted_forum ) ) { |
| 835 | echo "<li>" . sprintf( __( 'Added the forum as forum #<a href="%1$s">%2$s</a>', 'bbpress' ), get_permalink( $inserted_forum ), $inserted_forum ) . "</li>\n"; |
| 836 | } else { |
| 837 | echo "<li><em>" . __( 'There was a problem in adding the forum.', 'bbpress' ) . "</em></li></ul></li>\n"; |
| 838 | continue; |
| 839 | } |
| 840 | |
| 841 | $topics_query = new BB_Query( 'topic', array( |
| 842 | 'forum_id' => $forum->forum_id, |
| 843 | 'per_page' => -1, |
| 844 | 'topic_status' => 'all' |
| 845 | ) ); |
| 846 | |
| 847 | $topics = $topics_query->results; |
| 848 | |
| 849 | // In standalone, categories can have topics, but this is not the case in plugin |
| 850 | // So make the forum category if it doesn't have topics |
| 851 | // Else close it if it's a category and has topics |
| 852 | if ( bb_get_forum_is_category( $forum->forum_id ) ) { |
| 853 | |
| 854 | if ( count( $topics ) == 0 ) { |
| 855 | bbp_categorize_forum( $inserted_forum ); |
| 856 | echo "<li>" . __( 'The forum is a category and has no topics.', 'bbpress' ) . "</li>\n</ul>\n</li>"; |
| 857 | |
| 858 | continue; |
| 859 | } else { |
| 860 | bbp_close_forum( $inserted_forum ); |
| 861 | echo "<li>" . __( 'The forum is a category but has topics, so it has been set as closed on the new board.', 'bbpress' ) . "</li>\n"; |
| 862 | } |
| 863 | |
| 864 | } |
| 865 | |
| 866 | bb_cache_first_posts( $topics ); |
| 867 | |
| 868 | if ( $this->debug == true ) |
| 869 | echo "<li>" . sprintf( __( 'Total number of topics in the forum: %s', 'bbpress' ), count( $topics ) ) . "</li>\n"; |
| 870 | |
| 871 | foreach ( (array) $topics as $topic ) { |
| 872 | $first_post = bb_get_first_post( $topic->topic_id ); |
| 873 | |
| 874 | // If the topic is public, check if it's open and set the status accordingly |
| 875 | $topic_status = $topic->topic_status == 0 ? ( $topic->topic_open == 0 ? $bbp->closed_status_id : $post_statuses[$topic->topic_status] ) : $post_statuses[$topic->topic_status]; |
| 876 | |
| 877 | $inserted_topic = wp_insert_post( array( |
| 878 | 'post_parent' => $inserted_forum, |
| 879 | 'post_author' => $topic->topic_poster, |
| 880 | 'post_content' => $first_post->post_text, |
| 881 | 'post_title' => $topic->topic_title, |
| 882 | 'post_name' => $topic->topic_slug, |
| 883 | 'post_status' => $topic_status, |
| 884 | 'post_date_gmt' => $topic->topic_start_time, |
| 885 | 'post_date' => get_date_from_gmt( $topic->topic_start_time ), |
| 886 | 'post_type' => bbp_get_topic_post_type(), |
| 887 | 'tax_input' => array( 'topic-tag' => array_map( array( $this, 'get_tag_name' ), bb_get_public_tags( $topic->topic_id ) ) ) |
| 888 | ) ); |
| 889 | |
| 890 | if ( !empty( $inserted_topic ) && !is_wp_error( $inserted_topic ) ) { |
| 891 | |
| 892 | // Loginless Posting |
| 893 | if ( $topic->topic_poster == 0 ) { |
| 894 | update_post_meta( $inserted_topic, '_bbp_anonymous_name', bb_get_post_meta( 'post_author', $first_post->post_id ) ); |
| 895 | update_post_meta( $inserted_topic, '_bbp_anonymous_email', bb_get_post_meta( 'post_email', $first_post->post_id ) ); |
| 896 | update_post_meta( $inserted_topic, '_bbp_anonymous_website', bb_get_post_meta( 'post_url', $first_post->post_id ) ); |
| 897 | } |
| 898 | |
| 899 | // Author IP |
| 900 | update_post_meta( $inserted_topic, '_bbp_author_ip', $first_post->poster_ip ); |
| 901 | |
| 902 | // Forum topic meta |
| 903 | update_post_meta( $inserted_topic, '_bbp_forum_id', $inserted_forum ); |
| 904 | update_post_meta( $inserted_topic, '_bbp_topic_id', $inserted_topic ); |
| 905 | |
| 906 | $posts = bb_cache_posts( $bbdb->prepare( 'SELECT * FROM ' . $bbdb->posts . ' WHERE topic_id = %d AND post_id != %d ORDER BY post_time', $topic->topic_id, $first_post->post_id ) ); |
| 907 | |
| 908 | $replies = 0; |
| 909 | $hidden_replies = 0; |
| 910 | $last_reply = 0; |
| 911 | $post = null; |
| 912 | |
| 913 | foreach ( (array) $posts as $post ) { |
| 914 | |
| 915 | // Pingback |
| 916 | if ( $post->poster_id == 0 && $pingback_uri = bb_get_post_meta( 'pingback_uri', $post->post_id ) ) { |
| 917 | $pingback = wp_insert_comment( wp_filter_comment( array( |
| 918 | 'comment_post_ID' => $inserted_topic, |
| 919 | 'comment_author' => bb_get_post_meta( 'pingback_title', $post->post_id ), |
| 920 | 'comment_author_url' => $pingback_uri, |
| 921 | 'comment_author_IP' => $post->poster_ip, |
| 922 | 'comment_date_gmt' => $post->post_time, |
| 923 | 'comment_date' => get_date_from_gmt( $post->post_time ), |
| 924 | 'comment_content' => $post->post_text, |
| 925 | 'comment_approved' => $post->post_status == 0 ? 1 : ( $post->post_status == 2 ? 'spam' : 0 ), |
| 926 | 'comment_type' => 'pingback' |
| 927 | ) ) ); |
| 928 | |
| 929 | // Normal post |
| 930 | } else { |
| 931 | $reply_title = sprintf( __( 'Reply To: %s', 'bbpress' ), $topic->topic_title ); |
| 932 | |
| 933 | $last_reply = wp_insert_post( array( |
| 934 | 'post_parent' => $inserted_topic, |
| 935 | 'post_author' => $post->poster_id, |
| 936 | 'post_date_gmt' => $post->post_time, |
| 937 | 'post_date' => get_date_from_gmt( $post->post_time ), |
| 938 | 'post_title' => $reply_title, |
| 939 | 'post_name' => sanitize_title_with_dashes( $reply_title ), |
| 940 | 'post_status' => $post_statuses[$post->post_status], |
| 941 | 'post_type' => bbp_get_reply_post_type(), |
| 942 | 'post_content' => $post->post_text |
| 943 | ) ); |
| 944 | |
| 945 | // Loginless |
| 946 | if ( $post->poster_id == 0 ) { |
| 947 | update_post_meta( $last_reply, '_bbp_anonymous_name', bb_get_post_meta( 'post_author', $post->post_id ) ); |
| 948 | update_post_meta( $last_reply, '_bbp_anonymous_email', bb_get_post_meta( 'post_email', $post->post_id ) ); |
| 949 | update_post_meta( $last_reply, '_bbp_anonymous_website', bb_get_post_meta( 'post_url', $post->post_id ) ); |
| 950 | } |
| 951 | |
| 952 | // Author IP |
| 953 | update_post_meta( $last_reply, '_bbp_author_ip', $post->poster_ip ); |
| 954 | |
| 955 | // Reply Parents |
| 956 | update_post_meta( $last_reply, '_bbp_forum_id', $inserted_forum ); |
| 957 | update_post_meta( $last_reply, '_bbp_topic_id', $inserted_topic ); |
| 958 | |
| 959 | bbp_update_reply_walker( $last_reply ); |
| 960 | } |
| 961 | |
| 962 | $replies++; |
| 963 | |
| 964 | if ( $post->post_status != 0 ) |
| 965 | $hidden_replies++; |
| 966 | } |
| 967 | |
| 968 | // Only add favorites and subscriptions if the topic is public |
| 969 | if ( in_array( $topic_status, array( 'publish', $bbp->closed_status_id ) ) ) { |
| 970 | |
| 971 | // Favorites |
| 972 | foreach ( (array) $this->bb_get_topic_favoriters( $topic->topic_id ) as $favoriter ) |
| 973 | bbp_add_user_favorite ( $favoriter, $inserted_topic ); |
| 974 | |
| 975 | // Subscriptions |
| 976 | foreach ( (array) $this->bb_get_topic_subscribers( $topic->topic_id ) as $subscriber ) |
| 977 | bbp_add_user_subscription( $subscriber, $inserted_topic ); |
| 978 | } |
| 979 | |
| 980 | // Topic stickiness |
| 981 | switch ( $topic->topic_sticky ) { |
| 982 | |
| 983 | // Forum |
| 984 | case 1 : |
| 985 | bbp_stick_topic( $inserted_topic ); |
| 986 | break; |
| 987 | |
| 988 | // Front |
| 989 | case 2 : |
| 990 | bbp_stick_topic( $inserted_topic, true ); |
| 991 | break; |
| 992 | } |
| 993 | |
| 994 | // Last active time |
| 995 | $last_active = $post ? $post->post_time : $first_post->post_time; |
| 996 | |
| 997 | // Reply topic meta |
| 998 | update_post_meta( $inserted_topic, '_bbp_last_reply_id', $last_reply ); |
| 999 | update_post_meta( $inserted_topic, '_bbp_last_active_id', $last_reply ? $last_reply : $inserted_topic ); |
| 1000 | update_post_meta( $inserted_topic, '_bbp_last_active_time', $topic->topic_time ); |
| 1001 | update_post_meta( $inserted_topic, '_bbp_reply_count', $replies - $hidden_replies ); |
| 1002 | update_post_meta( $inserted_topic, '_bbp_hidden_reply_count', $hidden_replies ); |
| 1003 | // Voices will be done by recount |
| 1004 | |
| 1005 | bbp_update_topic_walker( $inserted_topic ); |
| 1006 | |
| 1007 | echo "<li>" . sprintf( __( 'Added topic #%1$s (<a href="%2$s">%3$s</a>) as topic #<a href="%4$s">%5$s</a> with %6$s replies.', 'bbpress' ), $topic->topic_id, get_topic_link( $topic->topic_id ), esc_html( $topic->topic_title ), get_permalink( $inserted_topic ), $inserted_topic, $replies ) . "</li>\n"; |
| 1008 | } else { |
| 1009 | echo "<li><em>" . sprintf( __( 'There was a problem in adding topic #1$s (<a href="%2$s">%3$s</a>).', 'bbpress' ), $topic->topic_id, get_topic_link( $topic->topic_id ), esc_html( $topic->topic_title ) ) . "</em></li></ul></li>\n"; |
| 1010 | continue; |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | echo "</ul>\n</li>\n"; |
| 1015 | |
| 1016 | } ?> |
| 1017 | |
| 1018 | </ol> |
| 1019 | |
| 1020 | <?php |
| 1021 | |
| 1022 | // Clean up database and we're out |
| 1023 | $this->cleanup(); |
| 1024 | do_action( 'import_done', 'bbpress' ); |
| 1025 | |
| 1026 | ?> |
| 1027 | |
| 1028 | <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> |
| 1029 | |
| 1030 | <h4><?php printf( __( 'After that it\'s all done. <a href="%s">Have fun!</a> :)', 'bbpress' ), home_url() ); ?></h4> |
| 1031 | |
| 1032 | </div> |
| 1033 | |
| 1034 | <?php |
| 1035 | } |
| 1036 | |
| 1037 | } // class bbPress_Importer |
| 1038 | |
| 1039 | $bbpress_import = new bbPress_Importer(); |
| 1040 | |
| 1041 | register_importer( 'bbpress', __( 'bbPress Standalone', 'bbpress' ), __( 'Import your bbPress standalone board.', 'bbpress' ), array( $bbpress_import, 'dispatch' ) ); |
| 1042 | |
| 1043 | ?> |