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

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

634 lines 17.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress PHPFox3 Converter
5 *
6 * @package bbPress
7 * @subpackage Converters
8 */
9
10 /**
11 * Implementation of PHPFox v3.x Forum converter.
12 *
13 * @since 2.5.0 bbPress (r5146)
14 *
15 * @link Codex Docs https://codex.bbpress.org/import-forums/phpfox
16 */
17 class PHPFox3 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' => 'forum',
29 'from_fieldname' => 'forum_id',
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' => 'forum',
37 'from_fieldname' => 'parent_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' => 'forum',
45 'from_fieldname' => 'total_thread',
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' => 'forum',
53 'from_fieldname' => 'total_post',
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' => 'forum',
61 'from_fieldname' => 'total_thread',
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' => 'forum',
69 'from_fieldname' => 'total_post',
70 'to_type' => 'forum',
71 'to_fieldname' => '_bbp_total_reply_count'
72 );
73
74 // Forum title.
75 $this->field_map[] = array(
76 'from_tablename' => 'forum',
77 'from_fieldname' => 'name',
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' => 'forum',
85 'from_fieldname' => 'name_url',
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' => 'forum',
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' => 'forum',
103 'from_fieldname' => 'ordering',
104 'to_type' => 'forum',
105 'to_fieldname' => 'menu_order'
106 );
107
108 // Forum type (Forum = 0 or Category = 1, Stored in postmeta)
109 $this->field_map[] = array(
110 'from_tablename' => 'forum',
111 'from_fieldname' => 'is_category',
112 'to_type' => 'forum',
113 'to_fieldname' => '_bbp_forum_type',
114 'callback_method' => 'callback_forum_type'
115 );
116
117 // Forum status (0=Open or 1=Closed, Stored in postmeta)
118 $this->field_map[] = array(
119 'from_tablename' => 'forum',
120 'from_fieldname' => 'is_closed',
121 'to_type' => 'forum',
122 'to_fieldname' => '_bbp_status',
123 'callback_method' => 'callback_forum_status'
124 );
125
126 // Forum dates.
127 $this->field_map[] = array(
128 'to_type' => 'forum',
129 'to_fieldname' => 'post_date',
130 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore
131 );
132 $this->field_map[] = array(
133 'to_type' => 'forum',
134 'to_fieldname' => 'post_date_gmt',
135 'default' => gmdate( 'Y-m-d H:i:s' )
136 );
137 $this->field_map[] = array(
138 'to_type' => 'forum',
139 'to_fieldname' => 'post_modified',
140 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore
141 );
142 $this->field_map[] = array(
143 'to_type' => 'forum',
144 'to_fieldname' => 'post_modified_gmt',
145 'default' => gmdate( 'Y-m-d H:i:s' )
146 );
147
148 /** Topic Section *****************************************************/
149
150 // Old topic id (Stored in postmeta)
151 $this->field_map[] = array(
152 'from_tablename' => 'forum_thread',
153 'from_fieldname' => 'thread_id',
154 'to_type' => 'topic',
155 'to_fieldname' => '_bbp_old_topic_id'
156 );
157
158 // Topic reply count (Stored in postmeta)
159 $this->field_map[] = array(
160 'from_tablename' => 'forum_thread',
161 'from_fieldname' => 'total_post',
162 'to_type' => 'topic',
163 'to_fieldname' => '_bbp_reply_count',
164 'callback_method' => 'callback_topic_reply_count'
165 );
166
167 // Topic total reply count (Includes unpublished replies, Stored in postmeta)
168 $this->field_map[] = array(
169 'from_tablename' => 'forum_thread',
170 'from_fieldname' => 'total_post',
171 'to_type' => 'topic',
172 'to_fieldname' => '_bbp_total_reply_count',
173 'callback_method' => 'callback_topic_reply_count'
174 );
175
176 // Topic parent forum id (If no parent, then 0. Stored in postmeta)
177 $this->field_map[] = array(
178 'from_tablename' => 'forum_thread',
179 'from_fieldname' => 'forum_id',
180 'to_type' => 'topic',
181 'to_fieldname' => '_bbp_forum_id',
182 'callback_method' => 'callback_forumid'
183 );
184
185 // Topic author.
186 $this->field_map[] = array(
187 'from_tablename' => 'forum_thread',
188 'from_fieldname' => 'user_id',
189 'to_type' => 'topic',
190 'to_fieldname' => 'post_author',
191 'callback_method' => 'callback_userid'
192 );
193
194 // Topic content.
195 // Note: We join the 'forum_post_text' table because 'forum_thread' table does not include content.
196 // Note: We can use 'text' for original text OR 'text_parsed' for pre-parsed text output
197 $this->field_map[] = array(
198 'from_tablename' => 'forum_post_text',
199 'from_fieldname' => 'text_parsed',
200 'join_tablename' => 'forum_thread',
201 'join_type' => 'LEFT',
202 'join_expression' => 'ON forum_thread.start_id = forum_post_text.post_id',
203 'to_type' => 'topic',
204 'to_fieldname' => 'post_content',
205 'callback_method' => 'callback_html'
206 );
207
208 // Topic title.
209 $this->field_map[] = array(
210 'from_tablename' => 'forum_thread',
211 'from_fieldname' => 'title',
212 'to_type' => 'topic',
213 'to_fieldname' => 'post_title'
214 );
215
216 // Topic slug (Clean name to avoid conflicts)
217 $this->field_map[] = array(
218 'from_tablename' => 'forum_thread',
219 'from_fieldname' => 'title_url',
220 'to_type' => 'topic',
221 'to_fieldname' => 'post_name',
222 'callback_method' => 'callback_slug'
223 );
224
225 // Topic parent forum id (If no parent, then 0)
226 $this->field_map[] = array(
227 'from_tablename' => 'forum_thread',
228 'from_fieldname' => 'forum_id',
229 'to_type' => 'topic',
230 'to_fieldname' => 'post_parent',
231 'callback_method' => 'callback_forumid'
232 );
233
234 // Topic status (Open or Closed, PHPFox v3.5.x 0=open & 1=closed)
235 $this->field_map[] = array(
236 'from_tablename' => 'forum_thread',
237 'from_fieldname' => 'is_closed',
238 'to_type' => 'topic',
239 'to_fieldname' => '_bbp_old_closed_status_id',
240 'callback_method' => 'callback_topic_status'
241 );
242
243 // Sticky status (Stored in postmeta)
244 $this->field_map[] = array(
245 'from_tablename' => 'forum_thread',
246 'from_fieldname' => 'order_id',
247 'to_type' => 'topic',
248 'to_fieldname' => '_bbp_old_sticky_status_id',
249 'callback_method' => 'callback_sticky_status'
250 );
251
252 // Topic dates.
253 $this->field_map[] = array(
254 'from_tablename' => 'forum_thread',
255 'from_fieldname' => 'time_stamp',
256 'to_type' => 'topic',
257 'to_fieldname' => 'post_date',
258 'callback_method' => 'callback_datetime'
259 );
260 $this->field_map[] = array(
261 'from_tablename' => 'forum_thread',
262 'from_fieldname' => 'time_stamp',
263 'to_type' => 'topic',
264 'to_fieldname' => 'post_date_gmt',
265 'callback_method' => 'callback_datetime'
266 );
267 $this->field_map[] = array(
268 'from_tablename' => 'forum_thread',
269 'from_fieldname' => 'time_update',
270 'to_type' => 'topic',
271 'to_fieldname' => 'post_modified',
272 'callback_method' => 'callback_datetime'
273 );
274 $this->field_map[] = array(
275 'from_tablename' => 'forum_thread',
276 'from_fieldname' => 'time_update',
277 'to_type' => 'topic',
278 'to_fieldname' => 'post_modified_gmt',
279 'callback_method' => 'callback_datetime'
280 );
281 $this->field_map[] = array(
282 'from_tablename' => 'forum_thread',
283 'from_fieldname' => 'time_update',
284 'to_type' => 'topic',
285 'to_fieldname' => '_bbp_last_active_time',
286 'callback_method' => 'callback_datetime'
287 );
288
289 /** Tags Section ******************************************************/
290
291 // Topic id.
292 $this->field_map[] = array(
293 'from_tablename' => 'tag',
294 'from_fieldname' => 'item_id',
295 'to_type' => 'tags',
296 'to_fieldname' => 'objectid',
297 'callback_method' => 'callback_topicid'
298 );
299
300 // Taxonomy ID.
301 $this->field_map[] = array(
302 'from_tablename' => 'tag',
303 'from_fieldname' => 'tag_id',
304 'to_type' => 'tags',
305 'to_fieldname' => 'taxonomy'
306 );
307
308 // Term text.
309 $this->field_map[] = array(
310 'from_tablename' => 'tag',
311 'from_fieldname' => 'tag_text',
312 'to_type' => 'tags',
313 'to_fieldname' => 'name'
314 );
315
316 // Term slug.
317 $this->field_map[] = array(
318 'from_tablename' => 'tag',
319 'from_fieldname' => 'tag_url',
320 'to_type' => 'tags',
321 'to_fieldname' => 'slug',
322 'callback_method' => 'callback_slug'
323 );
324
325 /** Reply Section *****************************************************/
326
327 // Old reply id (Stored in postmeta)
328 $this->field_map[] = array(
329 'from_tablename' => 'forum_post',
330 'from_fieldname' => 'post_id',
331 'to_type' => 'reply',
332 'to_fieldname' => '_bbp_old_reply_id'
333 );
334
335 // Reply parent forum id (If no parent, then 0. Stored in postmeta)
336 $this->field_map[] = array(
337 'from_tablename' => 'forum_thread',
338 'from_fieldname' => 'forum_id',
339 'join_tablename' => 'forum_post',
340 'join_type' => 'LEFT',
341 'join_expression' => 'USING (thread_id)',
342 'to_type' => 'reply',
343 'to_fieldname' => '_bbp_forum_id',
344 'callback_method' => 'callback_topicid_to_forumid'
345 );
346
347 // Reply parent topic id (If no parent, then 0. Stored in postmeta)
348 $this->field_map[] = array(
349 'from_tablename' => 'forum_post',
350 'from_fieldname' => 'thread_id',
351 'to_type' => 'reply',
352 'to_fieldname' => '_bbp_topic_id',
353 'callback_method' => 'callback_topicid'
354 );
355
356 // Reply author.
357 $this->field_map[] = array(
358 'from_tablename' => 'forum_post',
359 'from_fieldname' => 'user_id',
360 'to_type' => 'reply',
361 'to_fieldname' => 'post_author',
362 'callback_method' => 'callback_userid'
363 );
364
365 // Reply content.
366 // Note: We join the 'forum_post_text' table because 'forum_post' table does not include content.
367 // Note: We can use 'text' for original text OR 'text_parsed' for pre-parsed text output
368 $this->field_map[] = array(
369 'from_tablename' => 'forum_post_text',
370 'from_fieldname' => 'text_parsed',
371 'join_tablename' => 'forum_post',
372 'join_type' => 'LEFT',
373 'join_expression' => 'ON forum_post_text.post_id = forum_post.post_id WHERE forum_thread.start_id != forum_post.post_id',
374 'to_type' => 'reply',
375 'to_fieldname' => 'post_content',
376 'callback_method' => 'callback_html'
377 );
378
379 // Reply parent topic id (If no parent, then 0)
380 $this->field_map[] = array(
381 'from_tablename' => 'forum_post',
382 'from_fieldname' => 'thread_id',
383 'to_type' => 'reply',
384 'to_fieldname' => 'post_parent',
385 'callback_method' => 'callback_topicid'
386 );
387
388 // Reply dates.
389 $this->field_map[] = array(
390 'from_tablename' => 'forum_post',
391 'from_fieldname' => 'time_stamp',
392 'to_type' => 'reply',
393 'to_fieldname' => 'post_date',
394 'callback_method' => 'callback_datetime'
395 );
396 $this->field_map[] = array(
397 'from_tablename' => 'forum_post',
398 'from_fieldname' => 'time_stamp',
399 'to_type' => 'reply',
400 'to_fieldname' => 'post_date_gmt',
401 'callback_method' => 'callback_datetime'
402 );
403 $this->field_map[] = array(
404 'from_tablename' => 'forum_post',
405 'from_fieldname' => 'time_stamp',
406 'to_type' => 'reply',
407 'to_fieldname' => 'post_modified',
408 'callback_method' => 'callback_datetime'
409 );
410 $this->field_map[] = array(
411 'from_tablename' => 'forum_post',
412 'from_fieldname' => 'time_stamp',
413 'to_type' => 'reply',
414 'to_fieldname' => 'post_modified_gmt',
415 'callback_method' => 'callback_datetime'
416 );
417
418 /** User Section ******************************************************/
419
420 // Store old user id (Stored in usermeta)
421 $this->field_map[] = array(
422 'from_tablename' => 'user',
423 'from_fieldname' => 'user_id',
424 'to_type' => 'user',
425 'to_fieldname' => '_bbp_old_user_id'
426 );
427
428 // Store old user password (Stored in usermeta serialized with salt)
429 $this->field_map[] = array(
430 'from_tablename' => 'user',
431 'from_fieldname' => 'password',
432 'to_type' => 'user',
433 'to_fieldname' => '_bbp_password',
434 'callback_method' => 'callback_savepass'
435 );
436
437 // Store old user salt (This is only used for the SELECT row info for the above password save)
438 $this->field_map[] = array(
439 'from_tablename' => 'user',
440 'from_fieldname' => 'password_salt',
441 'to_type' => 'user',
442 'to_fieldname' => ''
443 );
444
445 // User password verify class (Stored in usermeta for verifying password)
446 $this->field_map[] = array(
447 'to_type' => 'user',
448 'to_fieldname' => '_bbp_class',
449 'default' => 'PHPFox3'
450 );
451
452 // User name.
453 $this->field_map[] = array(
454 'from_tablename' => 'user',
455 'from_fieldname' => 'user_name',
456 'to_type' => 'user',
457 'to_fieldname' => 'user_login'
458 );
459
460 // User nice name.
461 $this->field_map[] = array(
462 'from_tablename' => 'user',
463 'from_fieldname' => 'user_name',
464 'to_type' => 'user',
465 'to_fieldname' => 'user_nicename'
466 );
467
468 // User email.
469 $this->field_map[] = array(
470 'from_tablename' => 'user',
471 'from_fieldname' => 'email',
472 'to_type' => 'user',
473 'to_fieldname' => 'user_email'
474 );
475
476 // User registered.
477 $this->field_map[] = array(
478 'from_tablename' => 'user',
479 'from_fieldname' => 'joined',
480 'to_type' => 'user',
481 'to_fieldname' => 'user_registered',
482 'callback_method' => 'callback_datetime'
483 );
484
485 // User display name.
486 $this->field_map[] = array(
487 'from_tablename' => 'user',
488 'from_fieldname' => 'full_name',
489 'to_type' => 'user',
490 'to_fieldname' => 'display_name'
491 );
492 }
493
494 /**
495 * This method allows us to indicates what is or is not converted for each
496 * converter.
497 */
498 public function info() {
499 return '';
500 }
501
502 /**
503 * This method is to save the salt and password together. That
504 * way when we authenticate it we can get it out of the database
505 * as one value. Array values are auto sanitized by WordPress.
506 */
507 public function callback_savepass( $field, $row ) {
508 $pass_array = array(
509 'hash' => $field,
510 'salt' => $row['salt']
511 );
512
513 return $pass_array;
514 }
515
516 /**
517 * This method is to take the pass out of the database and compare
518 * to a pass the user has typed in.
519 */
520 public function authenticate_pass( $password, $serialized_pass ) {
521
522 // Unserialize the password, with safeguards
523 $pass_array = unserialize(
524 $serialized_pass,
525 array(
526 'allowed_classes' => false,
527 'max_depth' => 1,
528 )
529 );
530
531 // Bail if missing values
532 if ( ! is_array( $pass_array ) || ! isset( $pass_array['hash'], $pass_array['salt'] ) ) {
533 return false;
534 }
535
536 // Return comparison
537 return hash_equals(
538 $pass_array['hash'],
539 md5( md5( $password ) . $pass_array['salt'] )
540 );
541 }
542
543 /**
544 * Translate the forum type from PHPFox v3.5.x numerics to WordPress's strings.
545 *
546 * @param int $status PHPFox v3.5.x numeric forum type
547 * @return string WordPress safe
548 */
549 public function callback_forum_type( $status = 0 ) {
550 switch ( $status ) {
551 case 1 :
552 $status = 'category';
553 break;
554
555 case 0 :
556 default :
557 $status = 'forum';
558 break;
559 }
560 return $status;
561 }
562
563 /**
564 * Translate the forum status from PHPFox v3.5.x numerics to WordPress's strings.
565 *
566 * @param int $status PHPFox v3.5.x numeric forum status
567 * @return string WordPress safe
568 */
569 public function callback_forum_status( $status = 0 ) {
570 switch ( $status ) {
571 case 1 :
572 $status = 'closed';
573 break;
574
575 case 0 :
576 default :
577 $status = 'open';
578 break;
579 }
580 return $status;
581 }
582
583 /**
584 * Translate the post status from PHPFox v3.5.x numerics to WordPress's strings.
585 *
586 * @param int $status PHPFox v3.5.x numeric topic status
587 * @return string WordPress safe
588 */
589 public function callback_topic_status( $status = 0 ) {
590 switch ( $status ) {
591 case 1 :
592 $status = 'closed';
593 break;
594
595 case 0 :
596 default :
597 $status = 'publish';
598 break;
599 }
600 return $status;
601 }
602
603 /**
604 * Translate the topic sticky status type from PHPFox v3.5.x numerics to WordPress's strings.
605 *
606 * @param int $status PHPFox v3.5.x numeric forum type
607 * @return string WordPress safe
608 */
609 public function callback_sticky_status( $status = 0 ) {
610 switch ( $status ) {
611 case 1 :
612 $status = 'sticky'; // PHPFox Sticky 'topic_sticky = 1'
613 break;
614
615 case 0 :
616 default :
617 $status = 'normal'; // PHPFox Normal Topic 'topic_sticky = 0'
618 break;
619 }
620 return $status;
621 }
622
623 /**
624 * Verify the topic/reply count.
625 *
626 * @param int $count PHPFox v3.5.x topic/reply counts
627 * @return string WordPress safe
628 */
629 public function callback_topic_reply_count( $count = 1 ) {
630 $count = absint( (int) $count - 1 );
631 return $count;
632 }
633 }
634