Skip to:
Content

bbPress.org

Changeset 4730


Ignore:
Timestamp:
01/28/2013 02:41:19 AM (14 years ago)
Author:
johnjamesjacoby
Message:

Improvements to vBulletin importer. Props netweb. Fixes #1991.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/admin/converters/vBulletin.php

    r4272 r4730  
    22
    33/**
    4  * vBulletin Converter
     4 * Implementation of vBulletin v4.x Converter.
    55 *
    6  * @since bbPress (r)
     6 * @since bbPress (r4724)
     7 * @link Codex Docs http://codex.bbpress.org/import-forums/vbulletin
    78 */
    89class vBulletin extends BBP_Converter_Base {
     
    3334                );
    3435
    35                 // Forum parent id (If no parent, than 0. Stored in postmeta)
     36                // Forum parent id (If no parent, then 0. Stored in postmeta)
    3637                $this->field_map[] = array(
    3738                        'from_tablename' => 'forum',
     
    3940                        'to_type'        => 'forum',
    4041                        'to_fieldname'   => '_bbp_forum_parent_id'
     42                );
     43
     44                // Forum topic count (Stored in postmeta)
     45                $this->field_map[] = array(
     46                        'from_tablename' => 'forum',
     47                        'from_fieldname' => 'threadcount',
     48                        'to_type'        => 'forum',
     49                        'to_fieldname'   => '_bbp_topic_count'
     50                );
     51
     52                // Forum reply count (Stored in postmeta)
     53                $this->field_map[] = array(
     54                        'from_tablename' => 'forum',
     55                        'from_fieldname' => 'replycount',
     56                        'to_type'        => 'forum',
     57                        'to_fieldname'   => '_bbp_reply_count'
    4158                );
    4259
     
    7592                );
    7693
    77                 // Forum date update.
     94                // Forum dates.
    7895                $this->field_map[] = array(
    7996                        'to_type'      => 'forum',
     
    107124                );
    108125
    109                 // Forum id (Stored in postmeta)
     126                // Topic parent forum id (If no parent, then 0. Stored in postmeta)
    110127                $this->field_map[] = array(
    111128                        'from_tablename'  => 'thread',
     
    114131                        'to_fieldname'    => '_bbp_forum_id',
    115132                        'callback_method' => 'callback_forumid'
     133                );
     134
     135                // Topic reply count (Stored in postmeta)
     136                $this->field_map[] = array(
     137                        'from_tablename'  => 'thread',
     138                        'from_fieldname'  => 'replycount',
     139                        'to_type'         => 'topic',
     140                        'to_fieldname'    => '_bbp_reply_count',
     141                        'callback_method' => 'callback_topic_reply_count'
    116142                );
    117143
     
    142168                );
    143169
    144                 // Forum id (If no parent, than 0)
     170                // Topic parent forum id (If no parent, then 0)
    145171                $this->field_map[] = array(
    146172                        'from_tablename'  => 'thread',
     
    164190                );
    165191
    166                 // Topic date update.
     192                // Topic dates.
    167193                $this->field_map[] = array(
    168194                        'from_tablename'  => 'thread',
     
    192218                        'to_fieldname'    => 'post_modified_gmt',
    193219                        'callback_method' => 'callback_datetime'
     220                );
     221                $this->field_map[] = array(
     222                        'from_tablename' => 'thread',
     223                        'from_fieldname' => 'lastpost',
     224                        'to_type'        => 'topic',
     225                        'to_fieldname'   => '_bbp_last_active_time',
     226                        'callback_method' => 'callback_datetime'
     227                );
     228
     229                // Topic status (Open or Closed)
     230                $this->field_map[] = array(
     231                        'from_tablename'  => 'thread',
     232                        'from_fieldname'  => 'open',
     233                        'to_type'         => 'topic',
     234                        'to_fieldname'    => 'post_status',
     235                        'callback_method' => 'callback_topic_status'
    194236                );
    195237
     
    205247                );
    206248
    207                 // Tags text.
     249                // Taxonomy ID.
     250                $this->field_map[] = array(
     251                        'from_tablename'  => 'tagcontent',
     252                        'from_fieldname'  => 'tagid',
     253                        'to_type'         => 'tags',
     254                        'to_fieldname'    => 'taxonomy'
     255                );
     256
     257                // Term text.
    208258                $this->field_map[] = array(
    209259                        'from_tablename'  => 'tag',
     
    216266                );
    217267
    218                 /** Post Section ******************************************************/
    219 
    220                 // Post id (Stores in postmeta)
     268                /** Reply Section *****************************************************/
     269
     270                // Reply id (Stored in postmeta)
    221271                $this->field_map[] = array(
    222272                        'from_tablename'  => 'post',
    223273                        'from_fieldname'  => 'postid',
    224                         'from_expression' => 'WHERE post.parentid != 0',
    225274                        'to_type'         => 'reply',
    226275                        'to_fieldname'    => '_bbp_post_id'
    227276                );
    228277
    229                 // Forum id (Stores in postmeta)
    230                 $this->field_map[] = array(
    231                         'from_tablename'  => 'post',
    232                         'from_fieldname'  => 'threadid',
     278                // Reply parent forum id (If no parent, then 0. Stored in postmeta)
     279                $this->field_map[] = array(
     280                        'from_tablename'  => 'thread',
     281                        'from_fieldname'  => 'forumid',
     282                        'join_tablename'  => 'post',
     283                        'join_type'       => 'INNER',
     284                        'join_expression' => 'USING (threadid) WHERE post.parentid != 0',
    233285                        'to_type'         => 'reply',
    234286                        'to_fieldname'    => '_bbp_forum_id',
     
    236288                );
    237289
    238                 // Topic id (Stores in postmeta)
     290                // Reply parent topic id (If no parent, then 0. Stored in postmeta)
    239291                $this->field_map[] = array(
    240292                        'from_tablename'  => 'post',
     
    245297                );
    246298
    247                 // Author ip.
     299                // Reply author ip (Stored in postmeta)
    248300                $this->field_map[] = array(
    249301                        'from_tablename' => 'post',
     
    253305                );
    254306
    255                 // Post author.
     307                // Reply author.
    256308                $this->field_map[] = array(
    257309                        'from_tablename'  => 'post',
     
    262314                );
    263315
    264                 // Topic title.
    265                 $this->field_map[] = array(
    266                         'from_tablename' => 'post',
    267                         'from_fieldname' => 'title',
    268                         'to_type'        => 'reply',
    269                         'to_fieldname'   => 'post_title'
    270                 );
    271 
    272                 // Topic slug (Clean name)
    273                 $this->field_map[] = array(
    274                         'from_tablename'  => 'post',
     316                // Reply title.
     317                // Note: We join the thread table because post table does not include topic title.
     318                $this->field_map[] = array(
     319                        'from_tablename'  => 'thread',
    275320                        'from_fieldname'  => 'title',
    276                         'to_type'         => 'reply',
    277                         'to_fieldname'    => 'post_name',
    278                         'callback_method' => 'callback_slug'
    279                 );
    280 
    281                 // Post content.
     321                        'join_tablename'  => 'post',
     322                        'join_type'       => 'INNER',
     323                        'join_expression' => 'USING (threadid) WHERE post.parentid != 0',
     324                        'to_type'         => 'reply',
     325                        'to_fieldname'    => 'post_title',
     326                        'callback_method' => 'callback_reply_title'
     327                );
     328
     329                // Reply content.
    282330                $this->field_map[] = array(
    283331                        'from_tablename'  => 'post',
     
    288336                );
    289337
    290                 // Topic id (If no parent, than 0)
     338                // Reply parent topic id (If no parent, then 0)
    291339                $this->field_map[] = array(
    292340                        'from_tablename'  => 'post',
     
    297345                );
    298346
    299                 // Topic date update.
     347                // Reply dates.
    300348                $this->field_map[] = array(
    301349                        'from_tablename'  => 'post',
     
    329377                /** User Section ******************************************************/
    330378
    331                 // Store old User id (Stores in usermeta)
     379                // Store old User id (Stored in usermeta)
    332380                $this->field_map[] = array(
    333381                        'from_tablename' => 'user',
     
    337385                );
    338386
    339                 // Store old User password (Stores in usermeta serialized with salt)
     387                // Store old User password (Stored in usermeta serialized with salt)
    340388                $this->field_map[] = array(
    341389                        'from_tablename'  => 'user',
     
    346394                );
    347395
    348                 // Store old User Salt (This is only used for the SELECT row info for
    349                 // the above password save)
     396                // Store old User Salt (This is only used for the SELECT row info for the above password save)
    350397                $this->field_map[] = array(
    351398                        'from_tablename' => 'user',
     
    355402                );
    356403
    357                 // User password verify class (Stores in usermeta for verifying password)
     404                // User password verify class (Stored in usermeta for verifying password)
    358405                $this->field_map[] = array(
    359406                        'to_type'      => 'user',
     
    368415                        'to_type'        => 'user',
    369416                        'to_fieldname'   => 'user_login'
    370                 );
    371 
    372                 // User nice name.
    373                 $this->field_map[] = array(
    374                         'from_tablename' => 'user',
    375                         'from_fieldname' => 'user_nicename',
    376                         'to_type'        => 'user',
    377                         'to_fieldname'   => 'user_nicename'
    378417                );
    379418
     
    403442                );
    404443
    405                 // User aim.
     444                // User AIM (Stored in usermeta)
    406445                $this->field_map[] = array(
    407446                        'from_tablename' => 'user',
     
    411450                );
    412451
    413                 // User yahoo.
     452                // User Yahoo (Stored in usermeta)
    414453                $this->field_map[] = array(
    415454                        'from_tablename' => 'user',
     
    417456                        'to_type'        => 'user',
    418457                        'to_fieldname'   => 'yim'
     458                );
     459
     460                // User ICQ (Stored in usermeta)
     461                $this->field_map[] = array(
     462                        'from_tablename' => 'user',
     463                        'from_fieldname' => 'icq',
     464                        'to_type'        => 'user',
     465                        'to_fieldname'   => '_bbp_vbulletin_user_icq'
     466                );
     467
     468                // User MSN (Stored in usermeta)
     469                $this->field_map[] = array(
     470                        'from_tablename' => 'user',
     471                        'from_fieldname' => 'msn',
     472                        'to_type'        => 'user',
     473                        'to_fieldname'   => '_bbp_vbulletin_user_msn'
     474                );
     475
     476                // User Skype (Stored in usermeta)
     477                $this->field_map[] = array(
     478                        'from_tablename' => 'user',
     479                        'from_fieldname' => 'skype',
     480                        'to_type'        => 'user',
     481                        'to_fieldname'   => '_bbp_vbulletin_user_skype'
    419482                );
    420483        }
     
    427490                return '';
    428491        }
     492
    429493
    430494        /**
     
    441505         * This method is to take the pass out of the database and compare
    442506         * to a pass the user has typed in.
     507         *
     508         * vBulletin passwords do not work. Maybe use the below plugin's approach?
     509         *
     510         * @link http://wordpress.org/extend/plugins/vb-user-copy/
     511         * @link http://plugins.trac.wordpress.org/browser/vb-user-copy/trunk/vb_user_copy.php
    443512         */
    444513        public function authenticate_pass( $password, $serialized_pass ) {
     
    446515                return ( $pass_array['hash'] == md5( md5( $password ) . $pass_array['salt'] ) );
    447516        }
     517
     518        /**
     519         * Verify the topic reply count.
     520         *
     521         * @param int $count vBulletin v4.x reply count
     522         * @return string WordPress safe
     523         */
     524        public function callback_topic_reply_count( $count = 1 ) {
     525                $count = absint( (int) $count - 1 );
     526                return $count;
     527        }
     528
     529        /**
     530         * Set the reply title
     531         *
     532         * @param string $title vBulletin v4.x topic title of this reply
     533         * @return string Prefixed topic title, or empty string
     534         */
     535        public function callback_reply_title( $title = '' ) {
     536                $title = !empty( $title ) ? __( 'Re: ', 'bbpress' ) . html_entity_decode( $title ) : '';
     537                return $title;
     538        }
     539
     540        /**
     541         * Translate the post status from vBulletin numeric's to WordPress's strings.
     542         *
     543         * @param int $status vBulletin v4.x numeric topic status
     544         * @return string WordPress safe
     545         */
     546        public function callback_topic_status( $status = 1 ) {
     547                switch ( $status ) {
     548                        case 0 :
     549                                $status = 'closed';
     550                                break;
     551
     552                        case 1  :
     553                        default :
     554                                $status = 'publish';
     555                                break;
     556                }
     557                return $status;
     558        }
     559
     560        /**
     561         * This callback processes any custom parser.php attributes and custom code with preg_replace
     562         */
     563        protected function callback_html( $field ) {
     564
     565                // Strips vBulletin custom HTML first from $field before parsing $field to parser.php
     566                $vbulletin_markup = $field;
     567                $vbulletin_markup = html_entity_decode( $vbulletin_markup );
     568
     569                // Replace '[QUOTE]' with '<blockquote>'
     570                $vbulletin_markup = preg_replace( '/\[QUOTE\]/', '<blockquote>', $vbulletin_markup );
     571                // Replace '[QUOTE=User Name($1);PostID($2)]' with '<em>@$1 $2 wrote:</em><blockquote>"
     572                $vbulletin_markup = preg_replace( '/\[QUOTE=(.*?);(.*?)\]/' , '<em>@$1 $2 wrote:</em><blockquote>', $vbulletin_markup );
     573                // Replace '[/QUOTE]' with '</blockquote>'
     574                $vbulletin_markup = preg_replace( '/\[\/QUOTE\]/', '</blockquote>', $vbulletin_markup );
     575                // Replace '[MENTION=###($1)]User Name($2)[/MENTION]' with '@$2"
     576                $vbulletin_markup = preg_replace( '/\[MENTION=(.*?)\](.*?)\[\/MENTION\]/', '@$2', $vbulletin_markup );
     577
     578                // Replace '[video=youtube;$1]$2[/video]' with '$2"
     579                $vbulletin_markup = preg_replace( '/\[video\=youtube;(.*?)\](.*?)\[\/video\]/', '$2', $vbulletin_markup );
     580
     581                // Now that vBulletin custom HTML has been stripped put the cleaned HTML back in $field
     582                $field = $vbulletin_markup;
     583
     584                // Parse out any bbCodes in $field with the BBCode 'parser.php'
     585                require_once( bbpress()->admin->admin_dir . 'parser.php' );
     586                $bbcode = BBCode::getInstance();
     587                $bbcode->enable_smileys = false;
     588                $bbcode->smiley_regex   = false;
     589                return html_entity_decode( $bbcode->Parse( $field ) );
     590        }
    448591}
Note: See TracChangeset for help on using the changeset viewer.