| | 1 | <?php |
| | 2 | |
| | 3 | /** |
| | 4 | * bbPress Repair Tools |
| | 5 | * |
| | 6 | * @package bbPress |
| | 7 | * @subpackage Administration |
| | 8 | */ |
| | 9 | |
| | 10 | // Exit if accessed directly. |
| | 11 | defined( 'ABSPATH' ) || exit; |
| | 12 | |
| | 13 | /** |
| | 14 | * Main BBP_Repair_Tools Class |
| | 15 | */ |
| | 16 | class BBP_Repair_Tools { |
| | 17 | |
| | 18 | /** |
| | 19 | * The main bbPress repair tools loader |
| | 20 | * |
| | 21 | * @since 2.6.0 bbPress (rXXXX) |
| | 22 | */ |
| | 23 | public function __construct() { |
| | 24 | |
| | 25 | // 'I wonder where I'll float next.' |
| | 26 | if ( empty( $_SERVER['REQUEST_METHOD'] ) ) { |
| | 27 | return; |
| | 28 | } |
| | 29 | |
| | 30 | // Bail if request is not correct. |
| | 31 | switch ( strtoupper( $_SERVER['REQUEST_METHOD'] ) ) { |
| | 32 | |
| | 33 | // Repair tools are running. |
| | 34 | case 'POST' : |
| | 35 | if ( ( empty( $_POST['action'] ) || ( 'bbp_repair_tool_process' != $_POST['action'] ) ) ) { |
| | 36 | return; |
| | 37 | } |
| | 38 | |
| | 39 | break; |
| | 40 | |
| | 41 | // Some other admin page. |
| | 42 | case 'GET' : |
| | 43 | if ( ( empty( $_GET['page'] ) || ( 'bbp-repair' != $_GET['page'] ) ) ) { |
| | 44 | return; |
| | 45 | } |
| | 46 | |
| | 47 | break; |
| | 48 | } |
| | 49 | |
| | 50 | // Proceed with the actions. |
| | 51 | $this->setup_actions(); |
| | 52 | } |
| | 53 | |
| | 54 | /** |
| | 55 | * Setup the default actions |
| | 56 | * |
| | 57 | * @since 2.6.0 bbPress (rXXXX) |
| | 58 | */ |
| | 59 | private function setup_actions() { |
| | 60 | |
| | 61 | // Attach to the admin head with our ajax requests cycle and css. |
| | 62 | add_action( 'bbp_admin_head', array( $this, 'admin_head' ) ); |
| | 63 | |
| | 64 | // Attach the repair tool admin settings action to the WordPress admin init action. |
| | 65 | add_action( 'bbp_register_admin_settings', array( $this, 'register_admin_settings' ) ); |
| | 66 | |
| | 67 | // Attach to the admin ajax request to process cycles. |
| | 68 | add_action( 'wp_ajax_bbp_repair_tool_process', array( $this, 'process_callback' ) ); |
| | 69 | } |
| | 70 | |
| | 71 | /** |
| | 72 | * Register the settings |
| | 73 | * |
| | 74 | * @since 2.6.0 bbPress (rXXXX) |
| | 75 | */ |
| | 76 | public function register_admin_settings() { |
| | 77 | |
| | 78 | // Add the main section. |
| | 79 | add_settings_section( 'bbpress_repair_tool_main', __( 'Repair Tools Settings', 'bbpress' ), 'bbp_repair_tool_setting_callback_main_section', 'bbpress_repair_tool' ); |
| | 80 | |
| | 81 | // Rows Limit. |
| | 82 | add_settings_field( '_bbp_repair_tool_rows', __( 'Rows Limit', 'bbpress' ), 'bbp_repair_tool_setting_callback_rows', 'bbpress_repair_tool', 'bbpress_repair_tool_main' ); |
| | 83 | register_setting ( 'bbpress_repair_tool_main', '_bbp_repair_tool_rows', 'intval' ); |
| | 84 | |
| | 85 | // Delay Time. |
| | 86 | add_settings_field( '_bbp_repair_tool_delay_time', __( 'Delay Time', 'bbpress' ), 'bbp_repair_tool_setting_callback_delay_time', 'bbpress_repair_tool', 'bbpress_repair_tool_main' ); |
| | 87 | register_setting ( 'bbpress_repair_tool_main', '_bbp_repair_tool_delay_time', 'intval' ); |
| | 88 | } |
| | 89 | |
| | 90 | /** |
| | 91 | * Admin scripts |
| | 92 | * |
| | 93 | * @since 2.6.0 bbPress (rXXXX) |
| | 94 | */ |
| | 95 | public function admin_head() { ?> |
| | 96 | |
| | 97 | <style type="text/css" media="screen"> |
| | 98 | /*<![CDATA[*/ |
| | 99 | |
| | 100 | div.bbp-repair-tool-updated, |
| | 101 | div.bbp-repair-tool-warning { |
| | 102 | border-radius: 3px 3px 3px 3px; |
| | 103 | border-style: solid; |
| | 104 | border-width: 1px; |
| | 105 | padding: 5px 5px 5px 5px; |
| | 106 | } |
| | 107 | |
| | 108 | div.bbp-repair-tool-updated { |
| | 109 | height: 300px; |
| | 110 | overflow: auto; |
| | 111 | display: none; |
| | 112 | background-color: #FFFFE0; |
| | 113 | border-color: #E6DB55; |
| | 114 | font-family: monospace; |
| | 115 | font-weight: bold; |
| | 116 | } |
| | 117 | |
| | 118 | div.bbp-repair-tool-updated p { |
| | 119 | margin: 0.5em 0; |
| | 120 | padding: 2px; |
| | 121 | float: left; |
| | 122 | clear: left; |
| | 123 | } |
| | 124 | |
| | 125 | div.bbp-repair-tool-updated p.loading { |
| | 126 | padding: 2px 20px 2px 2px; |
| | 127 | background-image: url('<?php echo admin_url(); ?>images/wpspin_light.gif'); |
| | 128 | background-repeat: no-repeat; |
| | 129 | background-position: center right; |
| | 130 | } |
| | 131 | |
| | 132 | #bbp-repair-tool-stop { |
| | 133 | display:none; |
| | 134 | } |
| | 135 | |
| | 136 | #bbp-repair-tool-progress { |
| | 137 | display:none; |
| | 138 | } |
| | 139 | |
| | 140 | /*]]>*/ |
| | 141 | </style> |
| | 142 | |
| | 143 | <script language="javascript"> |
| | 144 | |
| | 145 | var bbp_repair_tool_is_running = false; |
| | 146 | var bbp_repair_tool_run_timer; |
| | 147 | var bbp_repair_tool_delay_time = 0; |
| | 148 | |
| | 149 | function bbp_repair_tool_grab_data() { |
| | 150 | var values = {}; |
| | 151 | jQuery.each(jQuery('#bbp-repair-tool-settings').serializeArray(), function(i, field) { |
| | 152 | values[field.name] = field.value; |
| | 153 | }); |
| | 154 | |
| | 155 | if( values['_bbp_repair_tool_restart'] ) { |
| | 156 | jQuery('#_bbp_repair_tool_restart').removeAttr("checked"); |
| | 157 | } |
| | 158 | |
| | 159 | if( values['_bbp_repair_tool_delay_time'] ) { |
| | 160 | bbp_repair_tool_delay_time = values['_bbp_repair_tool_delay_time'] * 1000; |
| | 161 | } |
| | 162 | |
| | 163 | values['action'] = 'bbp_repair_tool_process'; |
| | 164 | values['_ajax_nonce'] = '<?php echo wp_create_nonce( 'bbp_repair_tool_process' ); ?>'; |
| | 165 | |
| | 166 | return values; |
| | 167 | } |
| | 168 | |
| | 169 | function bbp_repair_tool_start() { |
| | 170 | if( false === bbp_repair_tool_is_running ) { |
| | 171 | bbp_repair_tool_is_running = true; |
| | 172 | jQuery('#bbp-repair-tool-start').hide(); |
| | 173 | jQuery('#bbp-repair-tool-stop').show(); |
| | 174 | jQuery('#bbp-repair-tool-progress').show(); |
| | 175 | bbp_repair_tool_log( '<p class="loading"><?php esc_html_e( 'Starting Repair', 'bbpress' ); ?></p>' ); |
| | 176 | bbp_repair_tool_run(); |
| | 177 | } |
| | 178 | } |
| | 179 | |
| | 180 | function bbp_repair_tool_run() { |
| | 181 | jQuery.post(ajaxurl, bbp_repair_tool_grab_data(), function(response) { |
| | 182 | var response_length = response.length - 1; |
| | 183 | response = response.substring(0,response_length); |
| | 184 | bbp_repair_tool_success(response); |
| | 185 | }); |
| | 186 | } |
| | 187 | |
| | 188 | function bbp_repair_tool_stop() { |
| | 189 | jQuery('#bbp-repair-tool-start').show(); |
| | 190 | jQuery('#bbp-repair-tool-stop').hide(); |
| | 191 | jQuery('#bbp-repair-tool-progress').hide(); |
| | 192 | jQuery('#bbp-repair-tool-message p').removeClass( 'loading' ); |
| | 193 | bbp_repair_tool_is_running = false; |
| | 194 | clearTimeout( bbp_repair_tool_run_timer ); |
| | 195 | } |
| | 196 | |
| | 197 | function bbp_repair_tool_success(response) { |
| | 198 | bbp_repair_tool_log(response); |
| | 199 | |
| | 200 | if ( response === '<p class="loading"><?php esc_html_e( 'Conversion Complete', 'bbpress' ); ?></p>' || response.indexOf('error') > -1 ) { |
| | 201 | bbp_repair_tool_log('<p>Repair any missing information: <a href="<?php echo admin_url(); ?>tools.php?page=bbp-repair">Continue</a></p>'); |
| | 202 | bbp_repair_tool_stop(); |
| | 203 | } else if( bbp_repair_tool_is_running ) { // keep going |
| | 204 | jQuery('#bbp-repair-tool-progress').show(); |
| | 205 | clearTimeout( bbp_repair_tool_run_timer ); |
| | 206 | bbp_repair_tool_run_timer = setTimeout( 'bbp_repair_tool_run()', bbp_repair_tool_delay_time ); |
| | 207 | } else { |
| | 208 | bbp_repair_tool_stop(); |
| | 209 | } |
| | 210 | } |
| | 211 | |
| | 212 | function bbp_repair_tool_log(text) { |
| | 213 | if ( jQuery('#bbp-repair-tool-message').css('display') === 'none' ) { |
| | 214 | jQuery('#bbp-repair-tool-message').show(); |
| | 215 | } |
| | 216 | if ( text ) { |
| | 217 | jQuery('#bbp-repair-tool-message p').removeClass( 'loading' ); |
| | 218 | jQuery('#bbp-repair-tool-message').prepend( text ); |
| | 219 | } |
| | 220 | } |
| | 221 | |
| | 222 | </script> |
| | 223 | |
| | 224 | <?php |
| | 225 | } |
| | 226 | |
| | 227 | /** |
| | 228 | * Wrap the repair tool output in paragraph tags, so styling can be applied |
| | 229 | * |
| | 230 | * @since 2.6.0 bbPress (rXXXX) |
| | 231 | * |
| | 232 | * @param string $output |
| | 233 | */ |
| | 234 | private static function repair_tool_output( $output = '' ) { |
| | 235 | |
| | 236 | // Get the last query. |
| | 237 | $before = '<p class="loading">'; |
| | 238 | $after = '</p>'; |
| | 239 | $query = get_option( '_bbp_repair_tool_query' ); |
| | 240 | |
| | 241 | if ( ! empty( $query ) ) { |
| | 242 | $before = '<p class="loading" title="' . esc_attr( $query ) . '">'; |
| | 243 | } |
| | 244 | |
| | 245 | echo $before . $output . $after; |
| | 246 | } |
| | 247 | |
| | 248 | /** |
| | 249 | * Callback processor |
| | 250 | * |
| | 251 | * @since 2.6.0 bbPress (rXXXX) |
| | 252 | */ |
| | 253 | public function process_callback() { |
| | 254 | |
| | 255 | // Bail if user cannot view import page. |
| | 256 | if ( ! current_user_can( 'bbp_tools_import_page' ) ) { |
| | 257 | wp_die( '0' ); |
| | 258 | } |
| | 259 | |
| | 260 | // Verify intent. |
| | 261 | check_ajax_referer( 'bbp_repair_tool_process' ); |
| | 262 | |
| | 263 | if ( ! ini_get( 'safe_mode' ) ) { |
| | 264 | set_time_limit( 0 ); |
| | 265 | ini_set( 'memory_limit', '256M' ); |
| | 266 | ini_set( 'implicit_flush', '1' ); |
| | 267 | ignore_user_abort( true ); |
| | 268 | } |
| | 269 | |
| | 270 | // Save step and count so that it can be restarted. |
| | 271 | if ( ! get_option( '_bbp_repair_tool_step' ) || ( ! empty( $_POST['_bbp_repair_tool_restart'] ) ) ) { |
| | 272 | update_option( '_bbp_repair_tool_step', 1 ); |
| | 273 | update_option( '_bbp_repair_tool_start', 0 ); |
| | 274 | } |
| | 275 | |
| | 276 | $step = (int) get_option( '_bbp_repair_tool_step', 1 ); |
| | 277 | $min = (int) get_option( '_bbp_repair_tool_start', 0 ); |
| | 278 | $count = (int) ! empty( $_POST['_bbp_repair_tool_rows'] ) ? $_POST['_bbp_repair_tool_rows'] : 100; |
| | 279 | $max = ( $min + $count ) - 1; |
| | 280 | $start = $min; |
| | 281 | |
| | 282 | // Bail if platform did not get saved. |
| | 283 | $platform = ! empty( $_POST['_bbp_repair_tool_platform' ] ) ? $_POST['_bbp_repair_tool_platform' ] : get_option( '_bbp_repair_tool_platform' ); |
| | 284 | if ( empty( $platform ) ) { |
| | 285 | return; |
| | 286 | } |
| | 287 | |
| | 288 | // Include the appropriate repair tool. |
| | 289 | $repair_tool = bbp_new_repair( $platform ); |
| | 290 | |
| | 291 | switch ( $step ) { |
| | 292 | |
| | 293 | // STEP 1. Clean all tables. |
| | 294 | case 1 : |
| | 295 | if ( ! empty( $_POST['_bbp_repair_tool_clean'] ) ) { |
| | 296 | if ( $repair_tool->clean( $start ) ) { |
| | 297 | update_option( '_bbp_repair_tool_step', $step + 1 ); |
| | 298 | update_option( '_bbp_repair_tool_start', 0 ); |
| | 299 | $this->sync_table( true ); |
| | 300 | if ( empty( $start ) ) { |
| | 301 | $this->repair_tool_output( __( 'No data to clean', 'bbpress' ) ); |
| | 302 | } |
| | 303 | } else { |
| | 304 | update_option( '_bbp_repair_tool_start', $max + 1 ); |
| | 305 | $this->repair_tool_output( sprintf( __( 'Deleting previously converted data (%1$s - %2$s)', 'bbpress' ), $min, $max ) ); |
| | 306 | } |
| | 307 | } else { |
| | 308 | update_option( '_bbp_repair_tool_step', $step + 1 ); |
| | 309 | update_option( '_bbp_repair_tool_start', 0 ); |
| | 310 | } |
| | 311 | |
| | 312 | break; |
| | 313 | |
| | 314 | // STEP 18. Convert forum subscriptions. |
| | 315 | case 18 : |
| | 316 | if ( $repair_tool->convert_forum_subscriptions_test01( $start ) ) { |
| | 317 | update_option( '_bbp_repair_tool_step', $step + 1 ); |
| | 318 | update_option( '_bbp_repair_tool_start', 0 ); |
| | 319 | if ( empty( $start ) ) { |
| | 320 | $this->repair_tool_output( __( 'No forum subscriptions to convert', 'bbpress' ) ); |
| | 321 | } |
| | 322 | } else { |
| | 323 | update_option( '_bbp_repair_tool_start', $max + 1 ); |
| | 324 | $this->repair_tool_output( sprintf( __( 'Converting forum subscriptions (%1$s - %2$s)', 'bbpress' ), $min, $max ) ); |
| | 325 | } |
| | 326 | |
| | 327 | break; |
| | 328 | |
| | 329 | |
| | 330 | // STEP 19. Convert topic subscriptions. |
| | 331 | case 19 : |
| | 332 | if ( $repair_tool->convert_topic_subscriptions_tes01( $start ) ) { |
| | 333 | update_option( '_bbp_repair_tool_step', $step + 1 ); |
| | 334 | update_option( '_bbp_repair_tool_start', 0 ); |
| | 335 | if ( empty( $start ) ) { |
| | 336 | $this->repair_tool_output( __( 'No topic subscriptions to convert', 'bbpress' ) ); |
| | 337 | } |
| | 338 | } else { |
| | 339 | update_option( '_bbp_repair_tool_start', $max + 1 ); |
| | 340 | $this->repair_tool_output( sprintf( __( 'Converting topic subscriptions (%1$s - %2$s)', 'bbpress' ), $min, $max ) ); |
| | 341 | } |
| | 342 | |
| | 343 | break; |
| | 344 | |
| | 345 | // STEP 20. Convert topic favorites. |
| | 346 | case 20 : |
| | 347 | if ( $repair_tool->convert_favorites_test01( $start ) ) { |
| | 348 | update_option( '_bbp_repair_tool_step', $step + 1 ); |
| | 349 | update_option( '_bbp_repair_tool_start', 0 ); |
| | 350 | if ( empty( $start ) ) { |
| | 351 | $this->repair_tool_output( __( 'No favorites to convert', 'bbpress' ) ); |
| | 352 | } |
| | 353 | } else { |
| | 354 | update_option( '_bbp_repair_tool_start', $max + 1 ); |
| | 355 | $this->repair_tool_output( sprintf( __( 'Converting favorites (%1$s - %2$s)', 'bbpress' ), $min, $max ) ); |
| | 356 | } |
| | 357 | |
| | 358 | break; |
| | 359 | |
| | 360 | default : |
| | 361 | delete_option( '_bbp_repair_tool_step' ); |
| | 362 | delete_option( '_bbp_repair_tool_start' ); |
| | 363 | delete_option( '_bbp_repair_tool_query' ); |
| | 364 | |
| | 365 | $this->repair_tool_output( __( 'Repair tools complete', 'bbpress' ) ); |
| | 366 | |
| | 367 | break; |
| | 368 | } |
| | 369 | } |
| | 370 | |
| | 371 | /** |
| | 372 | * Create Tables for fast syncing |
| | 373 | * |
| | 374 | * @since 2.6.0 bbPress (rXXXX) |
| | 375 | */ |
| | 376 | public function sync_table( $drop = false ) { |
| | 377 | |
| | 378 | $bbp_db = bbp_db(); |
| | 379 | $table_name = $bbp_db->prefix . 'bbp_repair_tool_translator'; |
| | 380 | if ( ! empty( $drop ) && $bbp_db->get_var( "SHOW TABLES LIKE '{$table_name}'" ) === $table_name ) { |
| | 381 | $bbp_db->query( "DROP TABLE {$table_name}" ); |
| | 382 | } |
| | 383 | |
| | 384 | require_once( ABSPATH . '/wp-admin/includes/upgrade.php' ); |
| | 385 | |
| | 386 | if ( ! empty( $bbp_db->charset ) ) { |
| | 387 | $charset_collate = "DEFAULT CHARACTER SET $bbp_db->charset"; |
| | 388 | } |
| | 389 | |
| | 390 | if ( ! empty( $bbp_db->collate ) ) { |
| | 391 | $charset_collate .= " COLLATE $bbp_db->collate"; |
| | 392 | } |
| | 393 | |
| | 394 | $sql = array(); |
| | 395 | $max_index_length = 191; |
| | 396 | |
| | 397 | /** Translator ********************************************************/ |
| | 398 | |
| | 399 | $sql[] = "CREATE TABLE {$table_name} ( |
| | 400 | meta_id mediumint(8) unsigned not null auto_increment, |
| | 401 | value_type varchar(25) null, |
| | 402 | value_id bigint(20) unsigned not null default '0', |
| | 403 | meta_key varchar(255) null, |
| | 404 | meta_value varchar(255) null, |
| | 405 | PRIMARY KEY (meta_id), |
| | 406 | KEY value_id (value_id), |
| | 407 | KEY meta_join (meta_key({$max_index_length}), meta_value({$max_index_length})) |
| | 408 | ) {$charset_collate};"; |
| | 409 | |
| | 410 | dbDelta( $sql ); |
| | 411 | } |
| | 412 | } |
| | 413 | |
| | 414 | /** |
| | 415 | * Base class to be extended by specific individual importers |
| | 416 | * |
| | 417 | * @since 2.1.0 bbPress (r3813) |
| | 418 | */ |
| | 419 | abstract class BBP_Repair_Tools_Base { |
| | 420 | |
| | 421 | /** |
| | 422 | * @var array() This is the field mapping array to process. |
| | 423 | */ |
| | 424 | protected $field_map = array(); |
| | 425 | |
| | 426 | /** |
| | 427 | * @var object This is the connection to the WordPress database. |
| | 428 | */ |
| | 429 | protected $wpdb; |
| | 430 | |
| | 431 | /** |
| | 432 | * @var object This is the connection to the other platforms database. |
| | 433 | */ |
| | 434 | protected $opdb; |
| | 435 | |
| | 436 | /** |
| | 437 | * @var int This is the max rows to process at a time. |
| | 438 | */ |
| | 439 | public $max_rows; |
| | 440 | |
| | 441 | /** |
| | 442 | * @var array() Map of topic to forum. It is for optimization. |
| | 443 | */ |
| | 444 | private $map_topicid_to_forumid = array(); |
| | 445 | |
| | 446 | /** |
| | 447 | * @var array() Map of from old forum ids to new forum ids. It is for optimization. |
| | 448 | */ |
| | 449 | private $map_forumid = array(); |
| | 450 | |
| | 451 | /** |
| | 452 | * @var array() Map of from old topic ids to new topic ids. It is for optimization. |
| | 453 | */ |
| | 454 | private $map_topicid = array(); |
| | 455 | |
| | 456 | /** |
| | 457 | * @var array() Map of from old reply_to ids to new reply_to ids. It is for optimization. |
| | 458 | */ |
| | 459 | private $map_reply_to = array(); |
| | 460 | |
| | 461 | /** |
| | 462 | * @var array() Map of from old user ids to new user ids. It is for optimization. |
| | 463 | */ |
| | 464 | private $map_userid = array(); |
| | 465 | |
| | 466 | /** |
| | 467 | * @var str This is the charset for your wp database. |
| | 468 | */ |
| | 469 | public $charset; |
| | 470 | |
| | 471 | /** |
| | 472 | * @var boolean Sync table available. |
| | 473 | */ |
| | 474 | public $sync_table = false; |
| | 475 | |
| | 476 | /** |
| | 477 | * @var str Sync table name. |
| | 478 | */ |
| | 479 | public $sync_table_name; |
| | 480 | |
| | 481 | /** Methods ***************************************************************/ |
| | 482 | |
| | 483 | /** |
| | 484 | * This is the constructor and it connects to the platform databases. |
| | 485 | * |
| | 486 | * @since 2.6.0 bbPress (rXXXX) |
| | 487 | */ |
| | 488 | public function __construct() { |
| | 489 | $this->setup_globals(); |
| | 490 | } |
| | 491 | |
| | 492 | /** |
| | 493 | * [setup_globals description] |
| | 494 | * |
| | 495 | * @since 2.6.0 bbPress (rXXXX) |
| | 496 | */ |
| | 497 | private function setup_globals() { |
| | 498 | |
| | 499 | /** Get database connections ******************************************/ |
| | 500 | |
| | 501 | $this->wpdb = bbp_db(); |
| | 502 | $this->max_rows = (int) $_POST['_bbp_repair_tool_rows']; |
| | 503 | $this->opdb = new wpdb( $_POST['_bbp_repair_tool_db_user'], $_POST['_bbp_repair_tool_db_pass'], $_POST['_bbp_repair_tool_db_name'], $_POST['_bbp_repair_tool_db_server'] ); |
| | 504 | $this->opdb->prefix = $_POST['_bbp_repair_tool_db_prefix']; |
| | 505 | |
| | 506 | /** |
| | 507 | * Error Reporting |
| | 508 | */ |
| | 509 | $this->wpdb->show_errors(); |
| | 510 | $this->opdb->show_errors(); |
| | 511 | |
| | 512 | /** |
| | 513 | * Syncing |
| | 514 | */ |
| | 515 | $this->sync_table_name = $this->wpdb->prefix . 'bbp_repair_tool_translator'; |
| | 516 | if ( $this->wpdb->get_var( "SHOW TABLES LIKE '" . $this->sync_table_name . "'" ) === $this->sync_table_name ) { |
| | 517 | $this->sync_table = true; |
| | 518 | } else { |
| | 519 | $this->sync_table = false; |
| | 520 | } |
| | 521 | |
| | 522 | /** |
| | 523 | * Character set |
| | 524 | */ |
| | 525 | if ( empty( $this->wpdb->charset ) ) { |
| | 526 | $this->charset = 'UTF8'; |
| | 527 | } else { |
| | 528 | $this->charset = $this->wpdb->charset; |
| | 529 | } |
| | 530 | |
| | 531 | /** |
| | 532 | * Default mapping. |
| | 533 | */ |
| | 534 | |
| | 535 | /** User Section ******************************************************/ |
| | 536 | |
| | 537 | $this->field_map[] = array( |
| | 538 | 'to_type' => 'user', |
| | 539 | 'to_fieldname' => 'role', |
| | 540 | 'default' => get_option( 'default_role' ) |
| | 541 | ); |
| | 542 | } |
| | 543 | |
| | 544 | /** |
| | 545 | * Convert Users |
| | 546 | */ |
| | 547 | public function convert_users( $start = 1 ) { |
| | 548 | return $this->convert_table( 'user', $start ); |
| | 549 | } |
| | 550 | |
| | 551 | /** |
| | 552 | * Convert Forum Subscriptions |
| | 553 | */ |
| | 554 | public function convert_forum_subscriptions_test01( $start = 1 ) { |
| | 555 | return $this->convert_table( 'forum_subscriptions_test01', $start ); |
| | 556 | } |
| | 557 | |
| | 558 | /** |
| | 559 | * Convert Topic Subscriptions |
| | 560 | */ |
| | 561 | public function convert_topic_subscriptions_test01( $start = 1 ) { |
| | 562 | return $this->convert_table( 'topic_subscriptions_test01', $start ); |
| | 563 | } |
| | 564 | |
| | 565 | /** |
| | 566 | * Convert Favorites |
| | 567 | */ |
| | 568 | public function convert_favorites_test01( $start = 1 ) { |
| | 569 | return $this->convert_table( 'favorites', $start ); |
| | 570 | } |
| | 571 | |
| | 572 | /** |
| | 573 | * Convert Table |
| | 574 | * |
| | 575 | * @param string to type |
| | 576 | * @param int Start row |
| | 577 | */ |
| | 578 | public function convert_table( $to_type, $start ) { |
| | 579 | |
| | 580 | // Are we usig a sync table, or postmeta? |
| | 581 | if ( $this->wpdb->get_var( "SHOW TABLES LIKE '" . $this->sync_table_name . "'" ) === $this->sync_table_name ) { |
| | 582 | $this->sync_table = true; |
| | 583 | } else { |
| | 584 | $this->sync_table = false; |
| | 585 | } |
| | 586 | |
| | 587 | // Set some defaults. |
| | 588 | $has_insert = false; |
| | 589 | $from_tablename = ''; |
| | 590 | $field_list = $from_tables = $tablefield_array = array(); |
| | 591 | |
| | 592 | // Toggle Table Name based on $to_type (destination). |
| | 593 | switch ( $to_type ) { |
| | 594 | case 'user' : |
| | 595 | $tablename = $this->wpdb->users; |
| | 596 | break; |
| | 597 | |
| | 598 | case 'forum_subscriptions_test01' : |
| | 599 | $tablename = $this->wpdb->postmeta; |
| | 600 | break; |
| | 601 | |
| | 602 | case 'topic_subscriptions_test01' : |
| | 603 | $tablename = $this->wpdb->postmeta; |
| | 604 | break; |
| | 605 | |
| | 606 | case 'favorites_test01' : |
| | 607 | $tablename = $this->wpdb->postmeta; |
| | 608 | break; |
| | 609 | |
| | 610 | default : |
| | 611 | $tablename = $this->wpdb->posts; |
| | 612 | } |
| | 613 | |
| | 614 | // Get the fields from the destination table. |
| | 615 | if ( ! empty( $tablename ) ) { |
| | 616 | $tablefield_array = $this->get_fields( $tablename ); |
| | 617 | } |
| | 618 | |
| | 619 | /** Step 1 ************************************************************/ |
| | 620 | |
| | 621 | // Loop through the field maps, and look for to_type matches. |
| | 622 | foreach ( $this->field_map as $item ) { |
| | 623 | |
| | 624 | // Yay a match, and we have a from table, too. |
| | 625 | if ( ( $item['to_type'] === $to_type ) && ! empty( $item['from_tablename'] ) ) { |
| | 626 | |
| | 627 | // $from_tablename was set from a previous loop iteration. |
| | 628 | if ( ! empty( $from_tablename ) ) { |
| | 629 | |
| | 630 | // Doing some joining. |
| | 631 | if ( ! in_array( $item['from_tablename'], $from_tables ) && in_array( $item['join_tablename'], $from_tables ) ) { |
| | 632 | $from_tablename .= ' ' . $item['join_type'] . ' JOIN ' . $this->opdb->prefix . $item['from_tablename'] . ' AS ' . $item['from_tablename'] . ' ' . $item['join_expression']; |
| | 633 | } |
| | 634 | |
| | 635 | // $from_tablename needs to be set. |
| | 636 | } else { |
| | 637 | $from_tablename = $item['from_tablename'] . ' AS ' . $item['from_tablename']; |
| | 638 | } |
| | 639 | |
| | 640 | // Specific FROM expression data used. |
| | 641 | if ( ! empty( $item['from_expression'] ) ) { |
| | 642 | |
| | 643 | // No 'WHERE' in expression. |
| | 644 | if ( stripos( $from_tablename, "WHERE" ) === false ) { |
| | 645 | $from_tablename .= ' ' . $item['from_expression']; |
| | 646 | |
| | 647 | // 'WHERE' in expression, so replace with 'AND' |
| | 648 | } else { |
| | 649 | $from_tablename .= ' ' . str_replace( "WHERE", "AND", $item['from_expression'] ); |
| | 650 | } |
| | 651 | } |
| | 652 | |
| | 653 | // Add tablename and fieldname to arrays, formatted for querying. |
| | 654 | $from_tables[] = $item['from_tablename']; |
| | 655 | $field_list[] = 'convert(' . $item['from_tablename'] . '.' . $item['from_fieldname'] . ' USING "' . $this->charset . '") AS ' . $item['from_fieldname']; |
| | 656 | } |
| | 657 | } |
| | 658 | |
| | 659 | /** Step 2 ************************************************************/ |
| | 660 | |
| | 661 | // We have a $from_tablename, so we want to get some data to convert. |
| | 662 | if ( ! empty( $from_tablename ) ) { |
| | 663 | |
| | 664 | // Get some data from the old forums. |
| | 665 | $field_list = array_unique( $field_list ); |
| | 666 | $forum_query = 'SELECT ' . implode( ',', $field_list ) . ' FROM ' . $this->opdb->prefix . $from_tablename . ' LIMIT ' . $start . ', ' . $this->max_rows; |
| | 667 | $forum_array = $this->opdb->get_results( $forum_query, ARRAY_A ); |
| | 668 | |
| | 669 | // Set this query as the last one ran. |
| | 670 | update_option( '_bbp_repair_tool_query', $forum_query ); |
| | 671 | |
| | 672 | // Query returned some results. |
| | 673 | if ( ! empty( $forum_array ) ) { |
| | 674 | |
| | 675 | // Loop through results. |
| | 676 | foreach ( (array) $forum_array as $forum ) { |
| | 677 | |
| | 678 | // Reset some defaults. |
| | 679 | $insert_post = $insert_postmeta = $insert_data = array(); |
| | 680 | |
| | 681 | // Loop through field map, again... |
| | 682 | foreach ( $this->field_map as $row ) { |
| | 683 | |
| | 684 | // Types match and to_fieldname is present. This means |
| | 685 | // we have some work to do here. |
| | 686 | if ( ( $row['to_type'] === $to_type ) && isset( $row['to_fieldname'] ) ) { |
| | 687 | |
| | 688 | // This row has a destination that matches one of the |
| | 689 | // columns in this table. |
| | 690 | if ( in_array( $row['to_fieldname'], $tablefield_array ) ) { |
| | 691 | |
| | 692 | // Allows us to set default fields. |
| | 693 | if ( isset( $row['default'] ) ) { |
| | 694 | $insert_post[ $row['to_fieldname'] ] = $row['default']; |
| | 695 | |
| | 696 | // Translates a field from the old forum. |
| | 697 | } elseif ( isset( $row['callback_method'] ) ) { |
| | 698 | if ( ( 'callback_userid' === $row['callback_method'] ) && empty( $_POST['_bbp_repair_tool_convert_users'] ) ) { |
| | 699 | $insert_post[ $row['to_fieldname'] ] = $forum[ $row['from_fieldname'] ]; |
| | 700 | } else { |
| | 701 | $insert_post[ $row['to_fieldname'] ] = call_user_func_array( array( $this, $row['callback_method'] ), array( $forum[ $row['from_fieldname'] ], $forum ) ); |
| | 702 | } |
| | 703 | |
| | 704 | // Maps the field from the old forum. |
| | 705 | } else { |
| | 706 | $insert_post[ $row['to_fieldname'] ] = $forum[ $row['from_fieldname'] ]; |
| | 707 | } |
| | 708 | |
| | 709 | // Destination field is not empty, so we might need |
| | 710 | // to do some extra work or set a default. |
| | 711 | } elseif ( ! empty( $row['to_fieldname'] ) ) { |
| | 712 | |
| | 713 | // Allows us to set default fields. |
| | 714 | if ( isset( $row['default'] ) ) { |
| | 715 | $insert_postmeta[ $row['to_fieldname'] ] = $row['default']; |
| | 716 | |
| | 717 | // Translates a field from the old forum. |
| | 718 | } elseif ( isset( $row['callback_method'] ) ) { |
| | 719 | if ( ( $row['callback_method'] === 'callback_userid' ) && ( 0 == $_POST['_bbp_repair_tool_convert_users'] ) ) { |
| | 720 | $insert_postmeta[ $row['to_fieldname'] ] = $forum[ $row['from_fieldname'] ]; |
| | 721 | } else { |
| | 722 | $insert_postmeta[ $row['to_fieldname'] ] = call_user_func_array( array( $this, $row['callback_method'] ), array( $forum[ $row['from_fieldname'] ], $forum ) ); |
| | 723 | } |
| | 724 | |
| | 725 | // Maps the field from the old forum. |
| | 726 | } else { |
| | 727 | $insert_postmeta[ $row['to_fieldname'] ] = $forum[ $row['from_fieldname'] ]; |
| | 728 | } |
| | 729 | } |
| | 730 | } |
| | 731 | } |
| | 732 | |
| | 733 | /** Step 3 ************************************************/ |
| | 734 | |
| | 735 | // Something to insert into the destination field. |
| | 736 | if ( count( $insert_post ) > 0 || ( $to_type == 'tags' && count( $insert_postmeta ) > 0 ) ) { |
| | 737 | |
| | 738 | switch ( $to_type ) { |
| | 739 | |
| | 740 | /** New user **************************************/ |
| | 741 | |
| | 742 | case 'user': |
| | 743 | if ( username_exists( $insert_post['user_login'] ) ) { |
| | 744 | $insert_post['user_login'] = 'imported_' . $insert_post['user_login']; |
| | 745 | } |
| | 746 | |
| | 747 | if ( email_exists( $insert_post['user_email'] ) ) { |
| | 748 | $insert_post['user_email'] = 'imported_' . $insert_post['user_email']; |
| | 749 | } |
| | 750 | |
| | 751 | $post_id = wp_insert_user( $insert_post ); |
| | 752 | |
| | 753 | if ( is_numeric( $post_id ) ) { |
| | 754 | |
| | 755 | foreach ( $insert_postmeta as $key => $value ) { |
| | 756 | |
| | 757 | add_user_meta( $post_id, $key, $value, true ); |
| | 758 | |
| | 759 | if ( '_id' === substr( $key, -3 ) && ( true === $this->sync_table ) ) { |
| | 760 | $this->wpdb->insert( $this->sync_table_name, array( 'value_type' => 'user', 'value_id' => $post_id, 'meta_key' => $key, 'meta_value' => $value ) ); |
| | 761 | } |
| | 762 | } |
| | 763 | } |
| | 764 | break; |
| | 765 | |
| | 766 | /** Forum Subscriptions ***************************/ |
| | 767 | |
| | 768 | case 'forum_subscriptions_test01': |
| | 769 | $user_id = $insert_post['user_id']; |
| | 770 | if ( is_numeric( $user_id ) ) { |
| | 771 | foreach ($insert_postmeta as $key => $value) { |
| | 772 | |
| | 773 | // Only extract values from the key _bbp_forum_subscriptions. |
| | 774 | if ( '_bbp_forum_subscriptions' == $key ) { |
| | 775 | |
| | 776 | // Get the new forum ID |
| | 777 | $forum_id = $this->callback_forumid( $value ); |
| | 778 | |
| | 779 | // Add the topic ID to the users subscribed forums. |
| | 780 | bbp_add_user_forum_subscription( $user_id, $forum_id ); |
| | 781 | } |
| | 782 | } |
| | 783 | } |
| | 784 | break; |
| | 785 | |
| | 786 | /** Subscriptions *********************************/ |
| | 787 | |
| | 788 | case 'topic_subscriptions_test01': |
| | 789 | $user_id = $insert_post['user_id']; |
| | 790 | if ( is_numeric( $user_id ) ) { |
| | 791 | foreach ($insert_postmeta as $key => $value) { |
| | 792 | |
| | 793 | // Only extract values from the key _bbp_subscriptions. |
| | 794 | if ( '_bbp_subscriptions' == $key ) { |
| | 795 | |
| | 796 | // Get the new topic ID |
| | 797 | $topic_id = $this->callback_topicid( $value ); |
| | 798 | |
| | 799 | // Add the topic ID to the users subscribed topics. |
| | 800 | bbp_add_user_topic_subscription( $user_id, $topic_id ); |
| | 801 | } |
| | 802 | } |
| | 803 | } |
| | 804 | break; |
| | 805 | |
| | 806 | /** Favorites *************************************/ |
| | 807 | |
| | 808 | case 'favorites_test01': |
| | 809 | $user_id = $insert_post['user_id']; |
| | 810 | if ( is_numeric( $user_id ) ) { |
| | 811 | |
| | 812 | // Loop through the array |
| | 813 | foreach ($insert_postmeta as $key => $value) { |
| | 814 | |
| | 815 | // Only extract values from the key _bbp_favorites. |
| | 816 | if ( '_bbp_favorites' == $key ) { |
| | 817 | |
| | 818 | // Our array may contain comma delimited favorites so lets explode these. |
| | 819 | $insert_postmeta = explode(",", $insert_postmeta['_bbp_favorites']); |
| | 820 | |
| | 821 | // Loop through our updated exploded array. |
| | 822 | foreach ($insert_postmeta as $key => $value) { |
| | 823 | |
| | 824 | // Get the new topic ID. |
| | 825 | $topic_id = $this->callback_topicid( $value ); |
| | 826 | |
| | 827 | // Add the topic ID to the users favorites. |
| | 828 | bbp_add_user_favorite( $user_id, $topic_id ); |
| | 829 | } |
| | 830 | } |
| | 831 | } |
| | 832 | } |
| | 833 | break; |
| | 834 | } |
| | 835 | $has_insert = true; |
| | 836 | } |
| | 837 | } |
| | 838 | } |
| | 839 | } |
| | 840 | |
| | 841 | return ! $has_insert; |
| | 842 | } |
| | 843 | |
| | 844 | /** |
| | 845 | * This method converts old reply_to post id to new bbPress reply_to post id. |
| | 846 | * |
| | 847 | * @since 2.4.0 bbPress (r5093) |
| | 848 | */ |
| | 849 | public function convert_reply_to_parents( $start ) { |
| | 850 | |
| | 851 | $has_update = false; |
| | 852 | |
| | 853 | if ( ! empty( $this->sync_table ) ) { |
| | 854 | $query = 'SELECT value_id, meta_value FROM ' . $this->sync_table_name . ' WHERE meta_key = "_bbp_old_reply_to_id" AND meta_value > 0 LIMIT ' . $start . ', ' . $this->max_rows; |
| | 855 | } else { |
| | 856 | $query = 'SELECT post_id AS value_id, meta_value FROM ' . $this->wpdb->postmeta . ' WHERE meta_key = "_bbp_old_reply_to_id" AND meta_value > 0 LIMIT ' . $start . ', ' . $this->max_rows; |
| | 857 | } |
| | 858 | |
| | 859 | update_option( '_bbp_repair_tool_query', $query ); |
| | 860 | |
| | 861 | $reply_to_array = $this->wpdb->get_results( $query ); |
| | 862 | |
| | 863 | foreach ( (array) $reply_to_array as $row ) { |
| | 864 | $reply_to = $this->callback_reply_to( $row->meta_value ); |
| | 865 | $this->wpdb->query( 'UPDATE ' . $this->wpdb->postmeta . ' SET meta_value = "' . $reply_to . '" WHERE meta_key = "_bbp_reply_to" AND post_id = "' . $row->value_id . '" LIMIT 1' ); |
| | 866 | $has_update = true; |
| | 867 | } |
| | 868 | |
| | 869 | return ! $has_update; |
| | 870 | } |
| | 871 | |
| | 872 | |
| | 873 | /** |
| | 874 | * This method deletes data from the wp database. |
| | 875 | */ |
| | 876 | public function clean( $start ) { |
| | 877 | |
| | 878 | $start = 0; |
| | 879 | $has_delete = false; |
| | 880 | |
| | 881 | /** Delete bbconverter topics/forums/posts ****************************/ |
| | 882 | |
| | 883 | if ( true === $this->sync_table ) { |
| | 884 | $query = 'SELECT value_id FROM ' . $this->sync_table_name . ' INNER JOIN ' . $this->wpdb->posts . ' ON(value_id = ID) WHERE meta_key LIKE "_bbp_%" AND value_type = "post" GROUP BY value_id ORDER BY value_id DESC LIMIT ' . $this->max_rows; |
| | 885 | } else { |
| | 886 | $query = 'SELECT post_id AS value_id FROM ' . $this->wpdb->postmeta . ' WHERE meta_key LIKE "_bbp_%" GROUP BY post_id ORDER BY post_id DESC LIMIT ' . $this->max_rows; |
| | 887 | } |
| | 888 | |
| | 889 | update_option( '_bbp_repair_tool_query', $query ); |
| | 890 | |
| | 891 | $posts = $this->wpdb->get_results( $query, ARRAY_A ); |
| | 892 | |
| | 893 | if ( isset( $posts[0] ) && ! empty( $posts[0]['value_id'] ) ) { |
| | 894 | foreach ( (array) $posts as $value ) { |
| | 895 | wp_delete_post( $value['value_id'], true ); |
| | 896 | } |
| | 897 | $has_delete = true; |
| | 898 | } |
| | 899 | |
| | 900 | /** Delete bbconverter users ******************************************/ |
| | 901 | |
| | 902 | if ( true === $this->sync_table ) { |
| | 903 | $query = 'SELECT value_id FROM ' . $this->sync_table_name . ' INNER JOIN ' . $this->wpdb->users . ' ON(value_id = ID) WHERE meta_key = "_bbp_old_user_id" AND value_type = "user" LIMIT ' . $this->max_rows; |
| | 904 | } else { |
| | 905 | $query = 'SELECT user_id AS value_id FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_old_user_id" LIMIT ' . $this->max_rows; |
| | 906 | } |
| | 907 | |
| | 908 | update_option( '_bbp_repair_tool_query', $query ); |
| | 909 | |
| | 910 | $users = $this->wpdb->get_results( $query, ARRAY_A ); |
| | 911 | |
| | 912 | if ( ! empty( $users ) ) { |
| | 913 | foreach ( $users as $value ) { |
| | 914 | wp_delete_user( $value['value_id'] ); |
| | 915 | } |
| | 916 | $has_delete = true; |
| | 917 | } |
| | 918 | |
| | 919 | unset( $posts ); |
| | 920 | unset( $users ); |
| | 921 | |
| | 922 | return ! $has_delete; |
| | 923 | } |
| | 924 | |
| | 925 | /** |
| | 926 | * This method deletes passwords from the wp database. |
| | 927 | * |
| | 928 | * @param int Start row |
| | 929 | */ |
| | 930 | public function clean_passwords( $start ) { |
| | 931 | |
| | 932 | $has_delete = false; |
| | 933 | |
| | 934 | /** Delete bbconverter passwords **************************************/ |
| | 935 | |
| | 936 | $query = 'SELECT user_id, meta_value FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_password" LIMIT ' . $start . ', ' . $this->max_rows; |
| | 937 | update_option( '_bbp_repair_tool_query', $query ); |
| | 938 | |
| | 939 | $repair_tool = $this->wpdb->get_results( $query, ARRAY_A ); |
| | 940 | |
| | 941 | if ( ! empty( $repair_tool ) ) { |
| | 942 | |
| | 943 | foreach ( $repair_tool as $value ) { |
| | 944 | if ( is_serialized( $value['meta_value'] ) ) { |
| | 945 | $this->wpdb->query( 'UPDATE ' . $this->wpdb->users . ' ' . 'SET user_pass = "" ' . 'WHERE ID = "' . $value['user_id'] . '"' ); |
| | 946 | } else { |
| | 947 | $this->wpdb->query( 'UPDATE ' . $this->wpdb->users . ' ' . 'SET user_pass = "' . $value['meta_value'] . '" ' . 'WHERE ID = "' . $value['user_id'] . '"' ); |
| | 948 | $this->wpdb->query( 'DELETE FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_password" AND user_id = "' . $value['user_id'] . '"' ); |
| | 949 | } |
| | 950 | } |
| | 951 | $has_delete = true; |
| | 952 | } |
| | 953 | |
| | 954 | return ! $has_delete; |
| | 955 | } |
| | 956 | |
| | 957 | /** |
| | 958 | * This method implements the authentication for the different forums. |
| | 959 | * |
| | 960 | * @param string Unencoded password. |
| | 961 | */ |
| | 962 | abstract protected function authenticate_pass( $password, $hash ); |
| | 963 | |
| | 964 | /** |
| | 965 | * Info |
| | 966 | */ |
| | 967 | abstract protected function info(); |
| | 968 | |
| | 969 | /** |
| | 970 | * This method grabs appropriate fields from the table specified |
| | 971 | * |
| | 972 | * @param string The table name to grab fields from |
| | 973 | */ |
| | 974 | private function get_fields( $tablename ) { |
| | 975 | $rval = array(); |
| | 976 | $field_array = $this->wpdb->get_results( 'DESCRIBE ' . $tablename, ARRAY_A ); |
| | 977 | |
| | 978 | foreach ( $field_array as $field ) { |
| | 979 | $rval[] = $field['Field']; |
| | 980 | } |
| | 981 | |
| | 982 | if ( $tablename === $this->wpdb->users ) { |
| | 983 | $rval[] = 'role'; |
| | 984 | $rval[] = 'yim'; |
| | 985 | $rval[] = 'aim'; |
| | 986 | $rval[] = 'jabber'; |
| | 987 | } |
| | 988 | return $rval; |
| | 989 | } |
| | 990 | |
| | 991 | /** Callbacks *************************************************************/ |
| | 992 | |
| | 993 | /** |
| | 994 | * A mini cache system to reduce database calls to user ID's |
| | 995 | * |
| | 996 | * @param string $field |
| | 997 | * @return string |
| | 998 | */ |
| | 999 | private function callback_userid( $field ) { |
| | 1000 | if ( ! isset( $this->map_userid[ $field ] ) ) { |
| | 1001 | if ( ! empty( $this->sync_table ) ) { |
| | 1002 | $row = $this->wpdb->get_row( $this->wpdb->prepare( 'SELECT value_id, meta_value FROM ' . $this->sync_table_name . ' WHERE meta_key = "_bbp_old_user_id" AND meta_value = "%s" LIMIT 1', $field ) ); |
| | 1003 | } else { |
| | 1004 | $row = $this->wpdb->get_row( $this->wpdb->prepare( 'SELECT user_id AS value_id FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_old_user_id" AND meta_value = "%s" LIMIT 1', $field ) ); |
| | 1005 | } |
| | 1006 | |
| | 1007 | if ( ! is_null( $row ) ) { |
| | 1008 | $this->map_userid[ $field ] = $row->value_id; |
| | 1009 | } else { |
| | 1010 | if ( ! empty( $_POST['_bbp_repair_tool_convert_users'] ) && ( (int) $_POST['_bbp_repair_tool_convert_users'] == 1 ) ) { |
| | 1011 | $this->map_userid[ $field ] = 0; |
| | 1012 | } else { |
| | 1013 | $this->map_userid[ $field ] = $field; |
| | 1014 | } |
| | 1015 | } |
| | 1016 | } |
| | 1017 | return $this->map_userid[ $field ]; |
| | 1018 | } |
| | 1019 | } |
| | 1020 | |
| | 1021 | /** |
| | 1022 | * This is a function that is purposely written to look like a "new" statement. |
| | 1023 | * It is basically a dynamic loader that will load in the platform conversion |
| | 1024 | * of your choice. |
| | 1025 | * |
| | 1026 | * @param string $platform Name of valid platform class. |
| | 1027 | */ |
| | 1028 | function bbp_new_repair( $platform ) { |
| | 1029 | $found = false; |
| | 1030 | |
| | 1031 | if ( $curdir = opendir( bbpress()->admin->admin_dir . 'converters/' ) ) { |
| | 1032 | while ( $file = readdir( $curdir ) ) { |
| | 1033 | if ( stristr( $file, '.php' ) && stristr( $file, 'index' ) === FALSE ) { |
| | 1034 | $file = preg_replace( '/.php/', '', $file ); |
| | 1035 | if ( $platform === $file ) { |
| | 1036 | $found = true; |
| | 1037 | continue; |
| | 1038 | } |
| | 1039 | } |
| | 1040 | } |
| | 1041 | closedir( $curdir ); |
| | 1042 | } |
| | 1043 | |
| | 1044 | if ( true === $found ) { |
| | 1045 | require_once( bbpress()->admin->admin_dir . 'converters/' . $platform . '.php' ); |
| | 1046 | return new $platform; |
| | 1047 | } else { |
| | 1048 | return null; |
| | 1049 | } |
| | 1050 | } |