PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.5.0
Forumax – AI Powered Advanced Community Forum Plugin v2.5.0
2.5.0 2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 All 30 releases
bbp-core / lib / bbpress / includes / admin / converters / PHPFox3.php

PHPFox3.php in Forumax – AI Powered Advanced Community Forum Plugin 2.5.0, at lib/bbpress/includes/admin/converters/PHPFox3.php

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