PluginProbe
bbPress / 2.6.19
bbPress v2.6.19
2.6.19 2.6.18 2.6.17 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 All 74 releases
bbpress / includes / admin / converters / FluxBB.php

FluxBB.php in bbPress 2.6.19, at includes/admin/converters/FluxBB.php

732 lines 20.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress FluxBB Converter
5 *
6 * @package bbPress
7 * @subpackage Converters
8 */
9
10 /**
11 * Implementation of FluxBB Forum converter.
12 *
13 * @since 2.5.0 bbPress (r5139)
14 *
15 * @link Codex Docs https://codex.bbpress.org/import-forums/fluxbb
16 */
17 class FluxBB extends BBP_Converter_Base {
18
19 /**
20 * @var bool Whether source-dependent fields have been set up.
21 * @since 2.6.18 bbPress (r7588)
22 */
23 private $source_fields_setup = false;
24
25 /**
26 * Main Constructor
27 *
28 */
29 public function __construct() {
30 parent::__construct();
31 }
32
33 /**
34 * Sets up the field mappings
35 */
36 public function setup_globals() {
37
38 /** Forum Section *****************************************************/
39
40 // Old forum id (Stored in postmeta)
41 $this->field_map[] = array(
42 'from_tablename' => 'forums',
43 'from_fieldname' => 'id',
44 'to_type' => 'forum',
45 'to_fieldname' => '_bbp_old_forum_id'
46 );
47
48 // Forum topic count (Stored in postmeta)
49 $this->field_map[] = array(
50 'from_tablename' => 'forums',
51 'from_fieldname' => 'num_topics',
52 'to_type' => 'forum',
53 'to_fieldname' => '_bbp_topic_count'
54 );
55
56 // Forum reply count (Stored in postmeta)
57 $this->field_map[] = array(
58 'from_tablename' => 'forums',
59 'from_fieldname' => 'num_posts',
60 'to_type' => 'forum',
61 'to_fieldname' => '_bbp_reply_count'
62 );
63
64 // Forum total topic count (Stored in postmeta)
65 $this->field_map[] = array(
66 'from_tablename' => 'forums',
67 'from_fieldname' => 'num_topics',
68 'to_type' => 'forum',
69 'to_fieldname' => '_bbp_total_topic_count'
70 );
71
72 // Forum total reply count (Stored in postmeta)
73 $this->field_map[] = array(
74 'from_tablename' => 'forums',
75 'from_fieldname' => 'num_posts',
76 'to_type' => 'forum',
77 'to_fieldname' => '_bbp_total_reply_count'
78 );
79
80 // Forum title.
81 $this->field_map[] = array(
82 'from_tablename' => 'forums',
83 'from_fieldname' => 'forum_name',
84 'to_type' => 'forum',
85 'to_fieldname' => 'post_title'
86 );
87
88 // Forum slug (Clean name to avoid conflicts)
89 $this->field_map[] = array(
90 'from_tablename' => 'forums',
91 'from_fieldname' => 'forum_name',
92 'to_type' => 'forum',
93 'to_fieldname' => 'post_name',
94 'callback_method' => 'callback_slug'
95 );
96
97 // Forum description.
98 $this->field_map[] = array(
99 'from_tablename' => 'forums',
100 'from_fieldname' => 'forum_desc',
101 'to_type' => 'forum',
102 'to_fieldname' => 'post_content',
103 'callback_method' => 'callback_null'
104 );
105
106 // Forum display order (Starts from 1)
107 $this->field_map[] = array(
108 'from_tablename' => 'forums',
109 'from_fieldname' => 'disp_position',
110 'to_type' => 'forum',
111 'to_fieldname' => 'menu_order'
112 );
113
114 // Forum type (Set a default value 'forum', Stored in postmeta)
115 $this->field_map[] = array(
116 'to_type' => 'forum',
117 'to_fieldname' => '_bbp_forum_type',
118 'default' => 'forum'
119 );
120
121 // Forum status (Set a default value 'open', Stored in postmeta)
122 $this->field_map[] = array(
123 'to_type' => 'forum',
124 'to_fieldname' => '_bbp_status',
125 'default' => 'open'
126 );
127
128 // Forum dates.
129 $this->field_map[] = array(
130 'to_type' => 'forum',
131 'to_fieldname' => 'post_date',
132 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
133 );
134 $this->field_map[] = array(
135 'to_type' => 'forum',
136 'to_fieldname' => 'post_date_gmt',
137 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
138 );
139 $this->field_map[] = array(
140 'to_type' => 'forum',
141 'to_fieldname' => 'post_modified',
142 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
143 );
144 $this->field_map[] = array(
145 'to_type' => 'forum',
146 'to_fieldname' => 'post_modified_gmt',
147 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
148 );
149
150 /** Forum Subscriptions Section ***************************************/
151
152 // Subscribed forum ID (Stored in usermeta)
153 $this->field_map[] = array(
154 'from_tablename' => 'forum_subscriptions',
155 'from_fieldname' => 'forum_id',
156 'to_type' => 'forum_subscriptions',
157 'to_fieldname' => '_bbp_forum_subscriptions'
158 );
159
160 // Subscribed user ID (Stored in usermeta)
161 $this->field_map[] = array(
162 'from_tablename' => 'forum_subscriptions',
163 'from_fieldname' => 'user_id',
164 'to_type' => 'forum_subscriptions',
165 'to_fieldname' => 'user_id',
166 'callback_method' => 'callback_userid'
167 );
168
169 /** Topic Section *****************************************************/
170
171 // Old topic id (Stored in postmeta)
172 $this->field_map[] = array(
173 'from_tablename' => 'topics',
174 'from_fieldname' => 'id',
175 'to_type' => 'topic',
176 'to_fieldname' => '_bbp_old_topic_id'
177 );
178
179 // Topic reply count (Stored in postmeta)
180 $this->field_map[] = array(
181 'from_tablename' => 'topics',
182 'from_fieldname' => 'num_replies',
183 'to_type' => 'topic',
184 'to_fieldname' => '_bbp_reply_count',
185 'callback_method' => 'callback_topic_reply_count'
186 );
187
188 // Topic total reply count (Includes unpublished replies, Stored in postmeta)
189 $this->field_map[] = array(
190 'from_tablename' => 'topics',
191 'from_fieldname' => 'num_replies',
192 'to_type' => 'topic',
193 'to_fieldname' => '_bbp_total_reply_count',
194 'callback_method' => 'callback_topic_reply_count'
195 );
196
197 // Topic parent forum id (If no parent, then 0, Stored in postmeta)
198 $this->field_map[] = array(
199 'from_tablename' => 'topics',
200 'from_fieldname' => 'forum_id',
201 'to_type' => 'topic',
202 'to_fieldname' => '_bbp_forum_id',
203 'callback_method' => 'callback_forumid'
204 );
205
206 // Topic author.
207 // Note: We join the 'posts' table because 'topics' table does include numeric user id.
208 $this->field_map[] = array(
209 'from_tablename' => 'posts',
210 'from_fieldname' => 'poster_id',
211 'join_tablename' => 'topics',
212 'join_type' => 'INNER',
213 'join_expression' => 'ON topics.first_post_id = posts.id',
214 'to_type' => 'topic',
215 'to_fieldname' => 'post_author',
216 'callback_method' => 'callback_userid'
217 );
218
219 // Topic Author ip (Stored in postmeta)
220 // Note: We join the 'posts' table because 'topics' table does not include author IP addresses.
221 $this->field_map[] = array(
222 'from_tablename' => 'posts',
223 'from_fieldname' => 'poster_ip',
224 'join_tablename' => 'topics',
225 'join_type' => 'INNER',
226 'join_expression' => 'ON topics.first_post_id = posts.id',
227 'to_type' => 'topic',
228 'to_fieldname' => '_bbp_author_ip'
229 );
230
231 // Topic content.
232 // Note: We join the 'posts' table because 'topics' table does not include topic content.
233 $this->field_map[] = array(
234 'from_tablename' => 'posts',
235 'from_fieldname' => 'message',
236 'join_tablename' => 'topics',
237 'join_type' => 'INNER',
238 'join_expression' => 'ON topics.first_post_id = posts.id',
239 'to_type' => 'topic',
240 'to_fieldname' => 'post_content',
241 'callback_method' => 'callback_html'
242 );
243
244 // Topic title.
245 $this->field_map[] = array(
246 'from_tablename' => 'topics',
247 'from_fieldname' => 'subject',
248 'to_type' => 'topic',
249 'to_fieldname' => 'post_title'
250 );
251
252 // Topic slug (Clean name to avoid conflicts)
253 $this->field_map[] = array(
254 'from_tablename' => 'topics',
255 'from_fieldname' => 'subject',
256 'to_type' => 'topic',
257 'to_fieldname' => 'post_name',
258 'callback_method' => 'callback_slug'
259 );
260
261 // Topic parent forum id (If no parent, then 0)
262 $this->field_map[] = array(
263 'from_tablename' => 'topics',
264 'from_fieldname' => 'forum_id',
265 'to_type' => 'topic',
266 'to_fieldname' => 'post_parent',
267 'callback_method' => 'callback_forumid'
268 );
269
270 // Sticky status (Stored in postmeta)
271 $this->field_map[] = array(
272 'from_tablename' => 'topics',
273 'from_fieldname' => 'sticky',
274 'to_type' => 'topic',
275 'to_fieldname' => '_bbp_old_sticky_status_id',
276 'callback_method' => 'callback_sticky_status'
277 );
278
279 // Topic dates.
280 $this->field_map[] = array(
281 'from_tablename' => 'topics',
282 'from_fieldname' => 'posted',
283 'to_type' => 'topic',
284 'to_fieldname' => 'post_date',
285 'callback_method' => 'callback_datetime'
286 );
287 $this->field_map[] = array(
288 'from_tablename' => 'topics',
289 'from_fieldname' => 'posted',
290 'to_type' => 'topic',
291 'to_fieldname' => 'post_date_gmt',
292 'callback_method' => 'callback_datetime'
293 );
294 $this->field_map[] = array(
295 'from_tablename' => 'topics',
296 'from_fieldname' => 'posted',
297 'to_type' => 'topic',
298 'to_fieldname' => 'post_modified',
299 'callback_method' => 'callback_datetime'
300 );
301 $this->field_map[] = array(
302 'from_tablename' => 'topics',
303 'from_fieldname' => 'posted',
304 'to_type' => 'topic',
305 'to_fieldname' => 'post_modified_gmt',
306 'callback_method' => 'callback_datetime'
307 );
308 $this->field_map[] = array(
309 'from_tablename' => 'topics',
310 'from_fieldname' => 'posted',
311 'to_type' => 'topic',
312 'to_fieldname' => '_bbp_last_active_time',
313 'callback_method' => 'callback_datetime'
314 );
315
316 // Topic status (Open = 0 or Closed = 1, FluxBB v1.5.3)
317 $this->field_map[] = array(
318 'from_tablename' => 'topics',
319 'from_fieldname' => 'closed',
320 'to_type' => 'topic',
321 'to_fieldname' => '_bbp_old_closed_status_id',
322 'callback_method' => 'callback_topic_status'
323 );
324
325 /** Tags Section ******************************************************/
326
327 /**
328 * FluxBB v1.5.3 Forums do not support topic tags out of the box
329 */
330
331 /** Topic Subscriptions Section ***************************************/
332
333 // Subscribed topic ID (Stored in usermeta)
334 $this->field_map[] = array(
335 'from_tablename' => 'topic_subscriptions',
336 'from_fieldname' => 'topic_id',
337 'to_type' => 'topic_subscriptions',
338 'to_fieldname' => '_bbp_subscriptions'
339 );
340
341 // Subscribed user ID (Stored in usermeta)
342 $this->field_map[] = array(
343 'from_tablename' => 'topic_subscriptions',
344 'from_fieldname' => 'user_id',
345 'to_type' => 'topic_subscriptions',
346 'to_fieldname' => 'user_id',
347 'callback_method' => 'callback_userid'
348 );
349
350 /** Reply Section *****************************************************/
351
352 // Old reply id (Stored in postmeta)
353 $this->field_map[] = array(
354 'from_tablename' => 'posts',
355 'from_fieldname' => 'id',
356 'to_type' => 'reply',
357 'to_fieldname' => '_bbp_old_reply_id'
358 );
359
360 // Reply parent forum id (If no parent, then 0, Stored in postmeta)
361 $this->field_map[] = array(
362 'from_tablename' => 'posts',
363 'from_fieldname' => 'topic_id',
364 'to_type' => 'reply',
365 'to_fieldname' => '_bbp_forum_id',
366 'callback_method' => 'callback_topicid_to_forumid'
367 );
368
369 // Reply parent topic id (If no parent, then 0, Stored in postmeta)
370 $this->field_map[] = array(
371 'from_tablename' => 'posts',
372 'from_fieldname' => 'topic_id',
373 'to_type' => 'reply',
374 'to_fieldname' => '_bbp_topic_id',
375 'callback_method' => 'callback_topicid'
376 );
377
378 // Reply author ip (Stored in postmeta)
379 $this->field_map[] = array(
380 'from_tablename' => 'posts',
381 'from_fieldname' => 'poster_ip',
382 'to_type' => 'reply',
383 'to_fieldname' => '_bbp_author_ip'
384 );
385
386 // Reply author.
387 $this->field_map[] = array(
388 'from_tablename' => 'posts',
389 'from_fieldname' => 'poster_id',
390 'to_type' => 'reply',
391 'to_fieldname' => 'post_author',
392 'callback_method' => 'callback_userid'
393 );
394
395 // Reply content.
396 $this->field_map[] = array(
397 'from_tablename' => 'posts',
398 'from_fieldname' => 'message',
399 'to_type' => 'reply',
400 'to_fieldname' => 'post_content',
401 'callback_method' => 'callback_html'
402 );
403
404 // Reply parent topic id (If no parent, then 0)
405 $this->field_map[] = array(
406 'from_tablename' => 'posts',
407 'from_fieldname' => 'topic_id',
408 'to_type' => 'reply',
409 'to_fieldname' => 'post_parent',
410 'callback_method' => 'callback_topicid'
411 );
412
413 // Reply dates.
414 $this->field_map[] = array(
415 'from_tablename' => 'posts',
416 'from_fieldname' => 'posted',
417 'to_type' => 'reply',
418 'to_fieldname' => 'post_date',
419 'callback_method' => 'callback_datetime'
420 );
421 $this->field_map[] = array(
422 'from_tablename' => 'posts',
423 'from_fieldname' => 'posted',
424 'to_type' => 'reply',
425 'to_fieldname' => 'post_date_gmt',
426 'callback_method' => 'callback_datetime'
427 );
428 $this->field_map[] = array(
429 'from_tablename' => 'posts',
430 'from_fieldname' => 'posted',
431 'to_type' => 'reply',
432 'to_fieldname' => 'post_modified',
433 'callback_method' => 'callback_datetime'
434 );
435 $this->field_map[] = array(
436 'from_tablename' => 'posts',
437 'from_fieldname' => 'posted',
438 'to_type' => 'reply',
439 'to_fieldname' => 'post_modified_gmt',
440 'callback_method' => 'callback_datetime'
441 );
442
443 /** User Section ******************************************************/
444
445 // Store old user id (Stored in usermeta)
446 $this->field_map[] = array(
447 'from_tablename' => 'users',
448 'from_fieldname' => 'id',
449 'to_type' => 'user',
450 'to_fieldname' => '_bbp_old_user_id'
451 );
452
453 // Store old user password (Stored in usermeta serialized with salt)
454 $this->field_map[] = array(
455 'from_tablename' => 'users',
456 'from_fieldname' => 'password',
457 'to_type' => 'user',
458 'to_fieldname' => '_bbp_password',
459 'callback_method' => 'callback_savepass'
460 );
461
462 // User password verify class (Stored in usermeta for verifying password)
463 $this->field_map[] = array(
464 'to_type' => 'user',
465 'to_fieldname' => '_bbp_class',
466 'default' => 'FluxBB'
467 );
468
469 // User name.
470 $this->field_map[] = array(
471 'from_tablename' => 'users',
472 'from_fieldname' => 'username',
473 'to_type' => 'user',
474 'to_fieldname' => 'user_login'
475 );
476
477 // User nice name.
478 $this->field_map[] = array(
479 'from_tablename' => 'users',
480 'from_fieldname' => 'username',
481 'to_type' => 'user',
482 'to_fieldname' => 'user_nicename'
483 );
484
485 // User email.
486 $this->field_map[] = array(
487 'from_tablename' => 'users',
488 'from_fieldname' => 'email',
489 'to_type' => 'user',
490 'to_fieldname' => 'user_email'
491 );
492
493 // User homepage.
494 $this->field_map[] = array(
495 'from_tablename' => 'users',
496 'from_fieldname' => 'url',
497 'to_type' => 'user',
498 'to_fieldname' => 'user_url'
499 );
500
501 // User registered.
502 $this->field_map[] = array(
503 'from_tablename' => 'users',
504 'from_fieldname' => 'registered',
505 'to_type' => 'user',
506 'to_fieldname' => 'user_registered',
507 'callback_method' => 'callback_datetime'
508 );
509
510 // User display name.
511 $this->field_map[] = array(
512 'from_tablename' => 'users',
513 'from_fieldname' => 'realname',
514 'to_type' => 'user',
515 'to_fieldname' => 'display_name'
516 );
517
518 // User AIM (Stored in usermeta)
519 $this->field_map[] = array(
520 'from_tablename' => 'users',
521 'from_fieldname' => 'aim',
522 'to_type' => 'user',
523 'to_fieldname' => '_bbp_fluxbb_user_aim'
524 );
525
526 // User Yahoo (Stored in usermeta)
527 $this->field_map[] = array(
528 'from_tablename' => 'users',
529 'from_fieldname' => 'yahoo',
530 'to_type' => 'user',
531 'to_fieldname' => '_bbp_fluxbb_user_yim'
532 );
533
534 // Store Jabber
535 $this->field_map[] = array(
536 'from_tablename' => 'users',
537 'from_fieldname' => 'jabber',
538 'to_type' => 'user',
539 'to_fieldname' => '_bbp_fluxbb_user_jabber'
540 );
541
542 // Store ICQ (Stored in usermeta)
543 $this->field_map[] = array(
544 'from_tablename' => 'users',
545 'from_fieldname' => 'icq',
546 'to_type' => 'user',
547 'to_fieldname' => '_bbp_fluxbb_user_icq'
548 );
549
550 // Store MSN (Stored in usermeta)
551 $this->field_map[] = array(
552 'from_tablename' => 'users',
553 'from_fieldname' => 'msn',
554 'to_type' => 'user',
555 'to_fieldname' => '_bbp_fluxbb_user_msn'
556 );
557
558 // Store Location (Stored in usermeta)
559 $this->field_map[] = array(
560 'from_tablename' => 'users',
561 'from_fieldname' => 'location',
562 'to_type' => 'user',
563 'to_fieldname' => '_bbp_fluxbb_user_location'
564 );
565
566 // Store Signature (Stored in usermeta)
567 $this->field_map[] = array(
568 'from_tablename' => 'users',
569 'from_fieldname' => 'signature',
570 'to_type' => 'user',
571 'to_fieldname' => '_bbp_fluxbb_user_sig',
572 'callback_method' => 'callback_html'
573 );
574
575 // Store Admin Note (Stored in usermeta)
576 $this->field_map[] = array(
577 'from_tablename' => 'users',
578 'from_fieldname' => 'admin_note',
579 'to_type' => 'user',
580 'to_fieldname' => '_bbp_fluxbb_user_admin_note'
581 );
582 }
583
584 /**
585 * This method allows us to indicates what is or is not converted for each
586 * converter.
587 */
588 public function info() {
589 return '';
590 }
591
592 /**
593 * Setup the optional legacy salt field after connecting to the source.
594 *
595 * @since 2.6.18 bbPress (r7588)
596 */
597 protected function setup_source_fields() {
598 if ( $this->source_fields_setup ) {
599 return;
600 }
601
602 $this->source_fields_setup = true;
603
604 if ( $this->source_has_salt() ) {
605 $this->field_map[] = array(
606 'from_tablename' => 'users',
607 'from_fieldname' => 'salt',
608 'to_type' => 'user',
609 'to_fieldname' => ''
610 );
611 }
612 }
613
614 /**
615 * Check whether the source users table retains the legacy FluxBB salt field.
616 *
617 * @since 2.6.18 bbPress (r7538)
618 *
619 * @return bool True when the salt field exists, false otherwise.
620 */
621 private function source_has_salt() {
622 if ( empty( $this->opdb ) ) {
623 return false;
624 }
625
626 return (bool) $this->opdb->get_var( "SHOW COLUMNS FROM {$this->opdb->prefix}users LIKE 'salt'" );
627 }
628
629 /**
630 * Save the salt and password together. Pre-slash the salt because WordPress
631 * removes one layer of slashes when storing user metadata.
632 */
633 public function callback_savepass( $field, $row ) {
634 $pass_array = array(
635 'hash' => $field,
636 'salt' => isset( $row['salt'] ) ? wp_slash( (string) $row['salt'] ) : ''
637 );
638
639 return $pass_array;
640 }
641
642 /**
643 * This method is to take the pass out of the database and compare
644 * to a pass the user has typed in.
645 */
646 public function authenticate_pass( $password, $serialized_pass ) {
647
648 // Unserialize the password, with safeguards
649 $pass_array = $this->unserialize_pass( $serialized_pass );
650
651 // Bail if missing or invalid values
652 if ( ! is_array( $pass_array ) || ! isset( $pass_array['hash'] ) || ! array_key_exists( 'salt', $pass_array ) || ! is_string( $pass_array['hash'] ) || ( ! is_string( $pass_array['salt'] ) && ! is_null( $pass_array['salt'] ) ) ) {
653 return false;
654 }
655
656 $salt = (string) $pass_array['salt'];
657
658 // Salted SHA-1 from FluxBB 1.3
659 if ( ! empty( $salt ) ) {
660 return hash_equals(
661 $pass_array['hash'],
662 sha1( $salt . sha1( $password ) )
663 );
664 }
665
666 // Unsalted MD5 from FluxBB 1.2
667 if ( 40 !== strlen( $pass_array['hash'] ) ) {
668 return hash_equals(
669 $pass_array['hash'],
670 md5( $password )
671 );
672 }
673
674 // SHA-1 from FluxBB 1.4 and newer
675 return hash_equals(
676 $pass_array['hash'],
677 sha1( $password )
678 );
679 }
680
681 /**
682 * Translate the post status from FluxBB v1.5.3 numerics to WordPress's strings.
683 *
684 * @param int $status FluxBB v1.5.3 numeric topic status
685 * @return string WordPress safe
686 */
687 public function callback_topic_status( $status = 0 ) {
688 switch ( $status ) {
689 case 1 :
690 $status = 'closed';
691 break;
692
693 case 0 :
694 default :
695 $status = 'publish';
696 break;
697 }
698 return $status;
699 }
700
701 /**
702 * Translate the topic sticky status type from FluxBB v1.5.3 numerics to WordPress's strings.
703 *
704 * @param int $status FluxBB v1.5.3 numeric forum type
705 * @return string WordPress safe
706 */
707 public function callback_sticky_status( $status = 0 ) {
708 switch ( $status ) {
709 case 1 :
710 $status = 'sticky'; // FluxBB Sticky 'sticky = 1'
711 break;
712
713 case 0 :
714 default :
715 $status = 'normal'; // FluxBB Normal Topic 'sticky = 0'
716 break;
717 }
718 return $status;
719 }
720
721 /**
722 * Verify the topic/reply count.
723 *
724 * @param int $count FluxBB v1.5.3 topic/reply counts
725 * @return string WordPress safe
726 */
727 public function callback_topic_reply_count( $count = 1 ) {
728 $count = absint( (int) $count - 1 );
729 return $count;
730 }
731 }
732