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

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

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