PluginProbe
bbPress / 2.6.18
bbPress v2.6.18
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 / XenForo.php

XenForo.php in bbPress 2.6.18, at includes/admin/converters/XenForo.php

880 lines 26.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress XenForo Converter
5 *
6 * @package bbPress
7 * @subpackage Converters
8 */
9
10 /**
11 * Implementation of XenForo converter.
12 *
13 * @since 2.5.0 bbPress (r5145)
14 *
15 * @link Codex Docs https://codex.bbpress.org/import-forums/xenforo
16 */
17 class XenForo 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 // Setup smiley URL & path
33 $this->bbcode_parser_properties = array(
34 'smiley_url' => false,
35 'smiley_dir' => false
36 );
37
38 /** Forum Section *****************************************************/
39
40 // Old forum id (Stored in postmeta)
41 $this->field_map[] = array(
42 'from_tablename' => 'node',
43 'from_fieldname' => 'node_id',
44 'to_type' => 'forum',
45 'to_fieldname' => '_bbp_old_forum_id'
46 );
47
48 // Forum parent id (If no parent, then 0. Stored in postmeta)
49 $this->field_map[] = array(
50 'from_tablename' => 'node',
51 'from_fieldname' => 'parent_node_id',
52 'to_type' => 'forum',
53 'to_fieldname' => '_bbp_old_forum_parent_id'
54 );
55
56 // Forum topic count (Stored in postmeta)
57 // Note: We join the 'forum' table because 'node' does not include topic counts.
58 $this->field_map[] = array(
59 'from_tablename' => 'forum',
60 'from_fieldname' => 'discussion_count',
61 'join_tablename' => 'node',
62 'join_type' => 'LEFT',
63 'join_expression' => 'USING (node_id) WHERE node.node_type_id = "Category" OR node.node_type_id = "Forum" ',
64 'to_type' => 'forum',
65 'to_fieldname' => '_bbp_topic_count'
66 );
67
68 // Forum reply count (Stored in postmeta)
69 // Note: We join the 'forum' table because 'node' does not include reply counts.
70 $this->field_map[] = array(
71 'from_tablename' => 'forum',
72 'from_fieldname' => 'message_count',
73 'join_tablename' => 'node',
74 'join_type' => 'LEFT',
75 'join_expression' => 'USING (node_id) WHERE node.node_type_id = "Category" OR node.node_type_id = "Forum" ',
76 'to_type' => 'forum',
77 'to_fieldname' => '_bbp_reply_count'
78 );
79
80 // Forum total topic count (Includes unpublished topics, Stored in postmeta)
81 // Note: We join the 'forum' table because 'node' does not include topic counts.
82 $this->field_map[] = array(
83 'from_tablename' => 'forum',
84 'from_fieldname' => 'discussion_count',
85 'join_tablename' => 'node',
86 'join_type' => 'LEFT',
87 'join_expression' => 'USING (node_id) WHERE node.node_type_id = "Category" OR node.node_type_id = "Forum" ',
88 'to_type' => 'forum',
89 'to_fieldname' => '_bbp_total_topic_count'
90 );
91
92 // Forum total reply count (Includes unpublished replies, Stored in postmeta)
93 // Note: We join the 'forum' table because 'node' does not include reply counts.
94 $this->field_map[] = array(
95 'from_tablename' => 'forum',
96 'from_fieldname' => 'message_count',
97 'join_tablename' => 'node',
98 'join_type' => 'LEFT',
99 'join_expression' => 'USING (node_id) WHERE node.node_type_id = "Category" OR node.node_type_id = "Forum" ',
100 'to_type' => 'forum',
101 'to_fieldname' => '_bbp_total_reply_count'
102 );
103
104 // Forum title.
105 $this->field_map[] = array(
106 'from_tablename' => 'node',
107 'from_fieldname' => 'title',
108 'to_type' => 'forum',
109 'to_fieldname' => 'post_title'
110 );
111
112 // Forum slug (Clean name to avoid confilcts)
113 // 'node_name' only has slug for explictly named forums
114 $this->field_map[] = array(
115 'from_tablename' => 'node',
116 'from_fieldname' => 'node_name',
117 'to_type' => 'forum',
118 'to_fieldname' => 'post_name',
119 'callback_method' => 'callback_slug'
120 );
121
122 // Forum description.
123 $this->field_map[] = array(
124 'from_tablename' => 'node',
125 'from_fieldname' => 'description',
126 'to_type' => 'forum',
127 'to_fieldname' => 'post_content',
128 'callback_method' => 'callback_null'
129 );
130
131 // Forum display order (Starts from 1)
132 $this->field_map[] = array(
133 'from_tablename' => 'node',
134 'from_fieldname' => 'display_order',
135 'to_type' => 'forum',
136 'to_fieldname' => 'menu_order'
137 );
138
139 // Forum type (Category = Category or Forum = Forum, Stored in postmeta)
140 $this->field_map[] = array(
141 'from_tablename' => 'node',
142 'from_fieldname' => 'node_type_id',
143 'to_type' => 'forum',
144 'to_fieldname' => '_bbp_forum_type',
145 'callback_method' => 'callback_forum_type'
146 );
147
148 // Forum status (Unlocked = 1 or Locked = 0, Stored in postmeta)
149 // Note: We join the 'forum' table because 'node' does not include forum status.
150 $this->field_map[] = array(
151 'from_tablename' => 'forum',
152 'from_fieldname' => 'allow_posting',
153 'join_tablename' => 'node',
154 'join_type' => 'LEFT',
155 'join_expression' => 'USING (node_id) WHERE node.node_type_id = "Category" OR node.node_type_id = "Forum" ',
156 'to_type' => 'forum',
157 'to_fieldname' => '_bbp_status',
158 'callback_method' => 'callback_forum_status'
159 );
160
161 // Forum dates.
162 $this->field_map[] = array(
163 'to_type' => 'forum',
164 'to_fieldname' => 'post_date',
165 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
166 );
167 $this->field_map[] = array(
168 'to_type' => 'forum',
169 'to_fieldname' => 'post_date_gmt',
170 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
171 );
172 $this->field_map[] = array(
173 'to_type' => 'forum',
174 'to_fieldname' => 'post_modified',
175 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
176 );
177 $this->field_map[] = array(
178 'to_type' => 'forum',
179 'to_fieldname' => 'post_modified_gmt',
180 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
181 );
182
183 /** Forum Subscriptions Section ***************************************/
184
185 // Subscribed forum ID (Stored in usermeta)
186 $this->field_map[] = array(
187 'from_tablename' => 'forum_watch',
188 'from_fieldname' => 'node_id',
189 'to_type' => 'forum_subscriptions',
190 'to_fieldname' => '_bbp_forum_subscriptions'
191 );
192
193 // Subscribed user ID (Stored in usermeta)
194 $this->field_map[] = array(
195 'from_tablename' => 'forum_watch',
196 'from_fieldname' => 'user_id',
197 'to_type' => 'forum_subscriptions',
198 'to_fieldname' => 'user_id',
199 'callback_method' => 'callback_userid'
200 );
201
202 /** Topic Section *****************************************************/
203
204 // Old topic id (Stored in postmeta)
205 $this->field_map[] = array(
206 'from_tablename' => 'thread',
207 'from_fieldname' => 'thread_id',
208 'to_type' => 'topic',
209 'to_fieldname' => '_bbp_old_topic_id'
210 );
211
212 // Topic reply count (Stored in postmeta)
213 $this->field_map[] = array(
214 'from_tablename' => 'thread',
215 'from_fieldname' => 'reply_count',
216 'to_type' => 'topic',
217 'to_fieldname' => '_bbp_reply_count',
218 'callback_method' => 'callback_topic_reply_count'
219 );
220
221 // Topic total reply count (Includes unpublished replies, Stored in postmeta)
222 $this->field_map[] = array(
223 'from_tablename' => 'thread',
224 'from_fieldname' => 'reply_count',
225 'to_type' => 'topic',
226 'to_fieldname' => '_bbp_total_reply_count',
227 'callback_method' => 'callback_topic_reply_count'
228 );
229
230 // Topic parent forum id (If no parent, then 0. Stored in postmeta)
231 $this->field_map[] = array(
232 'from_tablename' => 'thread',
233 'from_fieldname' => 'node_id',
234 'to_type' => 'topic',
235 'to_fieldname' => '_bbp_forum_id',
236 'callback_method' => 'callback_forumid'
237 );
238
239 // Topic author.
240 $this->field_map[] = array(
241 'from_tablename' => 'thread',
242 'from_fieldname' => 'user_id',
243 'to_type' => 'topic',
244 'to_fieldname' => 'post_author',
245 'callback_method' => 'callback_userid'
246 );
247
248 // Topic author name (Stored in postmeta as _bbp_anonymous_name)
249 $this->field_map[] = array(
250 'from_tablename' => 'thread',
251 'from_fieldname' => 'username',
252 'to_type' => 'topic',
253 'to_fieldname' => '_bbp_old_topic_author_name_id'
254 );
255
256 // Is the topic anonymous (Stored in postmeta)
257 $this->field_map[] = array(
258 'from_tablename' => 'thread',
259 'from_fieldname' => 'user_id',
260 'to_type' => 'topic',
261 'to_fieldname' => '_bbp_old_is_topic_anonymous_id',
262 'callback_method' => 'callback_check_anonymous'
263 );
264
265 // Topic title.
266 $this->field_map[] = array(
267 'from_tablename' => 'thread',
268 'from_fieldname' => 'title',
269 'to_type' => 'topic',
270 'to_fieldname' => 'post_title'
271 );
272
273 // Topic slug (Clean name to avoid conflicts)
274 $this->field_map[] = array(
275 'from_tablename' => 'thread',
276 'from_fieldname' => 'title',
277 'to_type' => 'topic',
278 'to_fieldname' => 'post_name',
279 'callback_method' => 'callback_slug'
280 );
281
282 // Topic content.
283 // Note: We join the 'post' table because 'thread' table does not include content.
284 $this->field_map[] = array(
285 'from_tablename' => 'post',
286 'from_fieldname' => 'message',
287 'join_tablename' => 'thread',
288 'join_type' => 'INNER',
289 'join_expression' => 'ON thread.first_post_id = post.post_id',
290 'to_type' => 'topic',
291 'to_fieldname' => 'post_content',
292 'callback_method' => 'callback_html'
293 );
294
295 // Topic status (Visible or Deleted)
296 $this->field_map[] = array(
297 'from_tablename' => 'thread',
298 'from_fieldname' => 'discussion_state',
299 'to_type' => 'topic',
300 'to_fieldname' => 'post_status',
301 'callback_method' => 'callback_status'
302 );
303
304 // Topic status (Open = 1 or Closed = 0)
305 $this->field_map[] = array(
306 'from_tablename' => 'thread',
307 'from_fieldname' => 'discussion_open',
308 'to_type' => 'topic',
309 'to_fieldname' => '_bbp_old_closed_status_id',
310 'callback_method' => 'callback_topic_status'
311 );
312
313 // Topic parent forum id (If no parent, then 0)
314 $this->field_map[] = array(
315 'from_tablename' => 'thread',
316 'from_fieldname' => 'node_id',
317 'to_type' => 'topic',
318 'to_fieldname' => 'post_parent',
319 'callback_method' => 'callback_forumid'
320 );
321
322 // Sticky status (Stored in postmeta)
323 $this->field_map[] = array(
324 'from_tablename' => 'thread',
325 'from_fieldname' => 'sticky',
326 'to_type' => 'topic',
327 'to_fieldname' => '_bbp_old_sticky_status_id',
328 'callback_method' => 'callback_sticky_status'
329 );
330
331 // Topic dates.
332 $this->field_map[] = array(
333 'from_tablename' => 'thread',
334 'from_fieldname' => 'post_date',
335 'to_type' => 'topic',
336 'to_fieldname' => 'post_date',
337 'callback_method' => 'callback_datetime'
338 );
339 $this->field_map[] = array(
340 'from_tablename' => 'thread',
341 'from_fieldname' => 'post_date',
342 'to_type' => 'topic',
343 'to_fieldname' => 'post_date_gmt',
344 'callback_method' => 'callback_datetime'
345 );
346 $this->field_map[] = array(
347 'from_tablename' => 'thread',
348 'from_fieldname' => 'last_post_date',
349 'to_type' => 'topic',
350 'to_fieldname' => 'post_modified',
351 'callback_method' => 'callback_datetime'
352 );
353 $this->field_map[] = array(
354 'from_tablename' => 'thread',
355 'from_fieldname' => 'last_post_date',
356 'to_type' => 'topic',
357 'to_fieldname' => 'post_modified_gmt',
358 'callback_method' => 'callback_datetime'
359 );
360 $this->field_map[] = array(
361 'from_tablename' => 'thread',
362 'from_fieldname' => 'last_post_date',
363 'to_type' => 'topic',
364 'to_fieldname' => '_bbp_last_active_time',
365 'callback_method' => 'callback_datetime'
366 );
367
368 /** Tags Section ******************************************************/
369
370 /**
371 * XenForo Forums do not support topic tags out of the box
372 */
373
374 /** Topic Subscriptions Section ***************************************/
375
376 // Subscribed topic ID (Stored in usermeta)
377 $this->field_map[] = array(
378 'from_tablename' => 'thread_watch',
379 'from_fieldname' => 'thread_id',
380 'to_type' => 'topic_subscriptions',
381 'to_fieldname' => '_bbp_subscriptions'
382 );
383
384 // Subscribed user ID (Stored in usermeta)
385 $this->field_map[] = array(
386 'from_tablename' => 'thread_watch',
387 'from_fieldname' => 'user_id',
388 'to_type' => 'topic_subscriptions',
389 'to_fieldname' => 'user_id',
390 'callback_method' => 'callback_userid'
391 );
392
393 /** Reply Section *****************************************************/
394
395 // Old reply id (Stored in postmeta)
396 $this->field_map[] = array(
397 'from_tablename' => 'post',
398 'from_fieldname' => 'post_id',
399 'to_type' => 'reply',
400 'to_fieldname' => '_bbp_old_reply_id'
401 );
402
403 // Join the 'thread' table to exclude topics from being imported as replies
404 $this->field_map[] = array(
405 'from_tablename' => 'thread',
406 'from_fieldname' => 'thread_id',
407 'join_tablename' => 'post',
408 'join_type' => 'LEFT',
409 'join_expression' => 'USING (thread_id) WHERE thread.first_post_id != post.post_id',
410 'to_type' => 'reply'
411 );
412
413 // Reply parent forum id (If no parent, then 0. Stored in postmeta)
414 $this->field_map[] = array(
415 'from_tablename' => 'post',
416 'from_fieldname' => 'thread_id',
417 'to_type' => 'reply',
418 'to_fieldname' => '_bbp_forum_id',
419 'callback_method' => 'callback_topicid_to_forumid'
420 );
421
422 // Reply parent topic id (If no parent, then 0. Stored in postmeta)
423 $this->field_map[] = array(
424 'from_tablename' => 'post',
425 'from_fieldname' => 'thread_id',
426 'to_type' => 'reply',
427 'to_fieldname' => '_bbp_topic_id',
428 'callback_method' => 'callback_topicid'
429 );
430
431 // Reply author.
432 $this->field_map[] = array(
433 'from_tablename' => 'post',
434 'from_fieldname' => 'user_id',
435 'to_type' => 'reply',
436 'to_fieldname' => 'post_author',
437 'callback_method' => 'callback_userid'
438 );
439
440 // Reply status (Visible or Deleted)
441 $this->field_map[] = array(
442 'from_tablename' => 'post',
443 'from_fieldname' => 'message_state',
444 'to_type' => 'reply',
445 'to_fieldname' => 'post_status',
446 'callback_method' => 'callback_status'
447 );
448
449 // Reply author name (Stored in postmeta as _bbp_anonymous_name)
450 $this->field_map[] = array(
451 'from_tablename' => 'post',
452 'from_fieldname' => 'username',
453 'to_type' => 'reply',
454 'to_fieldname' => '_bbp_old_reply_author_name_id'
455 );
456
457 // Is the reply anonymous (Stored in postmeta)
458 $this->field_map[] = array(
459 'from_tablename' => 'post',
460 'from_fieldname' => 'user_id',
461 'to_type' => 'reply',
462 'to_fieldname' => '_bbp_old_is_reply_anonymous_id',
463 'callback_method' => 'callback_check_anonymous'
464 );
465
466 // Reply content.
467 $this->field_map[] = array(
468 'from_tablename' => 'post',
469 'from_fieldname' => 'message',
470 'to_type' => 'reply',
471 'to_fieldname' => 'post_content',
472 'callback_method' => 'callback_html'
473 );
474
475 // Reply parent topic id (If no parent, then 0)
476 $this->field_map[] = array(
477 'from_tablename' => 'post',
478 'from_fieldname' => 'thread_id',
479 'to_type' => 'reply',
480 'to_fieldname' => 'post_parent',
481 'callback_method' => 'callback_topicid'
482 );
483
484 // Reply dates.
485 $this->field_map[] = array(
486 'from_tablename' => 'post',
487 'from_fieldname' => 'post_date',
488 'to_type' => 'reply',
489 'to_fieldname' => 'post_date',
490 'callback_method' => 'callback_datetime'
491 );
492 $this->field_map[] = array(
493 'from_tablename' => 'post',
494 'from_fieldname' => 'post_date',
495 'to_type' => 'reply',
496 'to_fieldname' => 'post_date_gmt',
497 'callback_method' => 'callback_datetime'
498 );
499 $this->field_map[] = array(
500 'from_tablename' => 'post',
501 'from_fieldname' => 'post_date',
502 'to_type' => 'reply',
503 'to_fieldname' => 'post_modified',
504 'callback_method' => 'callback_datetime'
505 );
506 $this->field_map[] = array(
507 'from_tablename' => 'post',
508 'from_fieldname' => 'post_date',
509 'to_type' => 'reply',
510 'to_fieldname' => 'post_modified_gmt',
511 'callback_method' => 'callback_datetime'
512 );
513
514 /** User Section ******************************************************/
515
516 // Store old user id (Stored in usermeta)
517 $this->field_map[] = array(
518 'from_tablename' => 'user',
519 'from_fieldname' => 'user_id',
520 'to_type' => 'user',
521 'to_fieldname' => '_bbp_old_user_id'
522 );
523
524 // Store authentication data (Stored in serialized usermeta)
525 $this->field_map[] = array(
526 'from_tablename' => 'user_authenticate',
527 'from_fieldname' => 'data',
528 'join_tablename' => 'user',
529 'join_type' => 'LEFT',
530 'join_expression' => 'USING (user_id)',
531 'to_type' => 'user',
532 'to_fieldname' => '_bbp_password',
533 'callback_method' => 'callback_savepass'
534 );
535
536 // Authentication scheme (Used by the password callback above)
537 $this->field_map[] = array(
538 'from_tablename' => 'user_authenticate',
539 'from_fieldname' => 'scheme_class',
540 'to_type' => 'user',
541 'to_fieldname' => ''
542 );
543
544 // User password verify class (Stored in usermeta for verifying password)
545 $this->field_map[] = array(
546 'to_type' => 'user',
547 'to_fieldname' => '_bbp_class',
548 'default' => 'XenForo'
549 );
550
551 // User name.
552 $this->field_map[] = array(
553 'from_tablename' => 'user',
554 'from_fieldname' => 'username',
555 'to_type' => 'user',
556 'to_fieldname' => 'user_login'
557 );
558
559 // User email.
560 $this->field_map[] = array(
561 'from_tablename' => 'user',
562 'from_fieldname' => 'email',
563 'to_type' => 'user',
564 'to_fieldname' => 'user_email'
565 );
566
567 // User homepage.
568 // Note: We join the 'user_profile' table because 'user' does not include user homepage.
569 $this->field_map[] = array(
570 'from_tablename' => 'user_profile',
571 'from_fieldname' => 'homepage',
572 'join_tablename' => 'user',
573 'join_type' => 'LEFT',
574 'join_expression' => 'USING (user_id)',
575 'to_type' => 'user',
576 'to_fieldname' => 'user_url'
577 );
578
579 // User registered.
580 $this->field_map[] = array(
581 'from_tablename' => 'user',
582 'from_fieldname' => 'register_date',
583 'to_type' => 'user',
584 'to_fieldname' => 'user_registered',
585 'callback_method' => 'callback_datetime'
586 );
587
588 // User display name.
589 $this->field_map[] = array(
590 'from_tablename' => 'user',
591 'from_fieldname' => 'username',
592 'to_type' => 'user',
593 'to_fieldname' => 'display_name'
594 );
595
596 // Store Custom Title (Stored in usermeta)
597 $this->field_map[] = array(
598 'from_tablename' => 'user',
599 'from_fieldname' => 'custom_title',
600 'to_type' => 'user',
601 'to_fieldname' => '_bbp_xenforo_user_custom_title'
602 );
603
604 // Store Status (Stored in usermeta)
605 // Note: We join the 'user_profile' table because 'user' does not include user custom XenForo field user status.
606 $this->field_map[] = array(
607 'from_tablename' => 'user_profile',
608 'from_fieldname' => 'status',
609 'join_tablename' => 'user',
610 'join_type' => 'LEFT',
611 'join_expression' => 'USING (user_id)',
612 'to_type' => 'user',
613 'to_fieldname' => '_bbp_xenforo_user_status'
614 );
615
616 // Store Signature (Stored in usermeta)
617 // Note: We join the 'user_profile' table because 'user' does not include user custom XenForo field user signature.
618 $this->field_map[] = array(
619 'from_tablename' => 'user_profile',
620 'from_fieldname' => 'signature',
621 'join_tablename' => 'user',
622 'join_type' => 'LEFT',
623 'join_expression' => 'USING (user_id)',
624 'to_fieldname' => '_bbp_xenforo_user_sig',
625 'to_type' => 'user',
626 'callback_method' => 'callback_html'
627 );
628
629 // Store Location (Stored in usermeta)
630 // Note: We join the 'user_profile' table because 'user' does not include user custom XenForo field user location.
631 $this->field_map[] = array(
632 'from_tablename' => 'user_profile',
633 'from_fieldname' => 'location',
634 'join_tablename' => 'user',
635 'join_type' => 'LEFT',
636 'join_expression' => 'USING (user_id)',
637 'to_type' => 'user',
638 'to_fieldname' => '_bbp_xenforo_user_location'
639 );
640
641 // Store Occupation (Stored in usermeta)
642 // Note: We join the 'user_profile' table because 'user' does not include user custom XenForo field user occupation.
643 $this->field_map[] = array(
644 'from_tablename' => 'user_profile',
645 'from_fieldname' => 'occupation',
646 'join_tablename' => 'user',
647 'join_type' => 'LEFT',
648 'join_expression' => 'USING (user_id)',
649 'to_type' => 'user',
650 'to_fieldname' => '_bbp_xenforo_user_occupation'
651 );
652
653 // Store About (Stored in usermeta)
654 // Note: We join the 'user_profile' table because 'user' does not include user custom XenForo field user about.
655 $this->field_map[] = array(
656 'from_tablename' => 'user_profile',
657 'from_fieldname' => 'about',
658 'join_tablename' => 'user',
659 'join_type' => 'LEFT',
660 'join_expression' => 'USING (user_id)',
661 'to_type' => 'user',
662 'to_fieldname' => '_bbp_xenforo_user_about',
663 'callback_method' => 'callback_html'
664 );
665 }
666
667 /**
668 * This method allows us to indicates what is or is not converted for each
669 * converter.
670 */
671 public function info() {
672 return '';
673 }
674
675 /**
676 * Store XenForo's serialized authentication data with its scheme.
677 *
678 * @param string $field Serialized authentication data.
679 * @param array $row Source database row.
680 * @return array|bool Authentication metadata, or false if invalid.
681 */
682 public function callback_savepass( $field, $row ) {
683 $pass_array = $this->unserialize_pass( $field );
684
685 if ( ! is_array( $pass_array ) || ! isset( $pass_array['hash'], $row['scheme_class'] ) || ! is_string( $pass_array['hash'] ) || ! is_string( $row['scheme_class'] ) ) {
686 return false;
687 }
688
689 $pass_array['scheme'] = $row['scheme_class'];
690
691 return wp_slash( $pass_array );
692 }
693
694 /**
695 * Check a password against XenForo authentication metadata.
696 *
697 * @param string $password Password in plain text.
698 * @param string $serialized_pass Serialized authentication metadata.
699 * @return bool Whether the password is correct.
700 */
701 public function authenticate_pass( $password, $serialized_pass ) {
702
703 // Unserialize the password, with safeguards
704 $pass_array = $this->unserialize_pass( $serialized_pass );
705
706 // Bail if missing or invalid values
707 if ( ! is_string( $password ) || ! is_array( $pass_array ) || ! isset( $pass_array['scheme'], $pass_array['hash'] ) || ! is_string( $pass_array['scheme'] ) || ! is_string( $pass_array['hash'] ) ) {
708 return false;
709 }
710
711 // XenForo 1.2 and newer native bcrypt passwords
712 if ( in_array( $pass_array['scheme'], array( 'XenForo_Authentication_Core12', 'XF:Core12' ), true ) ) {
713 return password_verify( $password, $pass_array['hash'] );
714 }
715
716 // Older XenForo native passwords
717 if ( ! in_array( $pass_array['scheme'], array( 'XenForo_Authentication_Core', 'XF:Core' ), true ) || ! isset( $pass_array['hashFunc'], $pass_array['salt'] ) || ! is_string( $pass_array['hashFunc'] ) || ! is_string( $pass_array['salt'] ) ) {
718 return false;
719 }
720
721 switch ( $pass_array['hashFunc'] ) {
722 case 'sha256':
723 return hash_equals(
724 $pass_array['hash'],
725 hash( 'sha256', hash( 'sha256', $password ) . $pass_array['salt'] )
726 );
727 case 'sha1':
728 return hash_equals(
729 $pass_array['hash'],
730 sha1( sha1( $password ) . $pass_array['salt'] )
731 );
732 }
733
734 return false;
735 }
736
737 /**
738 * Translate the forum type from XenForo Capitalised case to WordPress's non-capatilise case strings.
739 *
740 * @param int $status XenForo numeric forum type
741 * @return string WordPress safe
742 */
743 public function callback_forum_type( $status = 1 ) {
744 switch ( $status ) {
745 case 'Category' :
746 $status = 'category';
747 break;
748
749 case 'Forum' :
750 default :
751 $status = 'forum';
752 break;
753 }
754 return $status;
755 }
756
757 /**
758 * Translate the forum status from XenForo numerics to WordPress's strings.
759 *
760 * @param int $status XenForo numeric forum status
761 * @return string WordPress safe
762 */
763 public function callback_forum_status( $status = 1 ) {
764 switch ( $status ) {
765 case 0 :
766 $status = 'closed';
767 break;
768
769 case 1 :
770 default :
771 $status = 'open';
772 break;
773 }
774 return $status;
775 }
776
777 /**
778 * Translate the post status from XenForo to WordPress' strings.
779 *
780 * @param int $status XenForo post status
781 * @return string WordPress safe
782 */
783 public function callback_status( $status = 1 ) {
784 switch ( $status ) {
785 case 'deleted' :
786 $status = 'pending'; // bbp_get_pending_status_id()
787 break;
788
789 case 'visible' :
790 default :
791 $status = 'publish'; // bbp_get_public_status_id()
792 break;
793 }
794 return $status;
795 }
796
797 /**
798 * Translate the topic status from XenForo numerics to WordPress's strings.
799 *
800 * @param int $status XenForo numeric topic status
801 * @return string WordPress safe
802 */
803 public function callback_topic_status( $status = 1 ) {
804 switch ( $status ) {
805 case 0 :
806 $status = 'closed';
807 break;
808
809 case 1 :
810 default :
811 $status = 'publish';
812 break;
813 }
814 return $status;
815 }
816
817 /**
818 * Translate the topic sticky status type from XenForo numerics to WordPress's strings.
819 *
820 * @param int $status XenForo numeric forum type
821 * @return string WordPress safe
822 */
823 public function callback_sticky_status( $status = 0 ) {
824 switch ( $status ) {
825 case 1 :
826 $status = 'sticky'; // XenForo Sticky 'sticky = 1'
827 break;
828
829 case 0 :
830 default :
831 $status = 'normal'; // XenForo Normal Topic 'sticky = 0'
832 break;
833 }
834 return $status;
835 }
836
837 /**
838 * Verify the topic reply count.
839 *
840 * @param int $count XenForo reply count
841 * @return string WordPress safe
842 */
843 public function callback_topic_reply_count( $count = 1 ) {
844 $count = absint( (int) $count - 1 );
845 return $count;
846 }
847
848 /**
849 * This callback processes any custom parser.php attributes and custom code with preg_replace
850 */
851 protected function callback_html( $field ) {
852
853 // Strips Xenforo custom HTML first from $field before parsing $field to parser.php
854 $xenforo_markup = $field;
855 $xenforo_markup = html_entity_decode( $xenforo_markup );
856
857 // Replace '[QUOTE]' with '<blockquote>'
858 $xenforo_markup = preg_replace( '/\[QUOTE\]/', '<blockquote>', $xenforo_markup );
859 // Replace '[/QUOTE]' with '</blockquote>'
860 $xenforo_markup = preg_replace( '/\[\/QUOTE\]/', '</blockquote>', $xenforo_markup );
861 // Replace '[QUOTE=User Name($1)]' with '<em>@$1 wrote:</em><blockquote>"
862 $xenforo_markup = preg_replace( '/\[quote=\"(.*?)\,\spost\:\s(.*?)\,\s\member\:\s(.*?)\"\](.*?)\[\/quote\]/', '<em>@$1 wrote:</em><blockquote>', $xenforo_markup );
863 // Replace '[/quote]' with '</blockquote>'
864 $xenforo_markup = preg_replace( '/\[\/quote\]/', '</blockquote>', $xenforo_markup );
865
866 // Replace '[media=youtube]$1[/media]' with '$1"
867 $xenforo_markup = preg_replace( '/\[media\=youtube\](.*?)\[\/media\]/', 'https://youtu.be/$1', $xenforo_markup );
868 // Replace '[media=dailymotion]$1[/media]' with '$1"
869 $xenforo_markup = preg_replace( '/\[media\=dailymotion\](.*?)\[\/media\]/', 'https://www.dailymotion.com/video/$1', $xenforo_markup );
870 // Replace '[media=vimeo]$1[/media]' with '$1"
871 $xenforo_markup = preg_replace( '/\[media\=vimeo\](.*?)\[\/media\]/', 'https://vimeo.com/$1', $xenforo_markup );
872
873 // Now that Xenforo custom HTML has been stripped put the cleaned HTML back in $field
874 $field = $xenforo_markup;
875
876 // Parse out any bbCodes in $field with the BBCode 'parser.php'
877 return parent::callback_html( $field );
878 }
879 }
880