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

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

701 lines 21.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 (r5143)
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' => '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' => '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' => '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' => '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 (PHPWind v9.x bitmask: 1=locked & 2=closed)
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' => 'windid_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' => 'windid_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' => 'windid_user',
429 'from_fieldname' => 'salt',
430 'to_type' => 'user',
431 'to_fieldname' => ''
432 );
433 // User password verify class (Stored in usermeta for verifying password)
434 $this->field_map[] = array(
435 'to_type' => 'user',
436 'to_fieldname' => '_bbp_class',
437 'default' => 'PHPWind'
438 );
439
440 // User name.
441 $this->field_map[] = array(
442 'from_tablename' => 'windid_user',
443 'from_fieldname' => 'username',
444 'to_type' => 'user',
445 'to_fieldname' => 'user_login'
446 );
447
448 // User nice name.
449 $this->field_map[] = array(
450 'from_tablename' => 'windid_user',
451 'from_fieldname' => 'username',
452 'to_type' => 'user',
453 'to_fieldname' => 'user_nicename'
454 );
455
456 // User email.
457 $this->field_map[] = array(
458 'from_tablename' => 'windid_user',
459 'from_fieldname' => 'email',
460 'to_type' => 'user',
461 'to_fieldname' => 'user_email'
462 );
463
464 // User registered.
465 $this->field_map[] = array(
466 'from_tablename' => 'windid_user',
467 'from_fieldname' => 'regdate',
468 'to_type' => 'user',
469 'to_fieldname' => 'user_registered',
470 'callback_method' => 'callback_datetime'
471 );
472
473 // User display name.
474 $this->field_map[] = array(
475 'from_tablename' => 'windid_user_info',
476 'from_fieldname' => 'realname',
477 'join_tablename' => 'windid_user',
478 'join_type' => 'LEFT',
479 'join_expression' => 'ON windid_user.uid = windid_user_info.uid',
480 'to_type' => 'user',
481 'to_fieldname' => 'display_name'
482 );
483 }
484
485 /**
486 * This method allows us to indicates what is or is not converted for each
487 * converter.
488 */
489 public function info() {
490 return '';
491 }
492
493 /**
494 * Save the salt and password together so both values are available during
495 * authentication. Pre-slash the salt because WordPress removes one layer of
496 * slashes when storing user metadata.
497 */
498 public function callback_savepass( $field, $row ) {
499 $pass_array = array(
500 'hash' => $field,
501 'salt' => wp_slash( isset( $row['salt'] ) ? (string) $row['salt'] : '' )
502 );
503
504 return $pass_array;
505 }
506
507 /**
508 * This method is to take the pass out of the database and compare
509 * to a pass the user has typed in.
510 */
511 public function authenticate_pass( $password, $serialized_pass ) {
512 if ( ! is_string( $password ) || ! is_string( $serialized_pass ) ) {
513 return false;
514 }
515
516 // Unserialize the password, with safeguards
517 $pass_array = $this->unserialize_pass( $serialized_pass );
518
519 // Bail if missing values
520 if ( ! is_array( $pass_array ) || ! isset( $pass_array['hash'], $pass_array['salt'] ) || ! is_string( $pass_array['hash'] ) || ! is_string( $pass_array['salt'] ) ) {
521 return false;
522 }
523
524 // Return comparison
525 return hash_equals(
526 $pass_array['hash'],
527 md5( md5( $password ) . $pass_array['salt'] )
528 );
529 }
530
531 /**
532 * Upgrade password metadata written by earlier PHPWind imports.
533 *
534 * Earlier imports stored PHPWind's random synchronization token instead of
535 * its login hash and salt. New imports use the parent callback and serialized
536 * metadata containing the login hash and salt.
537 *
538 * @param string $username WordPress user login.
539 * @param string $password Unslashed password for PHPWind.
540 * @param string|null $wp_password Optional slashed password for WordPress.
541 */
542 public function callback_pass( $username = '', $password = '', $wp_password = null ) {
543 $user = get_user_by( 'login', $username );
544
545 if ( ! empty( $user ) && '' === $user->user_pass ) {
546 $stored_hash = get_user_meta( $user->ID, '_bbp_password', true );
547
548 if ( is_string( $stored_hash ) && preg_match( '/^[a-f0-9]{32}$/i', $stored_hash ) ) {
549 $serialized_pass = $this->get_source_password( $user, $stored_hash );
550
551 if ( is_string( $serialized_pass ) && $this->authenticate_pass( $password, $serialized_pass ) ) {
552 $this->upgrade_user_pass( $user->ID, is_null( $wp_password ) ? $password : $wp_password );
553 }
554
555 return;
556 }
557 }
558
559 parent::callback_pass( $username, $password, $wp_password );
560 }
561
562 /**
563 * Upgrade a PHPWind hash copied directly into wp_users by an old import.
564 *
565 * Those imports stored PHPWind's random synchronization token, not its login
566 * hash. Match that token against the retained source row before retrieving
567 * the login hash and salt from WindID.
568 *
569 * @param WP_User $user WordPress user.
570 * @param string $password Unslashed password for PHPWind.
571 * @param string|null $wp_password Optional slashed password for WordPress.
572 */
573 public function callback_user_pass( $user, $password, $wp_password = null ) {
574 if ( ! ( $user instanceof WP_User ) || ! is_string( $password ) || ! preg_match( '/^[a-f0-9]{32}$/i', $user->user_pass ) ) {
575 return;
576 }
577
578 $wp_password = is_null( $wp_password ) ? $password : $wp_password;
579
580 // Do not replace a password that WordPress or a password plugin already
581 // recognizes, regardless of the stored hash format.
582 if ( wp_check_password( $wp_password, $user->user_pass, $user->ID ) ) {
583 return;
584 }
585
586 $serialized_pass = $this->get_source_password( $user, $user->user_pass );
587
588 if ( is_string( $serialized_pass ) && $this->authenticate_pass( $password, $serialized_pass ) ) {
589 $this->upgrade_user_pass( $user->ID, $wp_password );
590 }
591 }
592
593 /**
594 * Retrieve login metadata for a token written by an earlier import.
595 *
596 * @param WP_User $user WordPress user.
597 * @param string $stored_hash Random token stored by the earlier import.
598 * @return string|bool Serialized password metadata, or false on failure.
599 */
600 private function get_source_password( $user, $stored_hash ) {
601 $old_user_id = (int) get_user_meta( $user->ID, '_bbp_old_user_id', true );
602 if ( $old_user_id < 1 || get_transient( 'bbp_phpwind_source_connection_failed' ) ) {
603 return false;
604 }
605
606 // Block concurrent login attempts while the source connection or query is pending.
607 // Keep the backoff when either fails, so an unavailable source cannot stall
608 // every login attempt for an imported username.
609 set_transient( 'bbp_phpwind_source_connection_failed', 1, 5 * MINUTE_IN_SECONDS );
610
611 if ( ! $this->opdb->db_connect( false ) ) {
612 return false;
613 }
614
615 $legacy_table = $this->opdb->prefix . 'user';
616 $windid_table = $this->opdb->prefix . 'windid_user';
617 $source_user = $this->opdb->get_row(
618 $this->opdb->prepare( "SELECT legacy.password AS legacy_password, windid.password, windid.salt FROM {$legacy_table} AS legacy INNER JOIN {$windid_table} AS windid ON windid.uid = legacy.uid WHERE legacy.uid = %d LIMIT 1", $old_user_id ),
619 ARRAY_A
620 );
621 if ( empty( $this->opdb->last_error ) ) {
622 delete_transient( 'bbp_phpwind_source_connection_failed' );
623 }
624
625 if ( ! is_array( $source_user ) || ! isset( $source_user['legacy_password'], $source_user['password'], $source_user['salt'] ) || ! is_string( $source_user['legacy_password'] ) || ! is_string( $source_user['password'] ) || ! is_string( $source_user['salt'] ) || ! hash_equals( $stored_hash, $source_user['legacy_password'] ) ) {
626 return false;
627 }
628
629 return serialize(
630 array(
631 'hash' => $source_user['password'],
632 'salt' => $source_user['salt'],
633 )
634 );
635 }
636
637 /**
638 * Replace a verified PHPWind hash with a WordPress password.
639 *
640 * @param int $user_id WordPress user ID.
641 * @param string $password Password to hash for WordPress.
642 */
643 private function upgrade_user_pass( $user_id, $password ) {
644 wp_set_password( $password, $user_id );
645 delete_user_meta( $user_id, '_bbp_password' );
646 delete_user_meta( $user_id, '_bbp_class' );
647 }
648
649 /**
650 * Translate the forum type from PHPWind v9.x Capitalised case to WordPress's non-capatilise case strings.
651 *
652 * @param int $status PHPWind v9.x numeric forum type
653 * @return string WordPress safe
654 */
655 public function callback_forum_type( $status = 1 ) {
656 switch ( $status ) {
657 case 'category' :
658 $status = 'category';
659 break;
660
661 case 'sub' :
662 $status = 'forum';
663 break;
664
665 case 'sub2' :
666 $status = 'forum';
667 break;
668
669 case 'forum' :
670 default :
671 $status = 'forum';
672 break;
673 }
674 return $status;
675 }
676
677 /**
678 * Translate the post status from PHPWind v9.x numerics to WordPress's strings.
679 *
680 * @param int $status PHPWind v9.x numeric topic status
681 * @return string WordPress topic status.
682 */
683 public function callback_topic_status( $status = 0 ) {
684 // PHPWind stores locked (0b0001) and closed (0b0010) flags in tpcstatus. bbPress represents either state as closed.
685 $locked_or_closed_mask = 0b0011;
686
687 return ( (int) $status & $locked_or_closed_mask ) ? 'closed' : 'publish';
688 }
689
690 /**
691 * Verify the topic/reply count.
692 *
693 * @param int $count PHPWind v9.x topic/reply counts
694 * @return int Non-negative reply count.
695 */
696 public function callback_topic_reply_count( $count = 1 ) {
697 $count = absint( $count );
698 return $count;
699 }
700 }
701