Skip to:
Content

bbPress.org

Ticket #2417: vBulletin3.php

File vBulletin3.php, 19.3 KB (added by netweb, 12 years ago)

vBulletin3.php

Line 
1<?php
2
3/**
4 * Implementation of vBulletin v3.x Converter.
5 *
6 * @since bbPress (r4724)
7 * @link Codex Docs http://codex.bbpress.org/import-forums/vbulletin
8 */
9class vBulletin3 extends BBP_Converter_Base {
10
11        /**
12         * Main constructor
13         *
14         * @uses vBulletin::setup_globals()
15         */
16        function __construct() {
17                parent::__construct();
18                $this->setup_globals();
19        }
20
21        /**
22         * Sets up the field mappings
23         */
24        private function setup_globals() {
25
26                /** Forum Section *****************************************************/
27
28                // Forum id (Stored in postmeta)
29                $this->field_map[] = array(
30                        'from_tablename' => 'forum',
31                        'from_fieldname' => 'forumid',
32                        'to_type'        => 'forum',
33                        'to_fieldname'   => '_bbp_forum_id'
34                );
35
36                // Forum parent id (If no parent, then 0. Stored in postmeta)
37                $this->field_map[] = array(
38                        'from_tablename' => 'forum',
39                        'from_fieldname' => 'parentid',
40                        'to_type'        => 'forum',
41                        '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'
58                );
59
60                // Forum total topic count (Includes unpublished topics, Stored in postmeta)
61                $this->field_map[] = array(
62                        'from_tablename'  => 'forum',
63                        'from_fieldname'  => 'threadcount',
64                        'to_type'         => 'forum',
65                        'to_fieldname'    => '_bbp_total_topic_count'
66                );
67
68                // Forum total reply count (Includes unpublished replies, Stored in postmeta)
69                $this->field_map[] = array(
70                        'from_tablename'  => 'forum',
71                        'from_fieldname'  => 'replycount',
72                        'to_type'         => 'forum',
73                        'to_fieldname'    => '_bbp_total_reply_count'
74                );
75
76                // Forum title.
77                $this->field_map[] = array(
78                        'from_tablename' => 'forum',
79                        'from_fieldname' => 'title',
80                        'to_type'        => 'forum',
81                        'to_fieldname'   => 'post_title'
82                );
83
84                // Forum slug (Clean name to avoid confilcts)
85                $this->field_map[] = array(
86                        'from_tablename'  => 'forum',
87                        'from_fieldname'  => 'title_clean',
88                        'to_type'         => 'forum',
89                        'to_fieldname'    => 'post_name',
90                        'callback_method' => 'callback_slug'
91                );
92
93                // Forum description.
94                $this->field_map[] = array(
95                        'from_tablename'  => 'forum',
96                        'from_fieldname'  => 'description',
97                        'to_type'         => 'forum',
98                        'to_fieldname'    => 'post_content',
99                        'callback_method' => 'callback_null'
100                );
101
102                // Forum display order (Starts from 1)
103                $this->field_map[] = array(
104                        'from_tablename' => 'forum',
105                        'from_fieldname' => 'displayorder',
106                        'to_type'        => 'forum',
107                        'to_fieldname'   => 'menu_order'
108                );
109
110                // Forum type (Category = -1 or Forum > 0, Stored in postmeta)
111                $this->field_map[] = array(
112                        'from_tablename'  => 'forum',
113                        'from_fieldname'  => 'parentid',
114                        'to_type'         => 'forum',
115                        'to_fieldname'    => '_bbp_forum_type',
116                        'callback_method' => 'callback_forum_type'
117                );
118
119                // Forum dates.
120                $this->field_map[] = array(
121                        'to_type'      => 'forum',
122                        'to_fieldname' => 'post_date',
123                        'default'      => date( 'Y-m-d H:i:s' )
124                );
125                $this->field_map[]       = array(
126                        'to_type'      => 'forum',
127                        'to_fieldname' => 'post_date_gmt',
128                        'default'      => date( 'Y-m-d H:i:s' )
129                );
130                $this->field_map[]       = array(
131                        'to_type'      => 'forum',
132                        'to_fieldname' => 'post_modified',
133                        'default'      => date( 'Y-m-d H:i:s' )
134                );
135                $this->field_map[]       = array(
136                        'to_type'      => 'forum',
137                        'to_fieldname' => 'post_modified_gmt',
138                        'default'      => date( 'Y-m-d H:i:s' )
139                );
140
141                /** Topic Section *****************************************************/
142
143                // Topic id (Stored in postmeta)
144                $this->field_map[] = array(
145                        'from_tablename' => 'thread',
146                        'from_fieldname' => 'threadid',
147                        'to_type'        => 'topic',
148                        'to_fieldname'   => '_bbp_topic_id'
149                );
150
151                // Topic parent forum id (If no parent, then 0. Stored in postmeta)
152                $this->field_map[] = array(
153                        'from_tablename'  => 'thread',
154                        'from_fieldname'  => 'forumid',
155                        'to_type'         => 'topic',
156                        'to_fieldname'    => '_bbp_forum_id',
157                        'callback_method' => 'callback_forumid'
158                );
159
160                // Topic reply count (Stored in postmeta)
161                $this->field_map[] = array(
162                        'from_tablename'  => 'thread',
163                        'from_fieldname'  => 'replycount',
164                        'to_type'         => 'topic',
165                        'to_fieldname'    => '_bbp_reply_count',
166                        'callback_method' => 'callback_topic_reply_count'
167                );
168
169                // Topic total reply count (Includes unpublished replies, Stored in postmeta)
170                $this->field_map[] = array(
171                        'from_tablename'  => 'thread',
172                        'from_fieldname'  => 'replycount',
173                        'to_type'         => 'topic',
174                        'to_fieldname'    => '_bbp_total_reply_count',
175                        'callback_method' => 'callback_topic_reply_count'
176                );
177
178                // Topic author.
179                $this->field_map[] = array(
180                        'from_tablename'  => 'thread',
181                        'from_fieldname'  => 'postuserid',
182                        'to_type'         => 'topic',
183                        'to_fieldname'    => 'post_author',
184                        'callback_method' => 'callback_userid'
185                );
186
187                // Topic Author ip (Stored in postmeta)
188                // Note: We join the 'post' table because 'thread' table does not include topic content.
189                $this->field_map[] = array(
190                        'from_tablename'  => 'post',
191                        'from_fieldname'  => 'ipaddress',
192                        'join_tablename'  => 'thread',
193                        'join_type'       => 'INNER',
194                        'join_expression' => 'USING (threadid) WHERE post.parentid = 0',
195                        'to_type'         => 'topic',
196                        'to_fieldname'    => '_bbp_author_ip'
197                );
198
199                // Topic title.
200                $this->field_map[] = array(
201                        'from_tablename' => 'thread',
202                        'from_fieldname' => 'title',
203                        'to_type'        => 'topic',
204                        'to_fieldname'   => 'post_title'
205                );
206
207                // Topic slug (Clean name to avoid conflicts)
208                $this->field_map[] = array(
209                        'from_tablename'  => 'thread',
210                        'from_fieldname'  => 'title',
211                        'to_type'         => 'topic',
212                        'to_fieldname'    => 'post_name',
213                        'callback_method' => 'callback_slug'
214                );
215
216                // Topic parent forum id (If no parent, then 0)
217                $this->field_map[] = array(
218                        'from_tablename'  => 'thread',
219                        'from_fieldname'  => 'forumid',
220                        'to_type'         => 'topic',
221                        'to_fieldname'    => 'post_parent',
222                        'callback_method' => 'callback_forumid'
223                );
224
225                // Topic content.
226                // Note: We join the 'post' table because 'thread' table does not include topic content.
227                $this->field_map[] = array(
228                        'from_tablename'  => 'post',
229                        'from_fieldname'  => 'pagetext',
230                        'join_tablename'  => 'thread',
231                        'join_type'       => 'INNER',
232                        'join_expression' => 'USING (threadid) WHERE post.parentid = 0',
233                        'to_type'         => 'topic',
234                        'to_fieldname'    => 'post_content',
235                        'callback_method' => 'callback_html'
236                );
237
238                // Topic dates.
239                $this->field_map[] = array(
240                        'from_tablename'  => 'thread',
241                        'from_fieldname'  => 'dateline',
242                        'to_type'         => 'topic',
243                        'to_fieldname'    => 'post_date',
244                        'callback_method' => 'callback_datetime'
245                );
246                $this->field_map[] = array(
247                        'from_tablename'  => 'thread',
248                        'from_fieldname'  => 'dateline',
249                        'to_type'         => 'topic',
250                        'to_fieldname'    => 'post_date_gmt',
251                        'callback_method' => 'callback_datetime'
252                );
253                $this->field_map[] = array(
254                        'from_tablename'  => 'thread',
255                        'from_fieldname'  => 'dateline',
256                        'to_type'         => 'topic',
257                        'to_fieldname'    => 'post_modified',
258                        'callback_method' => 'callback_datetime'
259                );
260                $this->field_map[] = array(
261                        'from_tablename'  => 'thread',
262                        'from_fieldname'  => 'dateline',
263                        'to_type'         => 'topic',
264                        'to_fieldname'    => 'post_modified_gmt',
265                        'callback_method' => 'callback_datetime'
266                );
267                $this->field_map[] = array(
268                        'from_tablename' => 'thread',
269                        'from_fieldname' => 'lastpost',
270                        'to_type'        => 'topic',
271                        'to_fieldname'   => '_bbp_last_active_time',
272                        'callback_method' => 'callback_datetime'
273                );
274
275                // Topic status (Open or Closed)
276                $this->field_map[] = array(
277                        'from_tablename'  => 'thread',
278                        'from_fieldname'  => 'open',
279                        'to_type'         => 'topic',
280                        'to_fieldname'    => 'post_status',
281                        'callback_method' => 'callback_topic_status'
282                );
283
284                /** Tags Section ******************************************************/
285
286                // Topic id.
287                $this->field_map[] = array(
288                        'from_tablename'  => 'tagthread',
289                        'from_fieldname'  => 'threadid',
290                        'to_type'         => 'tags',
291                        'to_fieldname'    => 'objectid',
292                        'callback_method' => 'callback_topicid'
293                );
294
295                // Taxonomy ID.
296                $this->field_map[] = array(
297                        'from_tablename'  => 'tagthread',
298                        'from_fieldname'  => 'tagid',
299                        'to_type'         => 'tags',
300                        'to_fieldname'    => 'taxonomy'
301                );
302
303                // Term text.
304                $this->field_map[] = array(
305                        'from_tablename'  => 'tag',
306                        'from_fieldname'  => 'tagtext',
307                        'join_tablename'  => 'tagthread',
308                        'join_type'       => 'INNER',
309                        'join_expression' => 'USING (tagid)',
310                        'to_type'         => 'tags',
311                        'to_fieldname'    => 'name'
312                );
313
314                /** Reply Section *****************************************************/
315
316                // Reply id (Stored in postmeta)
317                $this->field_map[] = array(
318                        'from_tablename'  => 'post',
319                        'from_fieldname'  => 'postid',
320                        'to_type'         => 'reply',
321                        'to_fieldname'    => '_bbp_post_id'
322                );
323
324                // Reply parent forum id (If no parent, then 0. Stored in postmeta)
325                // Note: We join the 'thread' table because 'post' table does not include forum id.
326                $this->field_map[] = array(
327                        'from_tablename'  => 'thread',
328                        'from_fieldname'  => 'forumid',
329                        'join_tablename'  => 'post',
330                        'join_type'       => 'INNER',
331                        'join_expression' => 'USING (threadid) WHERE post.parentid != 0',
332                        'to_type'         => 'reply',
333                        'to_fieldname'    => '_bbp_forum_id',
334                        'callback_method' => 'callback_topicid_to_forumid'
335                );
336
337                // Reply parent topic id (If no parent, then 0. Stored in postmeta)
338                $this->field_map[] = array(
339                        'from_tablename'  => 'post',
340                        'from_fieldname'  => 'threadid',
341                        'to_type'         => 'reply',
342                        'to_fieldname'    => '_bbp_topic_id',
343                        'callback_method' => 'callback_topicid'
344                );
345
346                // Reply author ip (Stored in postmeta)
347                $this->field_map[] = array(
348                        'from_tablename' => 'post',
349                        'from_fieldname' => 'ipaddress',
350                        'to_type'        => 'reply',
351                        'to_fieldname'   => '_bbp_author_ip'
352                );
353
354                // Reply author.
355                $this->field_map[] = array(
356                        'from_tablename'  => 'post',
357                        'from_fieldname'  => 'userid',
358                        'to_type'         => 'reply',
359                        'to_fieldname'    => 'post_author',
360                        'callback_method' => 'callback_userid'
361                );
362
363                // Reply title.
364                // Note: We join the 'thread' table because 'post' table does not include reply title.
365                $this->field_map[] = array(
366                        'from_tablename'  => 'thread',
367                        'from_fieldname'  => 'title',
368                        'join_tablename'  => 'post',
369                        'join_type'       => 'INNER',
370                        'join_expression' => 'USING (threadid) WHERE post.parentid != 0',
371                        'to_type'         => 'reply',
372                        'to_fieldname'    => 'post_title',
373                        'callback_method' => 'callback_reply_title'
374                );
375
376        // Reply slug (Clean name to avoid conflicts)
377        // Note: We join the 'thread' table because 'post' table does not include reply slug.
378        $this->field_map[] = array(
379                        'from_tablename'  => 'thread',
380                        'from_fieldname'  => 'title',
381                        'join_tablename'  => 'post',
382                        'join_type'       => 'INNER',
383                        'join_expression' => 'USING (threadid) WHERE post.parentid != 0',
384                        'to_type'         => 'reply',
385                        'to_fieldname'    => 'post_name',
386                        'callback_method' => 'callback_slug'
387                );
388
389                // Reply content.
390                $this->field_map[] = array(
391                        'from_tablename'  => 'post',
392                        'from_fieldname'  => 'pagetext',
393                        'to_type'         => 'reply',
394                        'to_fieldname'    => 'post_content',
395                        'callback_method' => 'callback_html'
396                );
397
398                // Reply parent topic id (If no parent, then 0)
399                $this->field_map[] = array(
400                        'from_tablename'  => 'post',
401                        'from_fieldname'  => 'threadid',
402                        'to_type'         => 'reply',
403                        'to_fieldname'    => 'post_parent',
404                        'callback_method' => 'callback_topicid'
405                );
406
407                // Reply dates.
408                $this->field_map[] = array(
409                        'from_tablename'  => 'post',
410                        'from_fieldname'  => 'dateline',
411                        'to_type'         => 'reply',
412                        'to_fieldname'    => 'post_date',
413                        'callback_method' => 'callback_datetime'
414                );
415                $this->field_map[] = array(
416                        'from_tablename'  => 'post',
417                        'from_fieldname'  => 'dateline',
418                        'to_type'         => 'reply',
419                        'to_fieldname'    => 'post_date_gmt',
420                        'callback_method' => 'callback_datetime'
421                );
422                $this->field_map[] = array(
423                        'from_tablename'  => 'post',
424                        'from_fieldname'  => 'dateline',
425                        'to_type'         => 'reply',
426                        'to_fieldname'    => 'post_modified',
427                        'callback_method' => 'callback_datetime'
428                );
429                $this->field_map[]       = array(
430                        'from_tablename'  => 'post',
431                        'from_fieldname'  => 'dateline',
432                        'to_type'         => 'reply',
433                        'to_fieldname'    => 'post_modified_gmt',
434                        'callback_method' => 'callback_datetime'
435                );
436
437                /** User Section ******************************************************/
438
439                // Store old User id (Stored in usermeta)
440                $this->field_map[] = array(
441                        'from_tablename' => 'user',
442                        'from_fieldname' => 'userid',
443                        'to_type'        => 'user',
444                        'to_fieldname'   => '_bbp_user_id'
445                );
446
447                // Store old User password (Stored in usermeta serialized with salt)
448                $this->field_map[] = array(
449                        'from_tablename'  => 'user',
450                        'from_fieldname'  => 'password',
451                        'to_type'         => 'user',
452                        'to_fieldname'    => '_bbp_password',
453                        'callback_method' => 'callback_savepass'
454                );
455
456                // Store old User Salt (This is only used for the SELECT row info for the above password save)
457                $this->field_map[] = array(
458                        'from_tablename' => 'user',
459                        'from_fieldname' => 'salt',
460                        'to_type'        => 'user',
461                        'to_fieldname'   => ''
462                );
463
464                // User password verify class (Stored in usermeta for verifying password)
465                $this->field_map[] = array(
466                        'to_type'      => 'user',
467                        'to_fieldname' => '_bbp_class',
468                        'default'      => 'vBulletin3'
469                );
470
471                // User name.
472                $this->field_map[] = array(
473                        'from_tablename' => 'user',
474                        'from_fieldname' => 'username',
475                        'to_type'        => 'user',
476                        'to_fieldname'   => 'user_login'
477                );
478
479                // User email.
480                $this->field_map[] = array(
481                        'from_tablename' => 'user',
482                        'from_fieldname' => 'email',
483                        'to_type'        => 'user',
484                        'to_fieldname'   => 'user_email'
485                );
486
487                // User homepage.
488                $this->field_map[] = array(
489                        'from_tablename' => 'user',
490                        'from_fieldname' => 'homepage',
491                        'to_type'        => 'user',
492                        'to_fieldname'   => 'user_url'
493                );
494
495                // User registered.
496                $this->field_map[] = array(
497                        'from_tablename'  => 'user',
498                        'from_fieldname'  => 'joindate',
499                        'to_type'         => 'user',
500                        'to_fieldname'    => 'user_registered',
501                        'callback_method' => 'callback_datetime'
502                );
503
504                // User AIM (Stored in usermeta)
505                $this->field_map[] = array(
506                        'from_tablename' => 'user',
507                        'from_fieldname' => 'aim',
508                        'to_type'        => 'user',
509                        'to_fieldname'   => 'aim'
510                );
511
512                // User Yahoo (Stored in usermeta)
513                $this->field_map[] = array(
514                        'from_tablename' => 'user',
515                        'from_fieldname' => 'yahoo',
516                        'to_type'        => 'user',
517                        'to_fieldname'   => 'yim'
518                );
519
520                // User ICQ (Stored in usermeta)
521                $this->field_map[] = array(
522                        'from_tablename' => 'user',
523                        'from_fieldname' => 'icq',
524                        'to_type'        => 'user',
525                        'to_fieldname'   => '_bbp_vbulletin3_user_icq'
526                );
527
528                // User MSN (Stored in usermeta)
529                $this->field_map[] = array(
530                        'from_tablename' => 'user',
531                        'from_fieldname' => 'msn',
532                        'to_type'        => 'user',
533                        'to_fieldname'   => '_bbp_vbulletin3_user_msn'
534                );
535
536                // User Skype (Stored in usermeta)
537                $this->field_map[] = array(
538                        'from_tablename' => 'user',
539                        'from_fieldname' => 'skype',
540                        'to_type'        => 'user',
541                        'to_fieldname'   => '_bbp_vbulletin3_user_skype'
542                );
543        }
544
545        /**
546         * This method allows us to indicates what is or is not converted for each
547         * converter.
548         */
549        public function info() {
550                return '';
551        }
552
553
554        /**
555         * This method is to save the salt and password together.  That
556         * way when we authenticate it we can get it out of the database
557         * as one value. Array values are auto sanitized by WordPress.
558         */
559        public function callback_savepass( $field, $row ) {
560                $pass_array = array( 'hash'      => $field, 'salt'       => $row['salt'] );
561                return $pass_array;
562        }
563
564        /**
565         * This method is to take the pass out of the database and compare
566         * to a pass the user has typed in.
567         *
568         * vBulletin passwords do not work. Maybe use the below plugin's approach?
569         *
570         * @link http://wordpress.org/extend/plugins/vb-user-copy/
571         * @link http://plugins.trac.wordpress.org/browser/vb-user-copy/trunk/vb_user_copy.php
572         */
573        public function authenticate_pass( $password, $serialized_pass ) {
574                $pass_array = unserialize( $serialized_pass );
575                return ( $pass_array['hash'] == md5( md5( $password ) . $pass_array['salt'] ) );
576        }
577
578        /**
579         * Translate the forum type from vBulletin v3.x numeric's to WordPress's strings.
580         *
581         * @param int $status vBulletin v3.x numeric forum type
582         * @return string WordPress safe
583         */
584        public function callback_forum_type( $status = 0 ) {
585                if ( $status == -1 ) {
586                        $status = 'category';
587                } else {
588                        $status = 'forum';
589                }
590                return $status;
591        }
592
593        /**
594         * Verify the topic reply count.
595         *
596         * @param int $count vBulletin v3.x reply count
597         * @return string WordPress safe
598         */
599        public function callback_topic_reply_count( $count = 1 ) {
600                $count = absint( (int) $count - 1 );
601                return $count;
602        }
603
604        /**
605         * Set the reply title
606         *
607         * @param string $title vBulletin v3.x topic title of this reply
608         * @return string Prefixed topic title, or empty string
609         */
610        public function callback_reply_title( $title = '' ) {
611                $title = !empty( $title ) ? __( 'Re: ', 'bbpress' ) . html_entity_decode( $title ) : '';
612                return $title;
613        }
614
615        /**
616         * Translate the post status from vBulletin v3.x numeric's to WordPress's strings.
617         *
618         * @param int $status vBulletin v3.x numeric topic status
619         * @return string WordPress safe
620         */
621        public function callback_topic_status( $status = 1 ) {
622                switch ( $status ) {
623                        case 0 :
624                                $status = 'closed';
625                                break;
626
627                        case 1  :
628                        default :
629                                $status = 'publish';
630                                break;
631                }
632                return $status;
633        }
634
635        /**
636         * This callback processes any custom parser.php attributes and custom code with preg_replace
637         */
638        protected function callback_html( $field ) {
639
640                // Strips vBulletin custom HTML first from $field before parsing $field to parser.php
641                $vbulletin_markup = $field;
642                $vbulletin_markup = html_entity_decode( $vbulletin_markup );
643
644                // Replace '[QUOTE]' with '<blockquote>'
645                $vbulletin_markup = preg_replace( '/\[QUOTE\]/', '<blockquote>', $vbulletin_markup );
646                // Replace '[QUOTE=User Name($1);PostID($2)]' with '<em>@$1 $2 wrote:</em><blockquote>"
647                $vbulletin_markup = preg_replace( '/\[QUOTE=(.*?);(.*?)\]/' , '<em>@$1 $2 wrote:</em><blockquote>', $vbulletin_markup );
648                // Replace '[/QUOTE]' with '</blockquote>'
649                $vbulletin_markup = preg_replace( '/\[\/QUOTE\]/', '</blockquote>', $vbulletin_markup );
650                // Replace '[MENTION=###($1)]User Name($2)[/MENTION]' with '@$2"
651                $vbulletin_markup = preg_replace( '/\[MENTION=(.*?)\](.*?)\[\/MENTION\]/', '@$2', $vbulletin_markup );
652
653                // Replace '[video=youtube;$1]$2[/video]' with '$2"
654                $vbulletin_markup = preg_replace( '/\[video\=youtube;(.*?)\](.*?)\[\/video\]/', '$2', $vbulletin_markup );
655
656                // Now that vBulletin custom HTML has been stripped put the cleaned HTML back in $field
657                $field = $vbulletin_markup;
658
659                // Parse out any bbCodes in $field with the BBCode 'parser.php'
660                require_once( bbpress()->admin->admin_dir . 'parser.php' );
661                $bbcode = BBCode::getInstance();
662                $bbcode->enable_smileys = false;
663                $bbcode->smiley_regex   = false;
664                return html_entity_decode( $bbcode->Parse( $field ) );
665        }
666}