[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * bbPress e107 1.x Converter
   5   *
   6   * @package bbPress
   7   * @subpackage Converters
   8   */
   9  
  10  /**
  11   * Implementation of e107 v1.x Forum converter.
  12   *
  13   * @since 2.6.0 bbPress (r5352)
  14   *
  15   * @link Codex Docs https://codex.bbpress.org/import-forums/e107
  16   */
  17  class e107v1 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          // Setup smiley URL & path
  33          $this->bbcode_parser_properties = array(
  34              'smiley_url' => false,
  35              'smiley_dir' => false
  36          );
  37  
  38          /** Forum Section *****************************************************/
  39  
  40          // Old forum id (Stored in postmeta)
  41          $this->field_map[] = array(
  42              'from_tablename' => 'forum',
  43              'from_fieldname' => 'forum_id',
  44              'to_type'        => 'forum',
  45              'to_fieldname'   => '_bbp_old_forum_id'
  46          );
  47  
  48          // Forum parent id (If no parent, then 0, Stored in postmeta)
  49          $this->field_map[] = array(
  50              'from_tablename'  => 'forum',
  51              'from_fieldname'  => 'forum_parent',
  52              'to_type'         => 'forum',
  53              'to_fieldname'    => '_bbp_old_forum_parent_id'
  54          );
  55  
  56          // Forum topic count (Stored in postmeta)
  57          $this->field_map[] = array(
  58              'from_tablename' => 'forum',
  59              'from_fieldname' => 'forum_threads',
  60              'to_type'        => 'forum',
  61              'to_fieldname'   => '_bbp_topic_count'
  62          );
  63  
  64          // Forum reply count (Stored in postmeta)
  65          $this->field_map[] = array(
  66              'from_tablename' => 'forum',
  67              'from_fieldname' => 'forum_replies',
  68              'to_type'        => 'forum',
  69              'to_fieldname'   => '_bbp_reply_count'
  70          );
  71  
  72          // Forum total topic count (Includes unpublished topics, Stored in postmeta)
  73          $this->field_map[] = array(
  74              'from_tablename' => 'forum',
  75              'from_fieldname' => 'forum_threads',
  76              'to_type'        => 'forum',
  77              'to_fieldname'   => '_bbp_total_topic_count'
  78          );
  79  
  80          // Forum total reply count (Includes unpublished replies, Stored in postmeta)
  81          $this->field_map[] = array(
  82              'from_tablename' => 'forum',
  83              'from_fieldname' => 'forum_replies',
  84              'to_type'        => 'forum',
  85              'to_fieldname'   => '_bbp_total_reply_count'
  86          );
  87  
  88          // Forum title.
  89          $this->field_map[] = array(
  90              'from_tablename' => 'forum',
  91              'from_fieldname' => 'forum_name',
  92              'to_type'        => 'forum',
  93              'to_fieldname'   => 'post_title'
  94          );
  95  
  96          // Forum slug (Clean name to avoid conflicts)
  97          $this->field_map[] = array(
  98              'from_tablename'  => 'forum',
  99              'from_fieldname'  => 'forum_name',
 100              'to_type'         => 'forum',
 101              'to_fieldname'    => 'post_name',
 102              'callback_method' => 'callback_slug'
 103          );
 104  
 105          // Forum description.
 106          $this->field_map[] = array(
 107              'from_tablename'  => 'forum',
 108              'from_fieldname'  => 'forum_description',
 109              'to_type'         => 'forum',
 110              'to_fieldname'    => 'post_content',
 111              'callback_method' => 'callback_null'
 112          );
 113  
 114          // Forum display order (Starts from 1)
 115          $this->field_map[] = array(
 116              'from_tablename' => 'forum',
 117              'from_fieldname' => 'forum_order',
 118              'to_type'        => 'forum',
 119              'to_fieldname'   => 'menu_order'
 120          );
 121  
 122          // Forum type (Category = 0 or Forum > 0, Stored in postmeta)
 123          $this->field_map[] = array(
 124              'from_tablename'  => 'forum',
 125              'from_fieldname'  => 'forum_parent',
 126              'to_type'         => 'forum',
 127              'to_fieldname'    => '_bbp_forum_type',
 128              'callback_method' => 'callback_forum_type'
 129          );
 130  
 131          // Forum status (Set a default value 'open', Stored in postmeta)
 132          $this->field_map[] = array(
 133              'to_type'      => 'forum',
 134              'to_fieldname' => '_bbp_status',
 135              'default'      => 'open'
 136          );
 137  
 138          // Forum dates.
 139          $this->field_map[] = array(
 140              'to_type'      => 'forum',
 141              'to_fieldname' => 'post_date',
 142              'default'      => date('Y-m-d H:i:s')
 143          );
 144          $this->field_map[] = array(
 145              'to_type'      => 'forum',
 146              'to_fieldname' => 'post_date_gmt',
 147              'default'      => date('Y-m-d H:i:s')
 148          );
 149          $this->field_map[] = array(
 150              'to_type'      => 'forum',
 151              'to_fieldname' => 'post_modified',
 152              'default'      => date('Y-m-d H:i:s')
 153          );
 154          $this->field_map[] = array(
 155              'to_type'      => 'forum',
 156              'to_fieldname' => 'post_modified_gmt',
 157              'default'      => date('Y-m-d H:i:s')
 158          );
 159  
 160          /** Topic Section *****************************************************/
 161  
 162          // Old topic id (Stored in postmeta)
 163          $this->field_map[] = array(
 164              'from_tablename'  => 'forum_t',
 165              'from_fieldname'  => 'thread_id',
 166              'from_expression' => 'WHERE thread_parent = 0',
 167              'to_type'         => 'topic',
 168              'to_fieldname'    => '_bbp_old_topic_id'
 169          );
 170  
 171          // Topic reply count (Stored in postmeta)
 172          $this->field_map[] = array(
 173              'from_tablename'  => 'forum_t',
 174              'from_fieldname'  => 'thread_total_replies',
 175              'to_type'         => 'topic',
 176              'to_fieldname'    => '_bbp_reply_count',
 177              'callback_method' => 'callback_topic_reply_count'
 178          );
 179  
 180          // Topic total reply count (Includes unpublished replies, Stored in postmeta)
 181          $this->field_map[] = array(
 182              'from_tablename'  => 'forum_t',
 183              'from_fieldname'  => 'thread_total_replies',
 184              'to_type'         => 'topic',
 185              'to_fieldname'    => '_bbp_total_reply_count',
 186              'callback_method' => 'callback_topic_reply_count'
 187          );
 188  
 189          // Topic parent forum id (If no parent, then 0. Stored in postmeta)
 190          $this->field_map[] = array(
 191              'from_tablename'  => 'forum_t',
 192              'from_fieldname'  => 'thread_forum_id',
 193              'to_type'         => 'topic',
 194              'to_fieldname'    => '_bbp_forum_id',
 195              'callback_method' => 'callback_forumid'
 196          );
 197  
 198          // Topic author.
 199          // Note: Uses a custom callback to transform user id from '1.Administrator e107v1' to numeric user id.
 200          $this->field_map[] = array(
 201              'from_tablename'  => 'forum_t',
 202              'from_fieldname'  => 'thread_user',
 203              'to_type'         => 'topic',
 204              'to_fieldname'    => 'post_author',
 205              'callback_method' => 'callback_e107v1_userid'
 206          );
 207  
 208          // Topic content.
 209          $this->field_map[] = array(
 210              'from_tablename'  => 'forum_t',
 211              'from_fieldname'  => 'thread_thread',
 212              'to_type'         => 'topic',
 213              'to_fieldname'    => 'post_content',
 214              'callback_method' => 'callback_html'
 215          );
 216  
 217          // Topic title.
 218          $this->field_map[] = array(
 219              'from_tablename' => 'forum_t',
 220              'from_fieldname' => 'thread_name',
 221              'to_type'        => 'topic',
 222              'to_fieldname'   => 'post_title'
 223          );
 224  
 225          // Topic slug (Clean name to avoid conflicts)
 226          $this->field_map[] = array(
 227              'from_tablename'  => 'forum_t',
 228              'from_fieldname'  => 'thread_name',
 229              'to_type'         => 'topic',
 230              'to_fieldname'    => 'post_name',
 231              'callback_method' => 'callback_slug'
 232          );
 233  
 234          // Topic status (Open or Closed, e107 v1.x open = 1 & closed = 0)
 235          $this->field_map[] = array(
 236              'from_tablename'  => 'forum_t',
 237              'from_fieldname'  => 'thread_active',
 238              'to_type'         => 'topic',
 239              'to_fieldname'    => '_bbp_old_closed_status_id',
 240              'callback_method' => 'callback_topic_status'
 241          );
 242  
 243          // Topic parent forum id (If no parent, then 0)
 244          $this->field_map[] = array(
 245              'from_tablename'  => 'forum_t',
 246              'from_fieldname'  => 'thread_forum_id',
 247              'to_type'         => 'topic',
 248              'to_fieldname'    => 'post_parent',
 249              'callback_method' => 'callback_forumid'
 250          );
 251  
 252          // Sticky status (Stored in postmeta)
 253          $this->field_map[] = array(
 254              'from_tablename'  => 'forum_t',
 255              'from_fieldname'  => 'thread_s',
 256              'to_type'         => 'topic',
 257              'to_fieldname'    => '_bbp_old_sticky_status_id',
 258              'callback_method' => 'callback_sticky_status'
 259          );
 260  
 261          // Topic dates.
 262          $this->field_map[] = array(
 263              'from_tablename'  => 'forum_t',
 264              'from_fieldname'  => 'thread_datestamp',
 265              'to_type'         => 'topic',
 266              'to_fieldname'    => 'post_date',
 267              'callback_method' => 'callback_datetime'
 268          );
 269          $this->field_map[] = array(
 270              'from_tablename'  => 'forum_t',
 271              'from_fieldname'  => 'thread_datestamp',
 272              'to_type'         => 'topic',
 273              'to_fieldname'    => 'post_date_gmt',
 274              'callback_method' => 'callback_datetime'
 275          );
 276          $this->field_map[] = array(
 277              'from_tablename'  => 'forum_t',
 278              'from_fieldname'  => 'thread_datestamp',
 279              'to_type'         => 'topic',
 280              'to_fieldname'    => 'post_modified',
 281              'callback_method' => 'callback_datetime'
 282          );
 283          $this->field_map[] = array(
 284              'from_tablename'  => 'forum_t',
 285              'from_fieldname'  => 'thread_datestamp',
 286              'to_type'         => 'topic',
 287              'to_fieldname'    => 'post_modified_gmt',
 288              'callback_method' => 'callback_datetime'
 289          );
 290          $this->field_map[] = array(
 291              'from_tablename'  => 'forum_t',
 292              'from_fieldname'  => 'thread_datestamp',
 293              'to_type'         => 'topic',
 294              'to_fieldname'    => '_bbp_last_active_time',
 295              'callback_method' => 'callback_datetime'
 296          );
 297  
 298          /** Tags Section ******************************************************/
 299  
 300          /**
 301           * e107 v1.x Forums do not support topic tags out of the box
 302           */
 303  
 304          /** Reply Section *****************************************************/
 305  
 306          // Old reply id (Stored in postmeta)
 307          $this->field_map[] = array(
 308              'from_tablename'  => 'forum_t',
 309              'from_fieldname'  => 'thread_id',
 310              'from_expression' => 'WHERE thread_parent != 0',
 311              'to_type'         => 'reply',
 312              'to_fieldname'    => '_bbp_old_reply_id'
 313          );
 314  
 315          // Reply parent forum id (If no parent, then 0. Stored in postmeta)
 316          $this->field_map[] = array(
 317              'from_tablename'  => 'forum_t',
 318              'from_fieldname'  => 'thread_forum_id',
 319              'to_type'         => 'reply',
 320              'to_fieldname'    => '_bbp_forum_id',
 321              'callback_method' => 'callback_topicid_to_forumid'
 322          );
 323  
 324          // Reply parent topic id (If no parent, then 0. Stored in postmeta)
 325          $this->field_map[] = array(
 326              'from_tablename'  => 'forum_t',
 327              'from_fieldname'  => 'thread_parent',
 328              'to_type'         => 'reply',
 329              'to_fieldname'    => '_bbp_topic_id',
 330              'callback_method' => 'callback_topicid'
 331          );
 332  
 333          // Reply author.
 334          // Note: Uses a custom callback to transform user id from '1.Administrator e107v1' to numeric user id.
 335          $this->field_map[] = array(
 336              'from_tablename'  => 'forum_t',
 337              'from_fieldname'  => 'thread_user',
 338              'to_type'         => 'reply',
 339              'to_fieldname'    => 'post_author',
 340              'callback_method' => 'callback_e107v1_userid'
 341          );
 342  
 343          // Reply content.
 344          $this->field_map[] = array(
 345              'from_tablename'  => 'forum_t',
 346              'from_fieldname'  => 'thread_thread',
 347              'to_type'         => 'reply',
 348              'to_fieldname'    => 'post_content',
 349              'callback_method' => 'callback_html'
 350          );
 351  
 352          // Reply parent topic id (If no parent, then 0)
 353          $this->field_map[] = array(
 354              'from_tablename'  => 'forum_t',
 355              'from_fieldname'  => 'thread_parent',
 356              'to_type'         => 'reply',
 357              'to_fieldname'    => 'post_parent',
 358              'callback_method' => 'callback_topicid'
 359          );
 360  
 361          // Reply dates.
 362          $this->field_map[] = array(
 363              'from_tablename'  => 'forum_t',
 364              'from_fieldname'  => 'thread_datestamp',
 365              'to_type'         => 'reply',
 366              'to_fieldname'    => 'post_date',
 367              'callback_method' => 'callback_datetime'
 368          );
 369          $this->field_map[] = array(
 370              'from_tablename'  => 'forum_t',
 371              'from_fieldname'  => 'thread_datestamp',
 372              'to_type'         => 'reply',
 373              'to_fieldname'    => 'post_date_gmt',
 374              'callback_method' => 'callback_datetime'
 375          );
 376          $this->field_map[] = array(
 377              'from_tablename'  => 'forum_t',
 378              'from_fieldname'  => 'thread_datestamp',
 379              'to_type'         => 'reply',
 380              'to_fieldname'    => 'post_modified',
 381              'callback_method' => 'callback_datetime'
 382          );
 383          $this->field_map[] = array(
 384              'from_tablename'  => 'forum_t',
 385              'from_fieldname'  => 'thread_datestamp',
 386              'to_type'         => 'reply',
 387              'to_fieldname'    => 'post_modified_gmt',
 388              'callback_method' => 'callback_datetime'
 389          );
 390  
 391          /** User Section ******************************************************/
 392  
 393          // Store old user id (Stored in usermeta)
 394          $this->field_map[] = array(
 395              'from_tablename' => 'user',
 396              'from_fieldname' => 'user_id',
 397              'to_type'        => 'user',
 398              'to_fieldname'   => '_bbp_old_user_id'
 399          );
 400  
 401          // Store old user password (Stored in usermeta serialized with salt)
 402          $this->field_map[] = array(
 403              'from_tablename'  => 'user',
 404              'from_fieldname'  => 'user_password',
 405              'to_type'         => 'user',
 406              'to_fieldname'    => '_bbp_password',
 407              'callback_method' => 'callback_savepass'
 408          );
 409  
 410          // User password verify class (Stored in usermeta for verifying password)
 411          $this->field_map[] = array(
 412              'to_type'      => 'user',
 413              'to_fieldname' => '_bbp_class',
 414              'default'      => 'e107v1'
 415          );
 416  
 417          // User name.
 418          $this->field_map[] = array(
 419              'from_tablename' => 'user',
 420              'from_fieldname' => 'user_loginname',
 421              'to_type'        => 'user',
 422              'to_fieldname'   => 'user_login'
 423          );
 424  
 425          // User nice name.
 426          $this->field_map[] = array(
 427              'from_tablename' => 'user',
 428              'from_fieldname' => 'user_loginname',
 429              'to_type'        => 'user',
 430              'to_fieldname'   => 'user_nicename'
 431          );
 432  
 433          // User email.
 434          $this->field_map[] = array(
 435              'from_tablename' => 'user',
 436              'from_fieldname' => 'user_email',
 437              'to_type'        => 'user',
 438              'to_fieldname'   => 'user_email'
 439          );
 440  
 441          // User registered.
 442          $this->field_map[] = array(
 443              'from_tablename'  => 'user',
 444              'from_fieldname'  => 'user_join',
 445              'to_type'         => 'user',
 446              'to_fieldname'    => 'user_registered',
 447              'callback_method' => 'callback_datetime'
 448          );
 449  
 450          // User display name.
 451          $this->field_map[] = array(
 452              'from_tablename' => 'user',
 453              'from_fieldname' => 'user_name',
 454              'to_type'        => 'user',
 455              'to_fieldname'   => 'display_name'
 456          );
 457  
 458          // Store Signature (Stored in usermeta)
 459          $this->field_map[] = array(
 460              'from_tablename'  => 'user',
 461              'from_fieldname'  => 'user_signature',
 462              'to_fieldname'    => '_bbp_e107v1_user_sig',
 463              'to_type'         => 'user',
 464              'callback_method' => 'callback_html'
 465          );
 466      }
 467  
 468      /**
 469       * This method allows us to indicates what is or is not converted for each
 470       * converter.
 471       */
 472  	public function info() {
 473          return '';
 474      }
 475  
 476      /**
 477       * This method is to save the salt and password together. That
 478       * way when we authenticate it we can get it out of the database
 479       * as one value. Array values are auto sanitized by WordPress.
 480       */
 481  	public function callback_savepass( $field, $row ) {
 482          $pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
 483          return $pass_array;
 484      }
 485  
 486      /**
 487       * This method is to take the pass out of the database and compare
 488       * to a pass the user has typed in.
 489       */
 490  	public function authenticate_pass( $password, $serialized_pass ) {
 491          $pass_array = unserialize( $serialized_pass );
 492          return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) );
 493      }
 494  
 495      /**
 496       * Translate the forum type from e107 v1.x numerics to WordPress's strings.
 497       *
 498       * @param int $status e107 v1.x numeric forum type
 499       * @return string WordPress safe
 500       */
 501  	public function callback_forum_type( $status = 0 ) {
 502          if ( $status == 0 ) {
 503              $status = 'category';
 504          } else {
 505              $status = 'forum';
 506          }
 507          return $status;
 508      }
 509  
 510      /**
 511       * Translate the post status from e107 v1.x numerics to WordPress's strings.
 512       *
 513       * @param int $status e107 v1.x numeric topic status
 514       * @return string WordPress safe
 515       */
 516  	public function callback_topic_status( $status = 1 ) {
 517          switch ( $status ) {
 518              case 0 :
 519                  $status = 'closed';
 520                  break;
 521  
 522              case 1 :
 523              default :
 524                  $status = 'publish';
 525                  break;
 526          }
 527          return $status;
 528      }
 529  
 530      /**
 531       * Translate the topic sticky status type from e107 v1.x numerics to WordPress's strings.
 532       *
 533       * @param int $status e107 v1.x numeric forum type
 534       * @return string WordPress safe
 535       */
 536  	public function callback_sticky_status( $status = 0 ) {
 537          switch ( $status ) {
 538              case 2 :
 539                  $status = 'super-sticky'; // e107 Announcement Sticky 'thread_s = 2'
 540                  break;
 541  
 542              case 1 :
 543                  $status = 'sticky';       // e107 Sticky 'thread_s = 1'
 544                  break;
 545  
 546              case 0 :
 547              default :
 548                  $status = 'normal';       // e107 normal topic 'thread_s = 0'
 549                  break;
 550          }
 551          return $status;
 552      }
 553  
 554      /**
 555       * Verify the topic/reply count.
 556       *
 557       * @param int $count e107 v1.x topic/reply counts
 558       * @return string WordPress safe
 559       */
 560  	public function callback_topic_reply_count( $count = 1 ) {
 561          $count = absint( (int) $count - 1 );
 562          return $count;
 563      }
 564  
 565      /**
 566       * Override the `callback_user` function in 'converter.php' for custom e107v1 imports
 567       *
 568       * A mini cache system to reduce database calls to user ID's
 569       *
 570       * @param string $field
 571       * @return string
 572       */
 573  	protected function callback_e107v1_userid( $field ) {
 574  
 575          // Strip only the user id from the topic and reply authors
 576          $field = preg_replace( '/(\d+?)+\.[\S\s]+/', '$1', $field );
 577  
 578          if ( ! isset( $this->map_userid[ $field ] ) ) {
 579              if ( ! empty( $this->sync_table ) ) {
 580                  $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_user_id', $field ) );
 581              } else {
 582                  $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT user_id AS value_id FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_user_id', $field ) );
 583              }
 584  
 585              if ( ! is_null( $row ) ) {
 586                  $this->map_userid[ $field ] = $row->value_id;
 587              } else {
 588                  if ( true === $this->convert_users ) {
 589                      $this->map_userid[ $field ] = 0;
 590                  } else {
 591                      $this->map_userid[ $field ] = $field;
 592                  }
 593              }
 594          }
 595          return $this->map_userid[ $field ];
 596      }
 597  
 598      /**
 599       * This callback processes any custom parser.php attributes and custom code with preg_replace
 600       */
 601  	protected function callback_html( $field ) {
 602  
 603          // Strips custom e107v1 'magic_url' and 'bbcode_uid' first from $field before parsing $field to parser.php
 604          $e107v1_markup = $field;
 605          $e107v1_markup = html_entity_decode( $e107v1_markup );
 606  
 607          // Replace '[blockquote]' with '<blockquote>'
 608          $e107v1_markup = preg_replace( '/\[blockquote\]/',   '<blockquote>',  $e107v1_markup );
 609          // Replace '[/blockquote]' with '</blockquote>'
 610          $e107v1_markup = preg_replace( '/\[\/blockquote\]/', '</blockquote>', $e107v1_markup );
 611  
 612          // Replace '[quote$1=$2]' with '<em>$2 wrote:</em><blockquote>"
 613          $e107v1_markup = preg_replace( '/\[quote(.*?)=(.*?)\]/', '<em>@$2 wrote:</em><blockquote>', $e107v1_markup );
 614          // Replace '[/quote$1]' with '</blockquote>"
 615          $e107v1_markup = preg_replace( '/\[\/quote(.*?)\]/' ,    '</blockquote>',                   $e107v1_markup );
 616  
 617          // Remove '[justify]'
 618          $e107v1_markup = preg_replace( '/\[justify\]/',   '', $e107v1_markup );
 619          // Remove '[/justify]'
 620          $e107v1_markup = preg_replace( '/\[\/justify\]/', '', $e107v1_markup );
 621  
 622          // Replace '[link=(https|http)://$2]$3[/link]' with '<a href="$1://$2">$3</a>'
 623          $e107v1_markup = preg_replace( '/\[link\=(https|http)\:\/\/(.*?)\](.*?)\[\/link\]/i',  '<a href="$1://$2">$3</a>',  $e107v1_markup );
 624  
 625          // Replace '[list=(decimal|lower-roman|upper-roman|lower-alpha|upper-alpha)]' with '[list]'
 626          $e107v1_markup = preg_replace( '/\[list\=(decimal|lower-roman|upper-roman|lower-alpha|upper-alpha)\]/i',  '[list]',  $e107v1_markup );
 627  
 628          // Replace '[youtube]$1[/youtube]' with '$1"
 629          $e107v1_markup = preg_replace( '/\[youtube\](.*?)\[\/youtube\]/', 'https://youtu.be/$1', $e107v1_markup );
 630  
 631          // Now that e107v1 custom HTML has been stripped put the cleaned HTML back in $field
 632          $field = $e107v1_markup;
 633  
 634          // Parse out any bbCodes in $field with the BBCode 'parser.php'
 635          return parent::callback_html( $field );
 636      }
 637  }


Generated: Wed Sep 18 01:01:26 2019 Cross-referenced by PHPXref 0.7.1