[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * bbPress Mingle Converter
   5   *
   6   * @package bbPress
   7   * @subpackage Converters
   8   */
   9  
  10  /**
  11   * Implementation of Mingle Forums converter.
  12   *
  13   * @since 2.3.0 bbPress (r4691)
  14   *
  15   * @link Codex Docs https://codex.bbpress.org/import-forums/mingle
  16   */
  17  class Mingle 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_forums',
  43              'from_fieldname' => '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_forums',
  51              'from_fieldname' => 'parent_id',
  52              'to_type'        => 'forum',
  53              'to_fieldname'   => '_bbp_old_forum_parent_id'
  54          );
  55  
  56          // Forum title.
  57          $this->field_map[] = array(
  58              'from_tablename' => 'forum_forums',
  59              'from_fieldname' => 'name',
  60              'to_type'        => 'forum',
  61              'to_fieldname'   => 'post_title'
  62          );
  63  
  64          // Forum slug (Clean name to avoid confilcts)
  65          $this->field_map[] = array(
  66              'from_tablename'  => 'forum_forums',
  67              'from_fieldname'  => 'name',
  68              'to_type'         => 'forum',
  69              'to_fieldname'    => 'post_name',
  70              'callback_method' => 'callback_slug'
  71          );
  72          // Forum description.
  73          $this->field_map[] = array(
  74              'from_tablename'  => 'forum_forums',
  75              'from_fieldname'  => 'description',
  76              'to_type'         => 'forum',
  77              'to_fieldname'    => 'post_content',
  78              'callback_method' => 'callback_null'
  79          );
  80  
  81          // Forum display order (Starts from 1)
  82          $this->field_map[] = array(
  83              'from_tablename' => 'forum_forums',
  84              'from_fieldname' => 'sort',
  85              'to_type'        => 'forum',
  86              'to_fieldname'   => 'menu_order'
  87          );
  88  
  89          // Forum type (Set a default value 'forum', Stored in postmeta)
  90          $this->field_map[] = array(
  91              'to_type'      => 'forum',
  92              'to_fieldname' => '_bbp_forum_type',
  93              'default'      => 'forum'
  94          );
  95  
  96          // Forum status (Set a default value 'open', Stored in postmeta)
  97          $this->field_map[] = array(
  98              'to_type'      => 'forum',
  99              'to_fieldname' => '_bbp_status',
 100              'default'      => 'open'
 101          );
 102  
 103          // Forum dates.
 104          $this->field_map[] = array(
 105              'to_type'        => 'forum',
 106              'to_fieldname'   => 'post_date',
 107              'default'        => date('Y-m-d H:i:s')
 108          );
 109          $this->field_map[] = array(
 110              'to_type'        => 'forum',
 111              'to_fieldname'   => 'post_date_gmt',
 112              'default'        => date('Y-m-d H:i:s')
 113          );
 114          $this->field_map[] = array(
 115              'to_type'        => 'forum',
 116              'to_fieldname'   => 'post_modified',
 117              'default'        => date('Y-m-d H:i:s')
 118          );
 119          $this->field_map[] = array(
 120              'to_type'        => 'forum',
 121              'to_fieldname'   => 'post_modified_gmt',
 122              'default'        => date('Y-m-d H:i:s')
 123          );
 124  
 125          /** Topic Section ******************************************************/
 126  
 127          // Old topic id (Stored in postmeta)
 128          $this->field_map[] = array(
 129              'from_tablename' => 'forum_threads',
 130              'from_fieldname' => 'id',
 131              'to_type'        => 'topic',
 132              'to_fieldname'   => '_bbp_old_topic_id'
 133          );
 134  
 135          // Topic parent forum id (If no parent, then 0. Stored in postmeta)
 136          $this->field_map[] = array(
 137              'from_tablename'  => 'forum_threads',
 138              'from_fieldname'  => 'parent_id',
 139              'to_type'         => 'topic',
 140              'to_fieldname'    => '_bbp_forum_id',
 141              'callback_method' => 'callback_forumid'
 142          );
 143  
 144          // Topic author.
 145          $this->field_map[] = array(
 146              'from_tablename'  => 'forum_threads',
 147              'from_fieldname'  => 'starter',
 148              'to_type'         => 'topic',
 149              'to_fieldname'    => 'post_author',
 150              'callback_method' => 'callback_userid'
 151          );
 152  
 153          // Topic content.
 154          // Note: We join the forum_posts table because forum_topics do not have topic content.
 155          $this->field_map[] = array(
 156              'from_tablename'  => 'forum_posts',
 157              'from_fieldname'  => 'text',
 158              'join_tablename'  => 'forum_threads',
 159              'join_type'       => 'INNER',
 160              'join_expression' => 'ON forum_posts.parent_id = forum_threads.id GROUP BY forum_threads.id',
 161              'to_type'         => 'topic',
 162              'to_fieldname'    => 'post_content',
 163              'callback_method' => 'callback_html'
 164          );
 165          // Topic title.
 166          $this->field_map[] = array(
 167              'from_tablename' => 'forum_threads',
 168              'from_fieldname' => 'subject',
 169              'to_type'        => 'topic',
 170              'to_fieldname'   => 'post_title'
 171          );
 172  
 173          // Topic slug (Clean name to avoid conflicts)
 174          $this->field_map[] = array(
 175              'from_tablename'  => 'forum_threads',
 176              'from_fieldname'  => 'subject',
 177              'to_type'         => 'topic',
 178              'to_fieldname'    => 'post_name',
 179              'callback_method' => 'callback_slug'
 180          );
 181  
 182          // Topic parent forum id (If no parent, then 0)
 183          $this->field_map[] = array(
 184              'from_tablename'  => 'forum_threads',
 185              'from_fieldname'  => 'parent_id',
 186              'to_type'         => 'topic',
 187              'to_fieldname'    => 'post_parent',
 188              'callback_method' => 'callback_forumid'
 189          );
 190  
 191          // Sticky status (Stored in postmeta)
 192          $this->field_map[] = array(
 193              'from_tablename'  => 'forum_threads',
 194              'from_fieldname'  => 'status',
 195              'to_type'         => 'topic',
 196              'to_fieldname'    => '_bbp_old_sticky_status_id',
 197              'callback_method' => 'callback_sticky_status'
 198          );
 199  
 200          // Topic dates.
 201          $this->field_map[] = array(
 202              'from_tablename'  => 'forum_threads',
 203              'from_fieldname'  => 'date',
 204              'to_type'         => 'topic',
 205              'to_fieldname'    => 'post_date'
 206          );
 207          $this->field_map[] = array(
 208              'from_tablename'  => 'forum_threads',
 209              'from_fieldname'  => 'date',
 210              'to_type'         => 'topic',
 211              'to_fieldname'    => 'post_date_gmt'
 212          );
 213          $this->field_map[] = array(
 214              'from_tablename'  => 'forum_threads',
 215              'from_fieldname'  => 'last_post',
 216              'to_type'         => 'topic',
 217              'to_fieldname'    => 'post_modified'
 218          );
 219          $this->field_map[] = array(
 220              'from_tablename'  => 'forum_threads',
 221              'from_fieldname'  => 'last_post',
 222              'to_type'         => 'topic',
 223              'to_fieldname'    => 'post_modified_gmt'
 224          );
 225          $this->field_map[] = array(
 226              'from_tablename' => 'forum_threads',
 227              'from_fieldname' => 'last_post',
 228              'to_type'        => 'topic',
 229              'to_fieldname'   => '_bbp_last_active_time'
 230          );
 231  
 232          // Topic status (Open or Closed)
 233          $this->field_map[] = array(
 234              'from_tablename'  => 'forum_threads',
 235              'from_fieldname'  => 'closed',
 236              'to_type'         => 'topic',
 237              'to_fieldname'    => '_bbp_old_closed_status_id',
 238              'callback_method' => 'callback_topic_status'
 239          );
 240  
 241          /** Tags Section ******************************************************/
 242  
 243          /**
 244           * Mingle Forums do not support topic tags
 245           */
 246  
 247          /** Reply Section ******************************************************/
 248  
 249          // Old reply id (Stored in postmeta)
 250          $this->field_map[] = array(
 251              'from_tablename' => 'forum_posts',
 252              'from_fieldname' => 'id',
 253              'to_type'        => 'reply',
 254              'to_fieldname'   => '_bbp_old_reply_id'
 255          );
 256  
 257          // Setup reply section table joins
 258          // We need join the 'forum_threads' table to only import replies
 259          $this->field_map[] = array(
 260              'from_tablename'  => 'forum_threads',
 261              'from_fieldname'  => 'date',
 262              'join_tablename'  => 'forum_posts',
 263              'join_type'       => 'INNER',
 264              'join_expression' => 'ON forum_posts.parent_id = forum_threads.id',
 265              'from_expression' => 'WHERE forum_threads.subject != forum_posts.subject',
 266              'to_type'         => 'reply',
 267              'to_fieldname'    => '_bbp_last_active_time'
 268          );
 269  
 270          // Reply parent forum id (If no parent, then 0. Stored in postmeta)
 271          $this->field_map[] = array(
 272              'from_tablename'  => 'forum_posts',
 273              'from_fieldname'  => 'parent_id',
 274              'to_type'         => 'reply',
 275              'to_fieldname'    => '_bbp_forum_id',
 276              'callback_method' => 'callback_topicid_to_forumid'
 277          );
 278  
 279          // Reply parent topic id (If no parent, then 0. Stored in postmeta)
 280          $this->field_map[] = array(
 281              'from_tablename'  => 'forum_posts',
 282              'from_fieldname'  => 'parent_id',
 283              'to_type'         => 'reply',
 284              'to_fieldname'    => '_bbp_topic_id',
 285              'callback_method' => 'callback_topicid'
 286          );
 287  
 288          // Reply author.
 289          $this->field_map[] = array(
 290              'from_tablename'  => 'forum_posts',
 291              'from_fieldname'  => 'author_id',
 292              'to_type'         => 'reply',
 293              'to_fieldname'    => 'post_author',
 294              'callback_method' => 'callback_userid'
 295          );
 296  
 297          // Reply content.
 298          $this->field_map[] = array(
 299              'from_tablename'  => 'forum_posts',
 300              'from_fieldname'  => 'text',
 301              'to_type'         => 'reply',
 302              'to_fieldname'    => 'post_content',
 303              'callback_method' => 'callback_html'
 304          );
 305  
 306          // Reply parent topic id (If no parent, then 0)
 307          $this->field_map[] = array(
 308              'from_tablename'  => 'forum_posts',
 309              'from_fieldname'  => 'parent_id',
 310              'to_type'         => 'reply',
 311              'to_fieldname'    => 'post_parent',
 312              'callback_method' => 'callback_topicid'
 313          );
 314  
 315          // Reply dates.
 316          $this->field_map[] = array(
 317              'from_tablename'  => 'forum_posts',
 318              'from_fieldname'  => 'date',
 319              'to_type'         => 'reply',
 320              'to_fieldname'    => 'post_date'
 321          );
 322          $this->field_map[] = array(
 323              'from_tablename'  => 'forum_posts',
 324              'from_fieldname'  => 'date',
 325              'to_type'         => 'reply',
 326              'to_fieldname'    => 'post_date_gmt'
 327          );
 328          $this->field_map[] = array(
 329              'from_tablename'  => 'forum_posts',
 330              'from_fieldname'  => 'date',
 331              'to_type'         => 'reply',
 332              'to_fieldname'    => 'post_modified'
 333          );
 334          $this->field_map[] = array(
 335              'from_tablename'  => 'forum_posts',
 336              'from_fieldname'  => 'date',
 337              'to_type'         => 'reply',
 338              'to_fieldname'    => 'post_modified_gmt'
 339          );
 340  
 341          /** User Section ******************************************************/
 342  
 343          // Store old user id (Stored in usermeta)
 344          $this->field_map[] = array(
 345              'from_tablename' => 'users',
 346              'from_fieldname' => 'ID',
 347              'to_type'        => 'user',
 348              'to_fieldname'   => '_bbp_old_user_id'
 349          );
 350  
 351          // Store old user password (Stored in usermeta)
 352          $this->field_map[] = array(
 353              'from_tablename' => 'users',
 354              'from_fieldname' => 'user_pass',
 355              'to_type'        => 'user',
 356              'to_fieldname'   => '_bbp_password'
 357          );
 358  
 359          // User name.
 360          $this->field_map[] = array(
 361              'from_tablename' => 'users',
 362              'from_fieldname' => 'user_login',
 363              'to_type'        => 'user',
 364              'to_fieldname'   => 'user_login'
 365          );
 366  
 367          // User nice name.
 368          $this->field_map[] = array(
 369              'from_tablename' => 'users',
 370              'from_fieldname' => 'user_nicename',
 371              'to_type'        => 'user',
 372              'to_fieldname'   => 'user_nicename'
 373          );
 374  
 375          // User email.
 376          $this->field_map[] = array(
 377              'from_tablename' => 'users',
 378              'from_fieldname' => 'user_email',
 379              'to_type'        => 'user',
 380              'to_fieldname'   => 'user_email'
 381          );
 382  
 383          // User homepage.
 384          $this->field_map[] = array(
 385              'from_tablename' => 'users',
 386              'from_fieldname' => 'user_url',
 387              'to_type'        => 'user',
 388              'to_fieldname'   => 'user_url'
 389          );
 390  
 391          // User registered.
 392          $this->field_map[] = array(
 393              'from_tablename' => 'users',
 394              'from_fieldname' => 'user_registered',
 395              'to_type'        => 'user',
 396              'to_fieldname'   => 'user_registered'
 397          );
 398  
 399          // User status.
 400          $this->field_map[] = array(
 401              'from_tablename' => 'users',
 402              'from_fieldname' => 'user_status',
 403              'to_type'        => 'user',
 404              'to_fieldname'   => 'user_status'
 405          );
 406  
 407          // User display name.
 408          $this->field_map[] = array(
 409              'from_tablename' => 'users',
 410              'from_fieldname' => 'display_name',
 411              'to_type'        => 'user',
 412              'to_fieldname'   => 'display_name'
 413          );
 414      }
 415  
 416      /**
 417       * This method allows us to indicates what is or is not converted for each
 418       * converter.
 419       */
 420  	public function info() {
 421          return '';
 422      }
 423  
 424      /**
 425       * This method is to save the salt and password together. That
 426       * way when we authenticate it we can get it out of the database
 427       * as one value. Array values are auto sanitized by WordPress.
 428       */
 429  	public function callback_savepass( $field, $row ) {
 430          return false;
 431      }
 432  
 433      /**
 434       * This method is to take the pass out of the database and compare
 435       * to a pass the user has typed in.
 436       */
 437  	public function authenticate_pass( $password, $serialized_pass ) {
 438          return false;
 439      }
 440  
 441      /**
 442       * Translate the topic status from Mingle numerics to WordPress's strings.
 443       *
 444       * @param int $status Mingle v1.x numeric topic status
 445       * @return string WordPress safe
 446       */
 447  	public function callback_topic_status( $status = 0 ) {
 448          switch ( $status ) {
 449              case 1 :
 450                  $status = 'closed';
 451                  break;
 452  
 453              case 0  :
 454              default :
 455                  $status = 'publish';
 456                  break;
 457          }
 458          return $status;
 459      }
 460  
 461      /**
 462       * Translate the topic sticky status type from Mingle numerics to WordPress's strings.
 463       *
 464       * @param int $status Mingle numeric forum type
 465       * @return string WordPress safe
 466       */
 467  	public function callback_sticky_status( $status = 0 ) {
 468          switch ( $status ) {
 469              case 'sticky' :
 470                  $status = 'sticky';       // Mingle Sticky 'status = sticky'
 471                  break;
 472  
 473              case 'open'  :
 474              default :
 475                  $status = 'normal';       // Mingle Normal Topic 'status = open'
 476                  break;
 477          }
 478          return $status;
 479      }
 480  }


Generated: Sun Sep 15 01:01:26 2019 Cross-referenced by PHPXref 0.7.1