PluginProbe
bbPress / trunk
bbPress vtrunk
trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.2.2 All 71 releases
bbpress / includes / admin / converters / MyBB.php

MyBB.php in bbPress trunk, at includes/admin/converters/MyBB.php

604 lines 16.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress MyBB Converter
5 *
6 * @package bbPress
7 * @subpackage Converters
8 */
9
10 /**
11 * Implementation of MyBB Forum converter.
12 *
13 * @since 2.5.0 bbPress (r5140)
14 *
15 * @link Codex Docs https://codex.bbpress.org/import-forums/mybb
16 */
17 class MyBB extends BBP_Converter_Base {
18
19 /**
20 * Sets up the field mappings
21 */
22 public function setup_globals() {
23
24 /** Forum Section *****************************************************/
25
26 // Old forum id (Stored in postmeta)
27 $this->field_map[] = array(
28 'from_tablename' => 'forums',
29 'from_fieldname' => 'fid',
30 'to_type' => 'forum',
31 'to_fieldname' => '_bbp_old_forum_id'
32 );
33
34 // Forum parent id (If no parent, then 0, Stored in postmeta)
35 $this->field_map[] = array(
36 'from_tablename' => 'forums',
37 'from_fieldname' => 'pid',
38 'to_type' => 'forum',
39 'to_fieldname' => '_bbp_old_forum_parent_id'
40 );
41
42 // Forum topic count (Stored in postmeta)
43 $this->field_map[] = array(
44 'from_tablename' => 'forums',
45 'from_fieldname' => 'threads',
46 'to_type' => 'forum',
47 'to_fieldname' => '_bbp_topic_count'
48 );
49
50 // Forum reply count (Stored in postmeta)
51 $this->field_map[] = array(
52 'from_tablename' => 'forums',
53 'from_fieldname' => 'posts',
54 'to_type' => 'forum',
55 'to_fieldname' => '_bbp_reply_count'
56 );
57
58 // Forum title.
59 $this->field_map[] = array(
60 'from_tablename' => 'forums',
61 'from_fieldname' => 'name',
62 'to_type' => 'forum',
63 'to_fieldname' => 'post_title'
64 );
65
66 // Forum slug (Clean name to avoid conflicts)
67 $this->field_map[] = array(
68 'from_tablename' => 'forums',
69 'from_fieldname' => 'name',
70 'to_type' => 'forum',
71 'to_fieldname' => 'post_name',
72 'callback_method' => 'callback_slug'
73 );
74
75 // Forum description.
76 $this->field_map[] = array(
77 'from_tablename' => 'forums',
78 'from_fieldname' => 'description',
79 'to_type' => 'forum',
80 'to_fieldname' => 'post_content',
81 'callback_method' => 'callback_null'
82 );
83
84 // Forum display order (Starts from 1)
85 $this->field_map[] = array(
86 'from_tablename' => 'forums',
87 'from_fieldname' => 'disporder',
88 'to_type' => 'forum',
89 'to_fieldname' => 'menu_order'
90 );
91
92 // Forum type (Set a default value 'forum', Stored in postmeta)
93 $this->field_map[] = array(
94 'to_type' => 'forum',
95 'to_fieldname' => '_bbp_forum_type',
96 'default' => 'forum'
97 );
98
99 // Forum status (Set a default value 'open', Stored in postmeta)
100 $this->field_map[] = array(
101 'to_type' => 'forum',
102 'to_fieldname' => '_bbp_status',
103 'default' => 'open'
104 );
105
106 // Forum dates.
107 $this->field_map[] = array(
108 'to_type' => 'forum',
109 'to_fieldname' => 'post_date',
110 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore
111 );
112 $this->field_map[] = array(
113 'to_type' => 'forum',
114 'to_fieldname' => 'post_date_gmt',
115 'default' => gmdate( 'Y-m-d H:i:s' )
116 );
117 $this->field_map[] = array(
118 'to_type' => 'forum',
119 'to_fieldname' => 'post_modified',
120 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore
121 );
122 $this->field_map[] = array(
123 'to_type' => 'forum',
124 'to_fieldname' => 'post_modified_gmt',
125 'default' => gmdate( 'Y-m-d H:i:s' )
126 );
127
128 /** Topic Section *****************************************************/
129
130 // Old topic id (Stored in postmeta)
131 $this->field_map[] = array(
132 'from_tablename' => 'threads',
133 'from_fieldname' => 'tid',
134 'to_type' => 'topic',
135 'to_fieldname' => '_bbp_old_topic_id'
136 );
137
138 // Topic reply count (Stored in postmeta)
139 $this->field_map[] = array(
140 'from_tablename' => 'threads',
141 'from_fieldname' => 'replies',
142 'to_type' => 'topic',
143 'to_fieldname' => '_bbp_reply_count',
144 'callback_method' => 'callback_topic_reply_count'
145 );
146
147 // Topic total reply count (Includes unpublished replies, Stored in postmeta)
148 $this->field_map[] = array(
149 'from_tablename' => 'threads',
150 'from_fieldname' => 'replies',
151 'to_type' => 'topic',
152 'to_fieldname' => '_bbp_total_reply_count',
153 'callback_method' => 'callback_topic_reply_count'
154 );
155
156 // Topic parent forum id (If no parent, then 0. Stored in postmeta)
157 $this->field_map[] = array(
158 'from_tablename' => 'threads',
159 'from_fieldname' => 'fid',
160 'to_type' => 'topic',
161 'to_fieldname' => '_bbp_forum_id',
162 'callback_method' => 'callback_forumid'
163 );
164
165 // Topic author.
166 $this->field_map[] = array(
167 'from_tablename' => 'threads',
168 'from_fieldname' => 'uid',
169 'to_type' => 'topic',
170 'to_fieldname' => 'post_author',
171 'callback_method' => 'callback_userid'
172 );
173
174 // Topic Author ip (Stored in postmeta)
175 $this->field_map[] = array(
176 'from_tablename' => 'posts',
177 'from_fieldname' => 'ipaddress',
178 'join_tablename' => 'threads',
179 'join_type' => 'INNER',
180 'join_expression' => 'USING (tid) WHERE replyto = 0',
181 'to_type' => 'topic',
182 'to_fieldname' => '_bbp_author_ip'
183 );
184
185 // Topic content.
186 // Note: We join the 'posts' table because 'threads' table does not have content.
187 $this->field_map[] = array(
188 'from_tablename' => 'posts',
189 'from_fieldname' => 'message',
190 'join_tablename' => 'threads',
191 'join_type' => 'INNER',
192 'join_expression' => 'USING (tid) WHERE replyto = 0',
193 'to_type' => 'topic',
194 'to_fieldname' => 'post_content',
195 'callback_method' => 'callback_html'
196 );
197
198 // Topic title.
199 $this->field_map[] = array(
200 'from_tablename' => 'threads',
201 'from_fieldname' => 'subject',
202 'to_type' => 'topic',
203 'to_fieldname' => 'post_title'
204 );
205
206 // Topic slug (Clean name to avoid conflicts)
207 $this->field_map[] = array(
208 'from_tablename' => 'threads',
209 'from_fieldname' => 'subject',
210 'to_type' => 'topic',
211 'to_fieldname' => 'post_name',
212 'callback_method' => 'callback_slug'
213 );
214
215 // Topic parent forum id (If no parent, then 0)
216 $this->field_map[] = array(
217 'from_tablename' => 'threads',
218 'from_fieldname' => 'fid',
219 'to_type' => 'topic',
220 'to_fieldname' => 'post_parent',
221 'callback_method' => 'callback_forumid'
222 );
223
224 // Sticky status (Stored in postmeta)
225 $this->field_map[] = array(
226 'from_tablename' => 'threads',
227 'from_fieldname' => 'sticky',
228 'to_type' => 'topic',
229 'to_fieldname' => '_bbp_old_sticky_status_id',
230 'callback_method' => 'callback_sticky_status'
231 );
232
233 // Topic dates.
234 $this->field_map[] = array(
235 'from_tablename' => 'threads',
236 'from_fieldname' => 'dateline',
237 'to_type' => 'topic',
238 'to_fieldname' => 'post_date',
239 'callback_method' => 'callback_datetime'
240 );
241 $this->field_map[] = array(
242 'from_tablename' => 'threads',
243 'from_fieldname' => 'dateline',
244 'to_type' => 'topic',
245 'to_fieldname' => 'post_date_gmt',
246 'callback_method' => 'callback_datetime'
247 );
248 $this->field_map[] = array(
249 'from_tablename' => 'threads',
250 'from_fieldname' => 'lastpost',
251 'to_type' => 'topic',
252 'to_fieldname' => 'post_modified',
253 'callback_method' => 'callback_datetime'
254 );
255 $this->field_map[] = array(
256 'from_tablename' => 'threads',
257 'from_fieldname' => 'lastpost',
258 'to_type' => 'topic',
259 'to_fieldname' => 'post_modified_gmt',
260 'callback_method' => 'callback_datetime'
261 );
262 $this->field_map[] = array(
263 'from_tablename' => 'threads',
264 'from_fieldname' => 'lastpost',
265 'to_type' => 'topic',
266 'to_fieldname' => '_bbp_last_active_time',
267 'callback_method' => 'callback_datetime'
268 );
269
270 // Topic status (Open or Closed, MyBB v1.6.10 open = null & closed = 1)
271 $this->field_map[] = array(
272 'from_tablename' => 'threads',
273 'from_fieldname' => 'closed',
274 'to_type' => 'topic',
275 'to_fieldname' => '_bbp_old_closed_status_id',
276 'callback_method' => 'callback_topic_status'
277 );
278
279 /** Tags Section ******************************************************/
280
281 /**
282 * MyBB v1.6.10 Forums do not support topic tags out of the box
283 */
284
285 /** Reply Section *****************************************************/
286
287 // Old reply id (Stored in postmeta)
288 $this->field_map[] = array(
289 'from_tablename' => 'posts',
290 'from_fieldname' => 'pid',
291 'from_expression' => 'WHERE replyto != 0',
292 'to_type' => 'reply',
293 'to_fieldname' => '_bbp_old_reply_id'
294 );
295
296 // Reply parent forum id (If no parent, then 0. Stored in postmeta)
297 $this->field_map[] = array(
298 'from_tablename' => 'posts',
299 'from_fieldname' => 'fid',
300 'to_type' => 'reply',
301 'to_fieldname' => '_bbp_forum_id',
302 'callback_method' => 'callback_topicid_to_forumid'
303 );
304
305 // Reply parent topic id (If no parent, then 0. Stored in postmeta)
306 $this->field_map[] = array(
307 'from_tablename' => 'posts',
308 'from_fieldname' => 'tid',
309 'to_type' => 'reply',
310 'to_fieldname' => '_bbp_topic_id',
311 'callback_method' => 'callback_topicid'
312 );
313
314 // Reply author ip (Stored in postmeta)
315 $this->field_map[] = array(
316 'from_tablename' => 'posts',
317 'from_fieldname' => 'ipaddress',
318 'to_type' => 'reply',
319 'to_fieldname' => '_bbp_author_ip'
320 );
321
322 // Reply author.
323 $this->field_map[] = array(
324 'from_tablename' => 'posts',
325 'from_fieldname' => 'uid',
326 'to_type' => 'reply',
327 'to_fieldname' => 'post_author',
328 'callback_method' => 'callback_userid'
329 );
330
331 // Reply content.
332 $this->field_map[] = array(
333 'from_tablename' => 'posts',
334 'from_fieldname' => 'message',
335 'to_type' => 'reply',
336 'to_fieldname' => 'post_content',
337 'callback_method' => 'callback_html'
338 );
339
340 // Reply parent topic id (If no parent, then 0)
341 $this->field_map[] = array(
342 'from_tablename' => 'posts',
343 'from_fieldname' => 'tid',
344 'to_type' => 'reply',
345 'to_fieldname' => 'post_parent',
346 'callback_method' => 'callback_topicid'
347 );
348
349 // Reply dates.
350 $this->field_map[] = array(
351 'from_tablename' => 'posts',
352 'from_fieldname' => 'dateline',
353 'to_type' => 'reply',
354 'to_fieldname' => 'post_date',
355 'callback_method' => 'callback_datetime'
356 );
357 $this->field_map[] = array(
358 'from_tablename' => 'posts',
359 'from_fieldname' => 'dateline',
360 'to_type' => 'reply',
361 'to_fieldname' => 'post_date_gmt',
362 'callback_method' => 'callback_datetime'
363 );
364 $this->field_map[] = array(
365 'from_tablename' => 'posts',
366 'from_fieldname' => 'edittime',
367 'to_type' => 'reply',
368 'to_fieldname' => 'post_modified',
369 'callback_method' => 'callback_datetime'
370 );
371 $this->field_map[] = array(
372 'from_tablename' => 'posts',
373 'from_fieldname' => 'edittime',
374 'to_type' => 'reply',
375 'to_fieldname' => 'post_modified_gmt',
376 'callback_method' => 'callback_datetime'
377 );
378
379 /** User Section ******************************************************/
380
381 // Store old user id (Stored in usermeta)
382 $this->field_map[] = array(
383 'from_tablename' => 'users',
384 'from_fieldname' => 'uid',
385 'to_type' => 'user',
386 'to_fieldname' => '_bbp_old_user_id'
387 );
388
389 // Store old user password (Stored in usermeta serialized with salt)
390 $this->field_map[] = array(
391 'from_tablename' => 'users',
392 'from_fieldname' => 'password',
393 'to_type' => 'user',
394 'to_fieldname' => '_bbp_password',
395 'callback_method' => 'callback_savepass'
396 );
397
398 // Store old user salt (This is only used for the SELECT row info for the above password save)
399 $this->field_map[] = array(
400 'from_tablename' => 'users',
401 'from_fieldname' => 'salt',
402 'to_type' => 'user',
403 'to_fieldname' => ''
404 );
405
406 // User password verify class (Stored in usermeta for verifying password)
407 $this->field_map[] = array(
408 'to_type' => 'users',
409 'to_fieldname' => '_bbp_class',
410 'default' => 'MyBB'
411 );
412
413 // User name.
414 $this->field_map[] = array(
415 'from_tablename' => 'users',
416 'from_fieldname' => 'username',
417 'to_type' => 'user',
418 'to_fieldname' => 'user_login'
419 );
420
421 // User nice name.
422 $this->field_map[] = array(
423 'from_tablename' => 'users',
424 'from_fieldname' => 'username',
425 'to_type' => 'user',
426 'to_fieldname' => 'user_nicename'
427 );
428
429 // User email.
430 $this->field_map[] = array(
431 'from_tablename' => 'users',
432 'from_fieldname' => 'email',
433 'to_type' => 'user',
434 'to_fieldname' => 'user_email'
435 );
436
437 // User homepage.
438 $this->field_map[] = array(
439 'from_tablename' => 'users',
440 'from_fieldname' => 'website',
441 'to_type' => 'user',
442 'to_fieldname' => 'user_url'
443 );
444
445 // User registered.
446 $this->field_map[] = array(
447 'from_tablename' => 'users',
448 'from_fieldname' => 'regdate',
449 'to_type' => 'user',
450 'to_fieldname' => 'user_registered',
451 'callback_method' => 'callback_datetime'
452 );
453
454 // User display name.
455 $this->field_map[] = array(
456 'from_tablename' => 'users',
457 'from_fieldname' => 'usertitle',
458 'to_type' => 'user',
459 'to_fieldname' => 'display_name'
460 );
461
462 // User AIM (Stored in usermeta)
463 $this->field_map[] = array(
464 'from_tablename' => 'users',
465 'from_fieldname' => 'aim',
466 'to_type' => 'user',
467 'to_fieldname' => '_bbp_mybb_user_aim'
468 );
469
470 // User Yahoo (Stored in usermeta)
471 $this->field_map[] = array(
472 'from_tablename' => 'users',
473 'from_fieldname' => 'yahoo',
474 'to_type' => 'user',
475 'to_fieldname' => '_bbp_mybb_user_yim'
476 );
477
478 // Store ICQ (Stored in usermeta)
479 $this->field_map[] = array(
480 'from_tablename' => 'users',
481 'from_fieldname' => 'icq',
482 'to_type' => 'user',
483 'to_fieldname' => '_bbp_mybb_user_icq'
484 );
485
486 // Store MSN (Stored in usermeta)
487 $this->field_map[] = array(
488 'from_tablename' => 'users',
489 'from_fieldname' => 'msn',
490 'to_type' => 'user',
491 'to_fieldname' => '_bbp_mybb_user_msn'
492 );
493
494 // Store Signature (Stored in usermeta)
495 $this->field_map[] = array(
496 'from_tablename' => 'users',
497 'from_fieldname' => 'signature',
498 'to_type' => 'user',
499 'to_fieldname' => '_bbp_mybb_user_sig',
500 'callback_method' => 'callback_html'
501 );
502 }
503
504 /**
505 * This method allows us to indicates what is or is not converted for each
506 * converter.
507 */
508 public function info() {
509 return '';
510 }
511
512 /**
513 * This method is to save the salt and password together. That
514 * way when we authenticate it we can get it out of the database
515 * as one value. Array values are auto sanitized by WordPress.
516 */
517 public function callback_savepass( $field, $row ) {
518 $pass_array = array(
519 'hash' => $field,
520 'salt' => $row['salt']
521 );
522
523 return $pass_array;
524 }
525
526 /**
527 * This method is to take the pass out of the database and compare
528 * to a pass the user has typed in.
529 */
530 public function authenticate_pass( $password, $serialized_pass ) {
531
532 // Unserialize the password, with safeguards
533 $pass_array = unserialize(
534 $serialized_pass,
535 array(
536 'allowed_classes' => false,
537 'max_depth' => 1,
538 )
539 );
540
541 // Bail if missing values
542 if ( ! is_array( $pass_array ) || ! isset( $pass_array['hash'], $pass_array['salt'] ) ) {
543 return false;
544 }
545
546 // Return comparison
547 return hash_equals(
548 $pass_array['hash'],
549 md5( md5( $password ) . $pass_array['salt'] )
550 );
551 }
552
553 /**
554 * Translate the post status from MyBB v1.6.10 numerics to WordPress's strings.
555 *
556 * @param int $status MyBB v1.6.10 numeric topic status
557 * @return string WordPress safe
558 */
559 public function callback_topic_status( $status = 0 ) {
560 switch ( $status ) {
561 case 1 :
562 $status = 'closed';
563 break;
564
565 case 0 :
566 default :
567 $status = 'publish';
568 break;
569 }
570 return $status;
571 }
572
573 /**
574 * Translate the topic sticky status type from MyBB v1.6.10 numerics to WordPress's strings.
575 *
576 * @param int $status MyBB v1.6.10 numeric forum type
577 * @return string WordPress safe
578 */
579 public function callback_sticky_status( $status = 0 ) {
580 switch ( $status ) {
581 case 1 :
582 $status = 'sticky'; // MyBB Sticky 'topic_sticky = 1'
583 break;
584
585 case 0 :
586 default :
587 $status = 'normal'; // MyBB Normal Topic 'topic_sticky = 0'
588 break;
589 }
590 return $status;
591 }
592
593 /**
594 * Verify the topic/reply count.
595 *
596 * @param int $count MyBB v1.6.10 topic/reply counts
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