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

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

685 lines 18.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Vanilla Converter
5 *
6 * @package bbPress
7 * @subpackage Converters
8 */
9
10 /**
11 * Implementation of Vanilla 2.0.18.1 Converter
12 *
13 * @since 2.3.0 bbPress (r4718)
14 *
15 * @link Codex Docs https://codex.bbpress.org/import-forums/vanilla
16 */
17 class Vanilla 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' => 'Category',
43 'from_fieldname' => 'CategoryID',
44 'from_expression' => 'WHERE Category.CategoryID > 0',
45 'to_type' => 'forum',
46 'to_fieldname' => '_bbp_old_forum_id'
47 );
48
49 // Forum parent id (If no parent, then 0. Stored in postmeta)
50 $this->field_map[] = array(
51 'from_tablename' => 'Category',
52 'from_fieldname' => 'ParentCategoryID',
53 'to_type' => 'forum',
54 'to_fieldname' => '_bbp_old_forum_parent_id',
55 'callback_method' => 'callback_forum_parent'
56 );
57
58 // Forum topic count (Stored in postmeta)
59 $this->field_map[] = array(
60 'from_tablename' => 'Category',
61 'from_fieldname' => 'CountDiscussions',
62 'to_type' => 'forum',
63 'to_fieldname' => '_bbp_topic_count'
64 );
65
66 // Forum reply count (Stored in postmeta)
67 $this->field_map[] = array(
68 'from_tablename' => 'Category',
69 'from_fieldname' => 'CountComments',
70 'to_type' => 'forum',
71 'to_fieldname' => '_bbp_reply_count'
72 );
73
74 // Forum total topic count (Stored in postmeta)
75 $this->field_map[] = array(
76 'from_tablename' => 'Category',
77 'from_fieldname' => 'CountDiscussions',
78 'to_type' => 'forum',
79 'to_fieldname' => '_bbp_total_topic_count'
80 );
81
82 // Forum total reply count (Stored in postmeta)
83 $this->field_map[] = array(
84 'from_tablename' => 'Category',
85 'from_fieldname' => 'CountComments',
86 'to_type' => 'forum',
87 'to_fieldname' => '_bbp_total_reply_count'
88 );
89
90 // Forum title.
91 $this->field_map[] = array(
92 'from_tablename' => 'Category',
93 'from_fieldname' => 'Name',
94 'to_type' => 'forum',
95 'to_fieldname' => 'post_title'
96 );
97
98 // Forum slug (Clean name to avoid confilcts)
99 $this->field_map[] = array(
100 'from_tablename' => 'Category',
101 'from_fieldname' => 'Name',
102 'to_type' => 'forum',
103 'to_fieldname' => 'post_name',
104 'callback_method' => 'callback_slug'
105 );
106
107 // Forum description.
108 $this->field_map[] = array(
109 'from_tablename' => 'Category',
110 'from_fieldname' => 'Description',
111 'to_type' => 'forum',
112 'to_fieldname' => 'post_content',
113 'callback_method' => 'callback_null'
114 );
115
116 // Forum display order (Starts from 1)
117 $this->field_map[] = array(
118 'from_tablename' => 'Category',
119 'from_fieldname' => 'Sort',
120 'to_type' => 'forum',
121 'to_fieldname' => 'menu_order'
122 );
123
124 // Forum type (Set a default value 'forum', Stored in postmeta)
125 $this->field_map[] = array(
126 'to_type' => 'forum',
127 'to_fieldname' => '_bbp_forum_type',
128 'default' => 'forum'
129 );
130
131 // Forum status (Set a default value 'open', Stored in postmeta)
132 $this->field_map[] = array(
133 'to_type' => 'forum',
134 'to_fieldname' => '_bbp_status',
135 'default' => 'open'
136 );
137
138 // Forum dates.
139 $this->field_map[] = array(
140 'from_tablename' => 'Category',
141 'from_fieldname' => 'DateInserted',
142 'to_type' => 'forum',
143 'to_fieldname' => 'post_date',
144 );
145 $this->field_map[] = array(
146 'from_tablename' => 'Category',
147 'from_fieldname' => 'DateInserted',
148 'to_type' => 'forum',
149 'to_fieldname' => 'post_date_gmt',
150 );
151 $this->field_map[] = array(
152 'from_tablename' => 'Category',
153 'from_fieldname' => 'DateUpdated',
154 'to_type' => 'forum',
155 'to_fieldname' => 'post_modified',
156 );
157 $this->field_map[] = array(
158 'from_tablename' => 'Category',
159 'from_fieldname' => 'DateUpdated',
160 'to_type' => 'forum',
161 'to_fieldname' => 'post_modified_gmt',
162 );
163
164 /** Topic Section *****************************************************/
165
166 // Old topic id (Stored in postmeta)
167 // Don't import Vanilla 2's deleted topics
168 $this->field_map[] = array(
169 'from_tablename' => 'Discussion',
170 'from_fieldname' => 'DiscussionID',
171 'from_expression' => 'WHERE Format != "Deleted"',
172 'to_type' => 'topic',
173 'to_fieldname' => '_bbp_old_topic_id'
174 );
175
176 // Topic reply count (Stored in postmeta)
177 $this->field_map[] = array(
178 'from_tablename' => 'Discussion',
179 'from_fieldname' => 'CountComments',
180 'to_type' => 'topic',
181 'to_fieldname' => '_bbp_reply_count',
182 'callback_method' => 'callback_topic_reply_count'
183 );
184
185 // Topic total reply count (Includes unpublished replies, Stored in postmeta)
186 $this->field_map[] = array(
187 'from_tablename' => 'Discussion',
188 'from_fieldname' => 'CountComments',
189 'to_type' => 'topic',
190 'to_fieldname' => '_bbp_total_reply_count',
191 'callback_method' => 'callback_topic_reply_count'
192 );
193
194 // Topic parent forum id (If no parent, then 0. Stored in postmeta)
195 $this->field_map[] = array(
196 'from_tablename' => 'Discussion',
197 'from_fieldname' => 'CategoryID',
198 'to_type' => 'topic',
199 'to_fieldname' => '_bbp_forum_id',
200 'callback_method' => 'callback_forumid'
201 );
202
203 // Topic author.
204 $this->field_map[] = array(
205 'from_tablename' => 'Discussion',
206 'from_fieldname' => 'InsertUserID',
207 'to_type' => 'topic',
208 'to_fieldname' => 'post_author',
209 'callback_method' => 'callback_userid'
210 );
211
212 // Topic author name (Stored in postmeta as _bbp_anonymous_name)
213 $this->field_map[] = array(
214 'to_type' => 'topic',
215 'to_fieldname' => '_bbp_old_topic_author_name_id',
216 'default' => 'Anonymous'
217 );
218
219 // Is the topic anonymous (Stored in postmeta)
220 $this->field_map[] = array(
221 'from_tablename' => 'Discussion',
222 'from_fieldname' => 'InsertUserID',
223 'to_type' => 'topic',
224 'to_fieldname' => '_bbp_old_is_topic_anonymous_id',
225 'callback_method' => 'callback_check_anonymous'
226 );
227
228 // Topic title.
229 $this->field_map[] = array(
230 'from_tablename' => 'Discussion',
231 'from_fieldname' => 'Name',
232 'to_type' => 'topic',
233 'to_fieldname' => 'post_title'
234 );
235
236 // Topic slug (Clean name to avoid conflicts)
237 $this->field_map[] = array(
238 'from_tablename' => 'Discussion',
239 'from_fieldname' => 'Name',
240 'to_type' => 'topic',
241 'to_fieldname' => 'post_name',
242 'callback_method' => 'callback_slug'
243 );
244
245 // Topic content.
246 $this->field_map[] = array(
247 'from_tablename' => 'Discussion',
248 'from_fieldname' => 'Body',
249 'to_type' => 'topic',
250 'to_fieldname' => 'post_content',
251 'callback_method' => 'callback_html'
252 );
253
254 // Topic status (Open or Closed)
255 $this->field_map[] = array(
256 'from_tablename' => 'Discussion',
257 'from_fieldname' => 'closed',
258 'to_type' => 'topic',
259 'to_fieldname' => '_bbp_old_closed_status_id',
260 'callback_method' => 'callback_topic_status'
261 );
262
263 // Topic author ip (Stored in postmeta)
264 $this->field_map[] = array(
265 'from_tablename' => 'Discussion',
266 'from_fieldname' => 'InsertIPAddress',
267 'to_type' => 'topic',
268 'to_fieldname' => '_bbp_author_ip'
269 );
270
271 // Topic parent forum id (If no parent, then 0)
272 $this->field_map[] = array(
273 'from_tablename' => 'Discussion',
274 'from_fieldname' => 'CategoryID',
275 'to_type' => 'topic',
276 'to_fieldname' => 'post_parent',
277 'callback_method' => 'callback_forumid'
278 );
279
280 // Sticky status (Stored in postmeta)
281 $this->field_map[] = array(
282 'from_tablename' => 'Discussion',
283 'from_fieldname' => 'Announce',
284 'to_type' => 'topic',
285 'to_fieldname' => '_bbp_old_sticky_status_id',
286 'callback_method' => 'callback_sticky_status'
287 );
288
289 // Topic dates.
290 $this->field_map[] = array(
291 'from_tablename' => 'Discussion',
292 'from_fieldname' => 'DateInserted',
293 'to_type' => 'topic',
294 'to_fieldname' => 'post_date'
295 );
296 $this->field_map[] = array(
297 'from_tablename' => 'Discussion',
298 'from_fieldname' => 'DateInserted',
299 'to_type' => 'topic',
300 'to_fieldname' => 'post_date_gmt'
301 );
302 $this->field_map[] = array(
303 'from_tablename' => 'Discussion',
304 'from_fieldname' => 'DateUpdated',
305 'to_type' => 'topic',
306 'to_fieldname' => 'post_modified'
307 );
308 $this->field_map[] = array(
309 'from_tablename' => 'Discussion',
310 'from_fieldname' => 'DateUpdated',
311 'to_type' => 'topic',
312 'to_fieldname' => 'post_modified_gmt'
313 );
314 $this->field_map[] = array(
315 'from_tablename' => 'Discussion',
316 'from_fieldname' => 'DateLastComment',
317 'to_type' => 'topic',
318 'to_fieldname' => '_bbp_last_active_time'
319 );
320
321 /** Tags Section ******************************************************/
322
323 // Topic id.
324 $this->field_map[] = array(
325 'from_tablename' => 'TagDiscussion',
326 'from_fieldname' => 'DiscussionID',
327 'to_type' => 'tags',
328 'to_fieldname' => 'objectid',
329 'callback_method' => 'callback_topicid'
330 );
331
332 // Taxonomy ID.
333 $this->field_map[] = array(
334 'from_tablename' => 'TagDiscussion',
335 'from_fieldname' => 'TagID',
336 'to_type' => 'tags',
337 'to_fieldname' => 'taxonomy'
338 );
339
340 // Term text.
341 $this->field_map[] = array(
342 'from_tablename' => 'Tag',
343 'from_fieldname' => 'Name',
344 'join_tablename' => 'TagDiscussion',
345 'join_type' => 'INNER',
346 'join_expression' => 'USING (tagid)',
347 'to_type' => 'tags',
348 'to_fieldname' => 'name'
349 );
350
351 /** Reply Section *****************************************************/
352
353 // Old reply id (Stored in postmeta)
354 // Don't import Vanilla 2's deleted replies
355 $this->field_map[] = array(
356 'from_tablename' => 'Comment',
357 'from_fieldname' => 'CommentID',
358 'from_expression' => 'WHERE Format != "Deleted"',
359 'to_type' => 'reply',
360 'to_fieldname' => '_bbp_old_reply_id'
361 );
362
363 // Reply parent topic id (If no parent, then 0. Stored in postmeta)
364 $this->field_map[] = array(
365 'from_tablename' => 'Comment',
366 'from_fieldname' => 'DiscussionID',
367 'to_type' => 'reply',
368 'to_fieldname' => '_bbp_topic_id',
369 'callback_method' => 'callback_topicid'
370 );
371
372 // Reply parent forum id (If no parent, then 0. Stored in postmeta)
373 $this->field_map[] = array(
374 'from_tablename' => 'Comment',
375 'from_fieldname' => 'DiscussionID',
376 'to_type' => 'reply',
377 'to_fieldname' => '_bbp_forum_id',
378 'callback_method' => 'callback_topicid_to_forumid'
379 );
380
381 // Reply author ip (Stored in postmeta)
382 $this->field_map[] = array(
383 'from_tablename' => 'Comment',
384 'from_fieldname' => 'InsertIPAddress',
385 'to_type' => 'reply',
386 'to_fieldname' => '_bbp_author_ip'
387 );
388
389 // Reply author.
390 $this->field_map[] = array(
391 'from_tablename' => 'Comment',
392 'from_fieldname' => 'InsertUserID',
393 'to_type' => 'reply',
394 'to_fieldname' => 'post_author',
395 'callback_method' => 'callback_userid'
396 );
397
398 // Reply author name (Stored in postmeta as _bbp_anonymous_name)
399 $this->field_map[] = array(
400 'to_type' => 'reply',
401 'to_fieldname' => '_bbp_old_reply_author_name_id',
402 'default' => 'Anonymous'
403 );
404
405 // Is the reply anonymous (Stored in postmeta)
406 $this->field_map[] = array(
407 'from_tablename' => 'Comment',
408 'from_fieldname' => 'InsertUserID',
409 'to_type' => 'reply',
410 'to_fieldname' => '_bbp_old_is_reply_anonymous_id',
411 'callback_method' => 'callback_check_anonymous'
412 );
413
414 // Reply content.
415 $this->field_map[] = array(
416 'from_tablename' => 'Comment',
417 'from_fieldname' => 'Body',
418 'to_type' => 'reply',
419 'to_fieldname' => 'post_content',
420 'callback_method' => 'callback_html'
421 );
422
423 // Reply parent topic id (If no parent, then 0)
424 $this->field_map[] = array(
425 'from_tablename' => 'Comment',
426 'from_fieldname' => 'DiscussionID',
427 'to_type' => 'reply',
428 'to_fieldname' => 'post_parent',
429 'callback_method' => 'callback_topicid'
430 );
431
432 // Reply dates.
433 $this->field_map[] = array(
434 'from_tablename' => 'Comment',
435 'from_fieldname' => 'DateInserted',
436 'to_type' => 'reply',
437 'to_fieldname' => 'post_date'
438 );
439 $this->field_map[] = array(
440 'from_tablename' => 'Comment',
441 'from_fieldname' => 'DateInserted',
442 'to_type' => 'reply',
443 'to_fieldname' => 'post_date_gmt'
444 );
445 $this->field_map[] = array(
446 'from_tablename' => 'Comment',
447 'from_fieldname' => 'DateUpdated',
448 'to_type' => 'reply',
449 'to_fieldname' => 'post_modified'
450 );
451 $this->field_map[] = array(
452 'from_tablename' => 'Comment',
453 'from_fieldname' => 'DateUpdated',
454 'to_type' => 'reply',
455 'to_fieldname' => 'post_modified_gmt'
456 );
457
458 /** User Section ******************************************************/
459
460 // Store old user id (Stored in usermeta)
461 // Don't import user Vanilla's deleted users
462 $this->field_map[] = array(
463 'from_tablename' => 'User',
464 'from_fieldname' => 'UserID',
465 'from_expression' => 'WHERE Deleted !=1',
466 'to_type' => 'user',
467 'to_fieldname' => '_bbp_old_user_id'
468 );
469
470 // Store old user password (Stored in usermeta)
471 $this->field_map[] = array(
472 'from_tablename' => 'User',
473 'from_fieldname' => 'Password',
474 'to_type' => 'user',
475 'to_fieldname' => '_bbp_password',
476 'callback_method' => 'callback_savepass'
477 );
478
479 // Password hash method (Used by the password callback above)
480 $this->field_map[] = array(
481 'from_tablename' => 'User',
482 'from_fieldname' => 'HashMethod',
483 'to_type' => 'user',
484 'to_fieldname' => ''
485 );
486
487 // User password verify class (Stored in usermeta for verifying password)
488 $this->field_map[] = array(
489 'to_type' => 'user',
490 'to_fieldname' => '_bbp_class',
491 'default' => 'Vanilla'
492 );
493
494 // User name.
495 $this->field_map[] = array(
496 'from_tablename' => 'User',
497 'from_fieldname' => 'Name',
498 'to_type' => 'user',
499 'to_fieldname' => 'user_login'
500 );
501
502 // User nice name.
503 $this->field_map[] = array(
504 'from_tablename' => 'User',
505 'from_fieldname' => 'Name',
506 'to_type' => 'user',
507 'to_fieldname' => 'user_nicename'
508 );
509
510 // User email.
511 $this->field_map[] = array(
512 'from_tablename' => 'User',
513 'from_fieldname' => 'Email',
514 'to_type' => 'user',
515 'to_fieldname' => 'user_email'
516 );
517
518 // User registered.
519 $this->field_map[] = array(
520 'from_tablename' => 'User',
521 'from_fieldname' => 'DateInserted',
522 'to_type' => 'user',
523 'to_fieldname' => 'user_registered'
524 );
525
526 // Display Name
527 $this->field_map[] = array(
528 'from_tablename' => 'User',
529 'from_fieldname' => 'Name',
530 'to_type' => 'user',
531 'to_fieldname' => 'display_name'
532 );
533 }
534
535 /**
536 * This method allows us to indicates what is or is not converted for each
537 * converter.
538 */
539 public function info() {
540 return '';
541 }
542
543 /**
544 * Translate the topic status from Vanilla v2.x numerics to WordPress's strings.
545 *
546 * @param int $status Vanilla v2.x numeric topic status
547 * @return string WordPress safe
548 */
549 public function callback_topic_status( $status = 0 ) {
550 switch ( $status ) {
551 case 1 :
552 $status = 'closed';
553 break;
554
555 case 0 :
556 default :
557 $status = 'publish';
558 break;
559 }
560 return $status;
561 }
562
563 /**
564 * Translate the topic sticky status type from Vanilla v2.x numerics to WordPress's strings.
565 *
566 * @param int $status Vanilla v2.x numeric forum type
567 * @return string WordPress safe
568 */
569 public function callback_sticky_status( $status = 0 ) {
570 switch ( $status ) {
571 case 1 :
572 $status = 'sticky'; // Vanilla Sticky 'Announce = 1'
573 break;
574
575 case 0 :
576 default :
577 $status = 'normal'; // Vanilla normal topic 'Announce = 0'
578 break;
579 }
580 return $status;
581 }
582
583 /**
584 * Clean Root Parent ID -1 to 0
585 *
586 * @param int $parent Vanilla v2.x Parent ID
587 * @return int
588 */
589 public function callback_forum_parent( $parent_id = 0 ) {
590 if ( -1 === (int) $parent_id ) {
591 return 0;
592 } else {
593 return $parent_id;
594 }
595 }
596
597 /**
598 * Verify the topic reply count.
599 *
600 * @param int $count Vanilla v2.x reply count
601 * @return string WordPress safe
602 */
603 public function callback_topic_reply_count( $count = 1 ) {
604 $count = absint( (int) $count - 1 );
605 return $count;
606 }
607
608 /**
609 * Store Vanilla's password hash with its hash method.
610 *
611 * WordPress unslashes metadata before storage, so pre-slash the source value
612 * to preserve legacy plaintext passwords containing quotes or backslashes.
613 *
614 * @param string $field Password hash or legacy plaintext password.
615 * @param array $row Source database row.
616 * @return array|bool Password metadata, or false if invalid.
617 */
618 public function callback_savepass( $field, $row ) {
619 if ( ! is_string( $field ) ) {
620 return false;
621 }
622
623 $method = isset( $row['HashMethod'] ) && is_string( $row['HashMethod'] )
624 ? $row['HashMethod']
625 : '';
626
627 return wp_slash(
628 array(
629 'hash' => $field,
630 'method' => $method,
631 )
632 );
633 }
634
635 /**
636 * Check a password against Vanilla 2 authentication metadata.
637 *
638 * Vanilla 2.0.18.1 generated portable phpass hashes, while retaining
639 * compatibility with legacy MD5 hashes and plaintext passwords.
640 *
641 * @param string $password Password in plain text.
642 * @param string $serialized_pass Serialized authentication metadata.
643 * @return bool Whether the password is correct.
644 */
645 public function authenticate_pass( $password, $serialized_pass ) {
646
647 // Unserialize the password, with safeguards
648 $pass_array = $this->unserialize_pass( $serialized_pass );
649
650 // Bail if missing or invalid values
651 if ( ! is_string( $password ) || ! is_array( $pass_array ) || ! isset( $pass_array['hash'], $pass_array['method'] ) || ! is_string( $pass_array['hash'] ) || ! is_string( $pass_array['method'] ) ) {
652 return false;
653 }
654
655 // This converter targets Vanilla's native password formats only
656 if ( '' !== $pass_array['method'] && 0 !== strcasecmp( 'Vanilla', $pass_array['method'] ) ) {
657 return false;
658 }
659
660 $hash = $pass_array['hash'];
661
662 if ( '' === $hash || '*' === $hash ) {
663 return false;
664 }
665
666 // Vanilla used phpass for hashes beginning with "$" or "_"
667 if ( '$' === $hash[0] || '_' === $hash[0] ) {
668 require_once ABSPATH . WPINC . '/class-phpass.php';
669
670 $hasher = new PasswordHash( 8, true );
671
672 return $hasher->CheckPassword( $password, $hash );
673 }
674
675 if ( empty( $password ) ) {
676 return false;
677 }
678
679 $plain_matches = hash_equals( $hash, $password );
680 $md5_matches = hash_equals( $hash, md5( $password ) );
681
682 return $plain_matches || $md5_matches;
683 }
684 }
685