[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/src/includes/admin/converters/ -> MyBB.php (source)

   1  <?php
   2  
   3  /**
   4   * bbPress MyBB Converter
   5   *
   6   * @package bbPress
   7   * @subpackage Converters
   8   */
   9  
  10  /**
  11   * Implementation of MyBB Forum converter.
  12   *
  13   * @since 2.5.0 bbPress (r5140)
  14   *
  15   * @link Codex Docs https://codex.bbpress.org/import-forums/mybb
  16   */
  17  class MyBB extends BBP_Converter_Base {
  18  
  19      /**
  20       * Main Constructor
  21       *
  22       */
  23  	public function __construct() {
  24          parent::__construct();
  25      }
  26  
  27      /**
  28       * Sets up the field mappings
  29       */
  30  	public function setup_globals() {
  31  
  32          /** Forum Section *****************************************************/
  33  
  34          // Old forum id (Stored in postmeta)
  35          $this->field_map[] = array(
  36              'from_tablename' => 'forums',
  37              'from_fieldname' => 'fid',
  38              'to_type'        => 'forum',
  39              'to_fieldname'   => '_bbp_old_forum_id'
  40          );
  41  
  42          // Forum parent id (If no parent, then 0, Stored in postmeta)
  43          $this->field_map[] = array(
  44              'from_tablename'  => 'forums',
  45              'from_fieldname'  => 'pid',
  46              'to_type'         => 'forum',
  47              'to_fieldname'    => '_bbp_old_forum_parent_id'
  48          );
  49  
  50          // Forum topic count (Stored in postmeta)
  51          $this->field_map[] = array(
  52              'from_tablename' => 'forums',
  53              'from_fieldname' => 'threads',
  54              'to_type'        => 'forum',
  55              'to_fieldname'   => '_bbp_topic_count'
  56          );
  57  
  58          // Forum reply count (Stored in postmeta)
  59          $this->field_map[] = array(
  60              'from_tablename' => 'forums',
  61              'from_fieldname' => 'posts',
  62              'to_type'        => 'forum',
  63              'to_fieldname'   => '_bbp_reply_count'
  64          );
  65  
  66          // Forum title.
  67          $this->field_map[] = array(
  68              'from_tablename' => 'forums',
  69              'from_fieldname' => 'name',
  70              'to_type'        => 'forum',
  71              'to_fieldname'   => 'post_title'
  72          );
  73  
  74          // Forum slug (Clean name to avoid conflicts)
  75          $this->field_map[] = array(
  76              'from_tablename'  => 'forums',
  77              'from_fieldname'  => 'name',
  78              'to_type'         => 'forum',
  79              'to_fieldname'    => 'post_name',
  80              'callback_method' => 'callback_slug'
  81          );
  82  
  83          // Forum description.
  84          $this->field_map[] = array(
  85              'from_tablename'  => 'forums',
  86              'from_fieldname'  => 'description',
  87              'to_type'         => 'forum',
  88              'to_fieldname'    => 'post_content',
  89              'callback_method' => 'callback_null'
  90          );
  91  
  92          // Forum display order (Starts from 1)
  93          $this->field_map[] = array(
  94              'from_tablename' => 'forums',
  95              'from_fieldname' => 'disporder',
  96              'to_type'        => 'forum',
  97              'to_fieldname'   => 'menu_order'
  98          );
  99  
 100          // Forum type (Set a default value 'forum', Stored in postmeta)
 101          $this->field_map[] = array(
 102              'to_type'      => 'forum',
 103              'to_fieldname' => '_bbp_forum_type',
 104              'default'      => 'forum'
 105          );
 106  
 107          // Forum status (Set a default value 'open', Stored in postmeta)
 108          $this->field_map[] = array(
 109              'to_type'      => 'forum',
 110              'to_fieldname' => '_bbp_status',
 111              'default'      => 'open'
 112          );
 113  
 114          // Forum dates.
 115          $this->field_map[] = array(
 116              'to_type'      => 'forum',
 117              'to_fieldname' => 'post_date',
 118              'default'      => date('Y-m-d H:i:s')
 119          );
 120          $this->field_map[] = array(
 121              'to_type'      => 'forum',
 122              'to_fieldname' => 'post_date_gmt',
 123              'default'      => date('Y-m-d H:i:s')
 124          );
 125          $this->field_map[] = array(
 126              'to_type'      => 'forum',
 127              'to_fieldname' => 'post_modified',
 128              'default'      => date('Y-m-d H:i:s')
 129          );
 130          $this->field_map[] = array(
 131              'to_type'      => 'forum',
 132              'to_fieldname' => 'post_modified_gmt',
 133              'default'      => date('Y-m-d H:i:s')
 134          );
 135  
 136          /** Topic Section *****************************************************/
 137  
 138          // Old topic id (Stored in postmeta)
 139          $this->field_map[] = array(
 140              'from_tablename' => 'threads',
 141              'from_fieldname' => 'tid',
 142              'to_type'        => 'topic',
 143              'to_fieldname'   => '_bbp_old_topic_id'
 144          );
 145  
 146          // Topic reply count (Stored in postmeta)
 147          $this->field_map[] = array(
 148              'from_tablename'  => 'threads',
 149              'from_fieldname'  => 'replies',
 150              'to_type'         => 'topic',
 151              'to_fieldname'    => '_bbp_reply_count',
 152              'callback_method' => 'callback_topic_reply_count'
 153          );
 154  
 155          // Topic total reply count (Includes unpublished replies, Stored in postmeta)
 156          $this->field_map[] = array(
 157              'from_tablename'  => 'threads',
 158              'from_fieldname'  => 'replies',
 159              'to_type'         => 'topic',
 160              'to_fieldname'    => '_bbp_total_reply_count',
 161              'callback_method' => 'callback_topic_reply_count'
 162          );
 163  
 164          // Topic parent forum id (If no parent, then 0. Stored in postmeta)
 165          $this->field_map[] = array(
 166              'from_tablename'  => 'threads',
 167              'from_fieldname'  => 'fid',
 168              'to_type'         => 'topic',
 169              'to_fieldname'    => '_bbp_forum_id',
 170              'callback_method' => 'callback_forumid'
 171          );
 172  
 173          // Topic author.
 174          $this->field_map[] = array(
 175              'from_tablename'  => 'threads',
 176              'from_fieldname'  => 'uid',
 177              'to_type'         => 'topic',
 178              'to_fieldname'    => 'post_author',
 179              'callback_method' => 'callback_userid'
 180          );
 181  
 182          // Topic Author ip (Stored in postmeta)
 183          $this->field_map[] = array(
 184              'from_tablename'  => 'posts',
 185              'from_fieldname'  => 'ipaddress',
 186              'join_tablename'  => 'threads',
 187              'join_type'       => 'INNER',
 188              'join_expression' => 'USING (tid) WHERE replyto = 0',
 189              'to_type'         => 'topic',
 190              'to_fieldname'    => '_bbp_author_ip'
 191          );
 192  
 193          // Topic content.
 194          // Note: We join the 'posts' table because 'threads' table does not have content.
 195          $this->field_map[] = array(
 196              'from_tablename'  => 'posts',
 197              'from_fieldname'  => 'message',
 198              'join_tablename'  => 'threads',
 199              'join_type'       => 'INNER',
 200              'join_expression' => 'USING (tid) WHERE replyto = 0',
 201              'to_type'         => 'topic',
 202              'to_fieldname'    => 'post_content',
 203              'callback_method' => 'callback_html'
 204          );
 205  
 206          // Topic title.
 207          $this->field_map[] = array(
 208              'from_tablename' => 'threads',
 209              'from_fieldname' => 'subject',
 210              'to_type'        => 'topic',
 211              'to_fieldname'   => 'post_title'
 212          );
 213  
 214          // Topic slug (Clean name to avoid conflicts)
 215          $this->field_map[] = array(
 216              'from_tablename'  => 'threads',
 217              'from_fieldname'  => 'subject',
 218              'to_type'         => 'topic',
 219              'to_fieldname'    => 'post_name',
 220              'callback_method' => 'callback_slug'
 221          );
 222  
 223          // Topic parent forum id (If no parent, then 0)
 224          $this->field_map[] = array(
 225              'from_tablename'  => 'threads',
 226              'from_fieldname'  => 'fid',
 227              'to_type'         => 'topic',
 228              'to_fieldname'    => 'post_parent',
 229              'callback_method' => 'callback_forumid'
 230          );
 231  
 232          // Sticky status (Stored in postmeta)
 233          $this->field_map[] = array(
 234              'from_tablename'  => 'threads',
 235              'from_fieldname'  => 'sticky',
 236              'to_type'         => 'topic',
 237              'to_fieldname'    => '_bbp_old_sticky_status_id',
 238              'callback_method' => 'callback_sticky_status'
 239          );
 240  
 241          // Topic dates.
 242          $this->field_map[] = array(
 243              'from_tablename'  => 'threads',
 244              'from_fieldname'  => 'dateline',
 245              'to_type'         => 'topic',
 246              'to_fieldname'    => 'post_date',
 247              'callback_method' => 'callback_datetime'
 248          );
 249          $this->field_map[] = array(
 250              'from_tablename'  => 'threads',
 251              'from_fieldname'  => 'dateline',
 252              'to_type'         => 'topic',
 253              'to_fieldname'    => 'post_date_gmt',
 254              'callback_method' => 'callback_datetime'
 255          );
 256          $this->field_map[] = array(
 257              'from_tablename'  => 'threads',
 258              'from_fieldname'  => 'lastpost',
 259              'to_type'         => 'topic',
 260              'to_fieldname'    => 'post_modified',
 261              'callback_method' => 'callback_datetime'
 262          );
 263          $this->field_map[] = array(
 264              'from_tablename'  => 'threads',
 265              'from_fieldname'  => 'lastpost',
 266              'to_type'         => 'topic',
 267              'to_fieldname'    => 'post_modified_gmt',
 268              'callback_method' => 'callback_datetime'
 269          );
 270          $this->field_map[] = array(
 271              'from_tablename'  => 'threads',
 272              'from_fieldname'  => 'lastpost',
 273              'to_type'         => 'topic',
 274              'to_fieldname'    => '_bbp_last_active_time',
 275              'callback_method' => 'callback_datetime'
 276          );
 277  
 278          // Topic status (Open or Closed, MyBB v1.6.10 open = null & closed = 1)
 279          $this->field_map[] = array(
 280              'from_tablename'  => 'threads',
 281              'from_fieldname'  => 'closed',
 282              'to_type'         => 'topic',
 283              'to_fieldname'    => '_bbp_old_closed_status_id',
 284              'callback_method' => 'callback_topic_status'
 285          );
 286  
 287          /** Tags Section ******************************************************/
 288  
 289          /**
 290           * MyBB v1.6.10 Forums do not support topic tags out of the box
 291           */
 292  
 293          /** Reply Section *****************************************************/
 294  
 295          // Old reply id (Stored in postmeta)
 296          $this->field_map[] = array(
 297              'from_tablename'  => 'posts',
 298              'from_fieldname'  => 'pid',
 299              'from_expression' => 'WHERE replyto != 0',
 300              'to_type'         => 'reply',
 301              'to_fieldname'    => '_bbp_old_reply_id'
 302          );
 303  
 304          // Reply parent forum id (If no parent, then 0. Stored in postmeta)
 305          $this->field_map[] = array(
 306              'from_tablename'  => 'posts',
 307              'from_fieldname'  => 'fid',
 308              'to_type'         => 'reply',
 309              'to_fieldname'    => '_bbp_forum_id',
 310              'callback_method' => 'callback_topicid_to_forumid'
 311          );
 312  
 313          // Reply parent topic id (If no parent, then 0. Stored in postmeta)
 314          $this->field_map[] = array(
 315              'from_tablename'  => 'posts',
 316              'from_fieldname'  => 'tid',
 317              'to_type'         => 'reply',
 318              'to_fieldname'    => '_bbp_topic_id',
 319              'callback_method' => 'callback_topicid'
 320          );
 321  
 322          // Reply author ip (Stored in postmeta)
 323          $this->field_map[] = array(
 324              'from_tablename' => 'posts',
 325              'from_fieldname' => 'ipaddress',
 326              'to_type'        => 'reply',
 327              'to_fieldname'   => '_bbp_author_ip'
 328          );
 329  
 330          // Reply author.
 331          $this->field_map[] = array(
 332              'from_tablename'  => 'posts',
 333              'from_fieldname'  => 'uid',
 334              'to_type'         => 'reply',
 335              'to_fieldname'    => 'post_author',
 336              'callback_method' => 'callback_userid'
 337          );
 338  
 339          // Reply content.
 340          $this->field_map[] = array(
 341              'from_tablename'  => 'posts',
 342              'from_fieldname'  => 'message',
 343              'to_type'         => 'reply',
 344              'to_fieldname'    => 'post_content',
 345              'callback_method' => 'callback_html'
 346          );
 347  
 348          // Reply parent topic id (If no parent, then 0)
 349          $this->field_map[] = array(
 350              'from_tablename'  => 'posts',
 351              'from_fieldname'  => 'tid',
 352              'to_type'         => 'reply',
 353              'to_fieldname'    => 'post_parent',
 354              'callback_method' => 'callback_topicid'
 355          );
 356  
 357          // Reply dates.
 358          $this->field_map[] = array(
 359              'from_tablename'  => 'posts',
 360              'from_fieldname'  => 'dateline',
 361              'to_type'         => 'reply',
 362              'to_fieldname'    => 'post_date',
 363              'callback_method' => 'callback_datetime'
 364          );
 365          $this->field_map[] = array(
 366              'from_tablename'  => 'posts',
 367              'from_fieldname'  => 'dateline',
 368              'to_type'         => 'reply',
 369              'to_fieldname'    => 'post_date_gmt',
 370              'callback_method' => 'callback_datetime'
 371          );
 372          $this->field_map[] = array(
 373              'from_tablename'  => 'posts',
 374              'from_fieldname'  => 'edittime',
 375              'to_type'         => 'reply',
 376              'to_fieldname'    => 'post_modified',
 377              'callback_method' => 'callback_datetime'
 378          );
 379          $this->field_map[] = array(
 380              'from_tablename'  => 'posts',
 381              'from_fieldname'  => 'edittime',
 382              'to_type'         => 'reply',
 383              'to_fieldname'    => 'post_modified_gmt',
 384              'callback_method' => 'callback_datetime'
 385          );
 386  
 387          /** User Section ******************************************************/
 388  
 389          // Store old user id (Stored in usermeta)
 390          $this->field_map[] = array(
 391              'from_tablename' => 'users',
 392              'from_fieldname' => 'uid',
 393              'to_type'        => 'user',
 394              'to_fieldname'   => '_bbp_old_user_id'
 395          );
 396  
 397          // Store old user password (Stored in usermeta serialized with salt)
 398          $this->field_map[] = array(
 399              'from_tablename'  => 'users',
 400              'from_fieldname'  => 'password',
 401              'to_type'         => 'user',
 402              'to_fieldname'    => '_bbp_password',
 403              'callback_method' => 'callback_savepass'
 404          );
 405  
 406          // Store old user salt (This is only used for the SELECT row info for the above password save)
 407          $this->field_map[] = array(
 408              'from_tablename' => 'users',
 409              'from_fieldname' => 'salt',
 410              'to_type'        => 'user',
 411              'to_fieldname'   => ''
 412          );
 413  
 414          // User password verify class (Stored in usermeta for verifying password)
 415          $this->field_map[] = array(
 416              'to_type'      => 'users',
 417              'to_fieldname' => '_bbp_class',
 418              'default'      => 'MyBB'
 419          );
 420  
 421          // User name.
 422          $this->field_map[] = array(
 423              'from_tablename' => 'users',
 424              'from_fieldname' => 'username',
 425              'to_type'        => 'user',
 426              'to_fieldname'   => 'user_login'
 427          );
 428  
 429          // User nice name.
 430          $this->field_map[] = array(
 431              'from_tablename' => 'users',
 432              'from_fieldname' => 'username',
 433              'to_type'        => 'user',
 434              'to_fieldname'   => 'user_nicename'
 435          );
 436  
 437          // User email.
 438          $this->field_map[] = array(
 439              'from_tablename' => 'users',
 440              'from_fieldname' => 'email',
 441              'to_type'        => 'user',
 442              'to_fieldname'   => 'user_email'
 443          );
 444  
 445          // User homepage.
 446          $this->field_map[] = array(
 447              'from_tablename' => 'users',
 448              'from_fieldname' => 'website',
 449              'to_type'        => 'user',
 450              'to_fieldname'   => 'user_url'
 451          );
 452  
 453          // User registered.
 454          $this->field_map[] = array(
 455              'from_tablename'  => 'users',
 456              'from_fieldname'  => 'regdate',
 457              'to_type'         => 'user',
 458              'to_fieldname'    => 'user_registered',
 459              'callback_method' => 'callback_datetime'
 460          );
 461  
 462          // User display name.
 463          $this->field_map[] = array(
 464              'from_tablename' => 'users',
 465              'from_fieldname' => 'usertitle',
 466              'to_type'        => 'user',
 467              'to_fieldname'   => 'display_name'
 468          );
 469  
 470          // User AIM (Stored in usermeta)
 471          $this->field_map[] = array(
 472              'from_tablename' => 'users',
 473              'from_fieldname' => 'aim',
 474              'to_type'        => 'user',
 475              'to_fieldname'   => '_bbp_mybb_user_aim'
 476          );
 477  
 478          // User Yahoo (Stored in usermeta)
 479          $this->field_map[] = array(
 480              'from_tablename' => 'users',
 481              'from_fieldname' => 'yahoo',
 482              'to_type'        => 'user',
 483              'to_fieldname'   => '_bbp_mybb_user_yim'
 484          );
 485  
 486          // Store ICQ (Stored in usermeta)
 487          $this->field_map[] = array(
 488              'from_tablename' => 'users',
 489              'from_fieldname' => 'icq',
 490              'to_type'        => 'user',
 491              'to_fieldname'   => '_bbp_mybb_user_icq'
 492          );
 493  
 494          // Store MSN (Stored in usermeta)
 495          $this->field_map[] = array(
 496              'from_tablename' => 'users',
 497              'from_fieldname' => 'msn',
 498              'to_type'        => 'user',
 499              'to_fieldname'   => '_bbp_mybb_user_msn'
 500          );
 501  
 502          // Store Signature (Stored in usermeta)
 503          $this->field_map[] = array(
 504              'from_tablename' => 'users',
 505              'from_fieldname' => 'signature',
 506              'to_type'        => 'user',
 507              'to_fieldname'   => '_bbp_mybb_user_sig',
 508              'callback_method' => 'callback_html'
 509          );
 510  
 511      }
 512  
 513      /**
 514       * This method allows us to indicates what is or is not converted for each
 515       * converter.
 516       */
 517  	public function info() {
 518          return '';
 519      }
 520  
 521      /**
 522       * This method is to save the salt and password together.  That
 523       * way when we authenticate it we can get it out of the database
 524       * as one value. Array values are auto sanitized by WordPress.
 525       */
 526  	public function callback_savepass( $field, $row ) {
 527          $pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
 528          return $pass_array;
 529      }
 530  
 531      /**
 532       * This method is to take the pass out of the database and compare
 533       * to a pass the user has typed in.
 534       */
 535  	public function authenticate_pass( $password, $serialized_pass ) {
 536          $pass_array = unserialize( $serialized_pass );
 537          return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) );
 538      }
 539  
 540      /**
 541       * Translate the post status from MyBB v1.6.10 numerics to WordPress's strings.
 542       *
 543       * @param int $status MyBB v1.6.10 numeric topic status
 544       * @return string WordPress safe
 545       */
 546  	public function callback_topic_status( $status = 0 ) {
 547          switch ( $status ) {
 548              case 1 :
 549                  $status = 'closed';
 550                  break;
 551  
 552              case 0  :
 553              default :
 554                  $status = 'publish';
 555                  break;
 556          }
 557          return $status;
 558      }
 559  
 560      /**
 561       * Translate the topic sticky status type from MyBB v1.6.10 numerics to WordPress's strings.
 562       *
 563       * @param int $status MyBB v1.6.10 numeric forum type
 564       * @return string WordPress safe
 565       */
 566  	public function callback_sticky_status( $status = 0 ) {
 567          switch ( $status ) {
 568              case 1 :
 569                  $status = 'sticky';       // MyBB Sticky 'topic_sticky = 1'
 570                  break;
 571  
 572              case 0  :
 573              default :
 574                  $status = 'normal';       // MyBB Normal Topic 'topic_sticky = 0'
 575                  break;
 576          }
 577          return $status;
 578      }
 579  
 580      /**
 581       * Verify the topic/reply count.
 582       *
 583       * @param int $count MyBB v1.6.10 topic/reply counts
 584       * @return string WordPress safe
 585       */
 586  	public function callback_topic_reply_count( $count = 1 ) {
 587          $count = absint( (int) $count - 1 );
 588          return $count;
 589      }
 590  }


Generated: Sat Dec 21 01:00:52 2024 Cross-referenced by PHPXref 0.7.1