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

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

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