PluginProbe
bbPress / 2.6.17
bbPress v2.6.17
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 2.2 2.2.1 All 72 releases
bbpress / includes / admin / converters / Vanilla.php

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

609 lines 16.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 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 (r4717)
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 );
477
478 // User name.
479 $this->field_map[] = array(
480 'from_tablename' => 'User',
481 'from_fieldname' => 'Name',
482 'to_type' => 'user',
483 'to_fieldname' => 'user_login'
484 );
485
486 // User nice name.
487 $this->field_map[] = array(
488 'from_tablename' => 'User',
489 'from_fieldname' => 'Name',
490 'to_type' => 'user',
491 'to_fieldname' => 'user_nicename'
492 );
493
494 // User email.
495 $this->field_map[] = array(
496 'from_tablename' => 'User',
497 'from_fieldname' => 'Email',
498 'to_type' => 'user',
499 'to_fieldname' => 'user_email'
500 );
501
502 // User registered.
503 $this->field_map[] = array(
504 'from_tablename' => 'User',
505 'from_fieldname' => 'DateInserted',
506 'to_type' => 'user',
507 'to_fieldname' => 'user_registered'
508 );
509
510 // Display Name
511 $this->field_map[] = array(
512 'from_tablename' => 'User',
513 'from_fieldname' => 'Name',
514 'to_type' => 'user',
515 'to_fieldname' => 'display_name'
516 );
517 }
518
519 /**
520 * This method allows us to indicates what is or is not converted for each
521 * converter.
522 */
523 public function info() {
524 return '';
525 }
526
527 /**
528 * Translate the topic status from Vanilla v2.x numerics to WordPress's strings.
529 *
530 * @param int $status Vanilla v2.x numeric topic status
531 * @return string WordPress safe
532 */
533 public function callback_topic_status( $status = 0 ) {
534 switch ( $status ) {
535 case 1 :
536 $status = 'closed';
537 break;
538
539 case 0 :
540 default :
541 $status = 'publish';
542 break;
543 }
544 return $status;
545 }
546
547 /**
548 * Translate the topic sticky status type from Vanilla v2.x numerics to WordPress's strings.
549 *
550 * @param int $status Vanilla v2.x numeric forum type
551 * @return string WordPress safe
552 */
553 public function callback_sticky_status( $status = 0 ) {
554 switch ( $status ) {
555 case 1 :
556 $status = 'sticky'; // Vanilla Sticky 'Announce = 1'
557 break;
558
559 case 0 :
560 default :
561 $status = 'normal'; // Vanilla normal topic 'Announce = 0'
562 break;
563 }
564 return $status;
565 }
566
567 /**
568 * Clean Root Parent ID -1 to 0
569 *
570 * @param int $parent Vanilla v2.x Parent ID
571 * @return int
572 */
573 public function callback_forum_parent( $parent_id = 0 ) {
574 if ( -1 === (int) $parent_id ) {
575 return 0;
576 } else {
577 return $parent_id;
578 }
579 }
580
581 /**
582 * Verify the topic reply count.
583 *
584 * @param int $count Vanilla v2.x reply count
585 * @return string WordPress safe
586 */
587 public function callback_topic_reply_count( $count = 1 ) {
588 $count = absint( (int) $count - 1 );
589 return $count;
590 }
591
592 /**
593 * This method is to save the salt and password together. That
594 * way when we authenticate it we can get it out of the database
595 * as one value. Array values are auto sanitized by WordPress.
596 */
597 public function callback_savepass( $field, $row ) {
598 return false;
599 }
600
601 /**
602 * This method is to take the pass out of the database and compare
603 * to a pass the user has typed in.
604 */
605 public function authenticate_pass( $password, $serialized_pass ) {
606 return false;
607 }
608 }
609