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 / AEF.php

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

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