[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * bbPress Phorum Converter
   5   *
   6   * @package bbPress
   7   * @subpackage Converters
   8   */
   9  
  10  /**
  11   * Implementation of Phorum Forum converter.
  12   *
  13   * @since 2.5.0 bbPress (r5141)
  14   *
  15   * @link Codex Docs https://codex.bbpress.org/import-forums/phorum
  16   */
  17  class Phorum 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' => 'forum_id',
  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'  => 'parent_id',
  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' => 'thread_count',
  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' => 'message_count',
  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' => 'display_order',
  96              'to_type'        => 'forum',
  97              'to_fieldname'   => 'menu_order'
  98          );
  99  
 100          // Forum type (Category = 1 or Forum = 0, Stored in postmeta)
 101          $this->field_map[] = array(
 102              'from_tablename'  => 'forums',
 103              'from_fieldname'  => 'folder_flag',
 104              'to_type'         => 'forum',
 105              'to_fieldname'    => '_bbp_forum_type',
 106              'callback_method' => 'callback_forum_type'
 107          );
 108  
 109          // Forum status (Set a default value 'open', Stored in postmeta)
 110          $this->field_map[] = array(
 111              'to_type'      => 'forum',
 112              'to_fieldname' => '_bbp_status',
 113              'default'      => 'open'
 114          );
 115  
 116          // Forum dates.
 117          $this->field_map[] = array(
 118              'to_type'      => 'forum',
 119              'to_fieldname' => 'post_date',
 120              'default'      => date('Y-m-d H:i:s')
 121          );
 122          $this->field_map[] = array(
 123              'to_type'      => 'forum',
 124              'to_fieldname' => 'post_date_gmt',
 125              'default'      => date('Y-m-d H:i:s')
 126          );
 127          $this->field_map[] = array(
 128              'to_type'      => 'forum',
 129              'to_fieldname' => 'post_modified',
 130              'default'      => date('Y-m-d H:i:s')
 131          );
 132          $this->field_map[] = array(
 133              'to_type'      => 'forum',
 134              'to_fieldname' => 'post_modified_gmt',
 135              'default'      => date('Y-m-d H:i:s')
 136          );
 137  
 138          /** Topic Section *****************************************************/
 139  
 140          // Old topic id (Stored in postmeta)
 141          $this->field_map[] = array(
 142              'from_tablename'  => 'messages',
 143              'from_fieldname'  => 'thread',
 144              'from_expression' => 'WHERE parent_id = 0',
 145              'to_type'         => 'topic',
 146              'to_fieldname'    => '_bbp_old_topic_id'
 147          );
 148  
 149          // Topic reply count (Stored in postmeta)
 150          $this->field_map[] = array(
 151              'from_tablename'  => 'messages',
 152              'from_fieldname'  => 'thread_count',
 153              'to_type'         => 'topic',
 154              'to_fieldname'    => '_bbp_reply_count',
 155              'callback_method' => 'callback_topic_reply_count'
 156          );
 157  
 158          // Topic total reply count (Includes unpublished replies, Stored in postmeta)
 159          $this->field_map[] = array(
 160              'from_tablename'  => 'messages',
 161              'from_fieldname'  => 'thread_count',
 162              'to_type'         => 'topic',
 163              'to_fieldname'    => '_bbp_total_reply_count',
 164              'callback_method' => 'callback_topic_reply_count'
 165          );
 166  
 167          // Topic parent forum id (If no parent, then 0, Stored in postmeta)
 168          $this->field_map[] = array(
 169              'from_tablename'  => 'messages',
 170              'from_fieldname'  => 'forum_id',
 171              'to_type'         => 'topic',
 172              'to_fieldname'    => '_bbp_forum_id',
 173              'callback_method' => 'callback_forumid'
 174          );
 175  
 176          // Topic author.
 177          $this->field_map[] = array(
 178              'from_tablename'  => 'messages',
 179              'from_fieldname'  => 'user_id',
 180              'to_type'         => 'topic',
 181              'to_fieldname'    => 'post_author',
 182              'callback_method' => 'callback_userid'
 183          );
 184  
 185          // Topic author name (Stored in postmeta as _bbp_anonymous_name)
 186          $this->field_map[] = array(
 187              'from_tablename' => 'messages',
 188              'from_fieldname' => 'author',
 189              'to_type'        => 'topic',
 190              'to_fieldname'   => '_bbp_old_topic_author_name_id'
 191          );
 192  
 193          // Is the topic anonymous (Stored in postmeta)
 194          $this->field_map[] = array(
 195              'from_tablename'  => 'messages',
 196              'from_fieldname'  => 'user_id',
 197              'to_type'         => 'topic',
 198              'to_fieldname'    => '_bbp_old_is_topic_anonymous_id',
 199              'callback_method' => 'callback_check_anonymous'
 200          );
 201  
 202          // Topic Author ip (Stored in postmeta)
 203          $this->field_map[] = array(
 204              'from_tablename'  => 'messages',
 205              'from_fieldname'  => 'ip',
 206              'to_type'         => 'topic',
 207              'to_fieldname'    => '_bbp_author_ip'
 208          );
 209  
 210          // Topic content.
 211          $this->field_map[] = array(
 212              'from_tablename'  => 'messages',
 213              'from_fieldname'  => 'body',
 214              'to_type'         => 'topic',
 215              'to_fieldname'    => 'post_content',
 216              'callback_method' => 'callback_html'
 217          );
 218  
 219          // Topic title.
 220          $this->field_map[] = array(
 221              'from_tablename' => 'messages',
 222              'from_fieldname' => 'subject',
 223              'to_type'        => 'topic',
 224              'to_fieldname'   => 'post_title'
 225          );
 226  
 227          // Topic slug (Clean name to avoid conflicts)
 228          $this->field_map[] = array(
 229              'from_tablename'  => 'messages',
 230              'from_fieldname'  => 'subject',
 231              'to_type'         => 'topic',
 232              'to_fieldname'    => 'post_name',
 233              'callback_method' => 'callback_slug'
 234          );
 235  
 236          // Topic parent forum id (If no parent, then 0)
 237          $this->field_map[] = array(
 238              'from_tablename'  => 'messages',
 239              'from_fieldname'  => 'forum_id',
 240              'to_type'         => 'topic',
 241              'to_fieldname'    => 'post_parent',
 242              'callback_method' => 'callback_forumid'
 243          );
 244  
 245          // Topic dates.
 246          $this->field_map[] = array(
 247              'from_tablename'  => 'messages',
 248              'from_fieldname'  => 'datestamp',
 249              'to_type'         => 'topic',
 250              'to_fieldname'    => 'post_date',
 251              'callback_method' => 'callback_datetime'
 252          );
 253          $this->field_map[] = array(
 254              'from_tablename'  => 'messages',
 255              'from_fieldname'  => 'datestamp',
 256              'to_type'         => 'topic',
 257              'to_fieldname'    => 'post_date_gmt',
 258              'callback_method' => 'callback_datetime'
 259          );
 260          $this->field_map[] = array(
 261              'from_tablename'  => 'messages',
 262              'from_fieldname'  => 'datestamp',
 263              'to_type'         => 'topic',
 264              'to_fieldname'    => 'post_modified',
 265              'callback_method' => 'callback_datetime'
 266          );
 267          $this->field_map[] = array(
 268              'from_tablename'  => 'messages',
 269              'from_fieldname'  => 'datestamp',
 270              'to_type'         => 'topic',
 271              'to_fieldname'    => 'post_modified_gmt',
 272              'callback_method' => 'callback_datetime'
 273          );
 274          $this->field_map[] = array(
 275              'from_tablename'  => 'messages',
 276              'from_fieldname'  => 'datestamp',
 277              'to_type'         => 'topic',
 278              'to_fieldname'    => '_bbp_last_active_time',
 279              'callback_method' => 'callback_datetime'
 280          );
 281  
 282          // Topic status (Open = 0 or Closed = 1)
 283          $this->field_map[] = array(
 284              'from_tablename'  => 'messages',
 285              'from_fieldname'  => 'closed',
 286              'to_type'         => 'topic',
 287              'to_fieldname'    => '_bbp_old_closed_status_id',
 288              'callback_method' => 'callback_topic_status'
 289          );
 290  
 291          /** Tags Section ******************************************************/
 292  
 293          /**
 294           * Phorum v5.2.19 Forums do not support topic tags out of the box
 295           */
 296  
 297          /** Topic Subscriptions Section ***************************************/
 298  
 299          // Subscribed topic ID (Stored in usermeta)
 300          $this->field_map[] = array(
 301              'from_tablename'  => 'subscribers',
 302              'from_fieldname'  => 'thread',
 303              'to_type'         => 'topic_subscriptions',
 304              'to_fieldname'    => '_bbp_subscriptions'
 305          );
 306  
 307          // Subscribed user ID (Stored in usermeta)
 308          $this->field_map[] = array(
 309              'from_tablename'  => 'subscribers',
 310              'from_fieldname'  => 'user_id',
 311              'to_type'         => 'topic_subscriptions',
 312              'to_fieldname'    => 'user_id',
 313              'callback_method' => 'callback_userid'
 314          );
 315  
 316          /** Reply Section *****************************************************/
 317  
 318          // Old reply id (Stored in postmeta)
 319          $this->field_map[] = array(
 320              'from_tablename'  => 'messages',
 321              'from_fieldname'  => 'message_id',
 322              'from_expression' => 'WHERE parent_id != 0',
 323              'to_type'         => 'reply',
 324              'to_fieldname'    => '_bbp_old_reply_id'
 325          );
 326  
 327          // Reply parent forum id (If no parent, then 0. Stored in postmeta)
 328          $this->field_map[] = array(
 329              'from_tablename'  => 'messages',
 330              'from_fieldname'  => 'forum_id',
 331              'to_type'         => 'reply',
 332              'to_fieldname'    => '_bbp_forum_id',
 333              'callback_method' => 'callback_forumid'
 334          );
 335  
 336          // Reply parent topic id (If no parent, then 0. Stored in postmeta)
 337          $this->field_map[] = array(
 338              'from_tablename'  => 'messages',
 339              'from_fieldname'  => 'thread',
 340              'to_type'         => 'reply',
 341              'to_fieldname'    => '_bbp_topic_id',
 342              'callback_method' => 'callback_topicid'
 343          );
 344  
 345          // Reply author ip (Stored in postmeta)
 346          $this->field_map[] = array(
 347              'from_tablename' => 'messages',
 348              'from_fieldname' => 'ip',
 349              'to_type'        => 'reply',
 350              'to_fieldname'   => '_bbp_author_ip'
 351          );
 352  
 353          // Reply author.
 354          $this->field_map[] = array(
 355              'from_tablename'  => 'messages',
 356              'from_fieldname'  => 'user_id',
 357              'to_type'         => 'reply',
 358              'to_fieldname'    => 'post_author',
 359              'callback_method' => 'callback_userid'
 360          );
 361  
 362          // Reply author name (Stored in postmeta as _bbp_anonymous_name)
 363          $this->field_map[] = array(
 364              'from_tablename'  => 'messages',
 365              'from_fieldname'  => 'author',
 366              'to_type'         => 'reply',
 367              'to_fieldname'   => '_bbp_old_reply_author_name_id'
 368          );
 369  
 370          // Is the reply anonymous  (Stored in postmeta)
 371          $this->field_map[] = array(
 372              'from_tablename'  => 'messages',
 373              'from_fieldname'  => 'user_id',
 374              'to_type'         => 'reply',
 375              'to_fieldname'    => '_bbp_old_is_reply_anonymous_id',
 376              'callback_method' => 'callback_check_anonymous'
 377          );
 378  
 379          // Reply content.
 380          $this->field_map[] = array(
 381              'from_tablename'  => 'messages',
 382              'from_fieldname'  => 'body',
 383              'to_type'         => 'reply',
 384              'to_fieldname'    => 'post_content',
 385              'callback_method' => 'callback_html'
 386          );
 387  
 388          // Reply parent topic id (If no parent, then 0)
 389          $this->field_map[] = array(
 390              'from_tablename'  => 'messages',
 391              'from_fieldname'  => 'thread',
 392              'to_type'         => 'reply',
 393              'to_fieldname'    => 'post_parent',
 394              'callback_method' => 'callback_topicid'
 395          );
 396  
 397          // Reply dates.
 398          $this->field_map[] = array(
 399              'from_tablename'  => 'messages',
 400              'from_fieldname'  => 'datestamp',
 401              'to_type'         => 'reply',
 402              'to_fieldname'    => 'post_date',
 403              'callback_method' => 'callback_datetime'
 404          );
 405          $this->field_map[] = array(
 406              'from_tablename'  => 'messages',
 407              'from_fieldname'  => 'datestamp',
 408              'to_type'         => 'reply',
 409              'to_fieldname'    => 'post_date_gmt',
 410              'callback_method' => 'callback_datetime'
 411          );
 412          $this->field_map[] = array(
 413              'from_tablename'  => 'messages',
 414              'from_fieldname'  => 'datestamp',
 415              'to_type'         => 'reply',
 416              'to_fieldname'    => 'post_modified',
 417              'callback_method' => 'callback_datetime'
 418          );
 419          $this->field_map[] = array(
 420              'from_tablename'  => 'messages',
 421              'from_fieldname'  => 'datestamp',
 422              'to_type'         => 'reply',
 423              'to_fieldname'    => 'post_modified_gmt',
 424              'callback_method' => 'callback_datetime'
 425          );
 426  
 427          /** User Section ******************************************************/
 428  
 429          // Store old user id (Stored in usermeta)
 430          $this->field_map[] = array(
 431              'from_tablename' => 'users',
 432              'from_fieldname' => 'user_id',
 433              'to_type'        => 'user',
 434              'to_fieldname'   => '_bbp_old_user_id'
 435          );
 436  
 437          // Store old user password (Stored in usermeta serialized with salt)
 438          $this->field_map[] = array(
 439              'from_tablename'  => 'users',
 440              'from_fieldname'  => 'password',
 441              'to_type'         => 'user',
 442              'to_fieldname'    => '_bbp_password',
 443              'callback_method' => 'callback_savepass'
 444          );
 445  
 446          // Store old user salt (This is only used for the SELECT row info for the above password save)
 447  //        $this->field_map[] = array(
 448  //            'from_tablename' => 'users',
 449  //            'from_fieldname' => 'salt',
 450  //            'to_type'        => 'user',
 451  //            'to_fieldname'   => ''
 452  //        );
 453  
 454          // User password verify class (Stored in usermeta for verifying password)
 455          $this->field_map[] = array(
 456              'to_type'      => 'users',
 457              'to_fieldname' => '_bbp_class',
 458              'default'      => 'Phorum'
 459          );
 460  
 461          // User name.
 462          $this->field_map[] = array(
 463              'from_tablename' => 'users',
 464              'from_fieldname' => 'username',
 465              'to_type'        => 'user',
 466              'to_fieldname'   => 'user_login'
 467          );
 468  
 469          // User nice name.
 470          $this->field_map[] = array(
 471              'from_tablename' => 'users',
 472              'from_fieldname' => 'display_name',
 473              'to_type'        => 'user',
 474              'to_fieldname'   => 'user_nicename'
 475          );
 476  
 477          // User email.
 478          $this->field_map[] = array(
 479              'from_tablename' => 'users',
 480              'from_fieldname' => 'email',
 481              'to_type'        => 'user',
 482              'to_fieldname'   => 'user_email'
 483          );
 484  
 485          // User registered.
 486          $this->field_map[] = array(
 487              'from_tablename'  => 'users',
 488              'from_fieldname'  => 'date_added',
 489              'to_type'         => 'user',
 490              'to_fieldname'    => 'user_registered',
 491              'callback_method' => 'callback_datetime'
 492          );
 493  
 494          // User display name.
 495          $this->field_map[] = array(
 496              'from_tablename' => 'users',
 497              'from_fieldname' => 'real_name',
 498              'to_type'        => 'user',
 499              'to_fieldname'   => 'display_name'
 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_phorum_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 forum type from Phorum v5.2.19 numerics to WordPress's strings.
 542       *
 543       * @param int $status Phorum v5.2.19 numeric forum type
 544       * @return string WordPress safe
 545       */
 546  	public function callback_forum_type( $status = 0 ) {
 547          switch ( $status ) {
 548              case 1 :
 549                  $status = 'category';
 550                  break;
 551  
 552              case 0  :
 553              default :
 554                  $status = 'forum';
 555                  break;
 556          }
 557          return $status;
 558      }
 559  
 560      /**
 561       * Translate the post status from Phorum v5.2.19 numerics to WordPress's strings.
 562       *
 563       * @param int $status Phorum v5.2.19 numeric topic status
 564       * @return string WordPress safe
 565       */
 566  	public function callback_topic_status( $status = 0 ) {
 567          switch ( $status ) {
 568              case 1 :
 569                  $status = 'closed';
 570                  break;
 571  
 572              case 0  :
 573              default :
 574                  $status = 'publish';
 575                  break;
 576          }
 577          return $status;
 578      }
 579  
 580      /**
 581       * Verify the topic/reply count.
 582       *
 583       * @param int $count Phorum v5.2.19 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