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

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

662 lines 19.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 e107 1.x Converter
5 *
6 * @package bbPress
7 * @subpackage Converters
8 */
9
10 /**
11 * Implementation of e107 v1.x Forum converter.
12 *
13 * @since 2.6.0 bbPress (r5352)
14 *
15 * @link Codex Docs https://codex.bbpress.org/import-forums/e107
16 */
17 class e107v1 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' => 'forum',
43 'from_fieldname' => 'forum_id',
44 'to_type' => 'forum',
45 'to_fieldname' => '_bbp_old_forum_id'
46 );
47
48 // Forum parent id (If no parent, then 0, Stored in postmeta)
49 $this->field_map[] = array(
50 'from_tablename' => 'forum',
51 'from_fieldname' => 'forum_parent',
52 'to_type' => 'forum',
53 'to_fieldname' => '_bbp_old_forum_parent_id'
54 );
55
56 // Forum topic count (Stored in postmeta)
57 $this->field_map[] = array(
58 'from_tablename' => 'forum',
59 'from_fieldname' => 'forum_threads',
60 'to_type' => 'forum',
61 'to_fieldname' => '_bbp_topic_count'
62 );
63
64 // Forum reply count (Stored in postmeta)
65 $this->field_map[] = array(
66 'from_tablename' => 'forum',
67 'from_fieldname' => 'forum_replies',
68 'to_type' => 'forum',
69 'to_fieldname' => '_bbp_reply_count'
70 );
71
72 // Forum total topic count (Includes unpublished topics, Stored in postmeta)
73 $this->field_map[] = array(
74 'from_tablename' => 'forum',
75 'from_fieldname' => 'forum_threads',
76 'to_type' => 'forum',
77 'to_fieldname' => '_bbp_total_topic_count'
78 );
79
80 // Forum total reply count (Includes unpublished replies, Stored in postmeta)
81 $this->field_map[] = array(
82 'from_tablename' => 'forum',
83 'from_fieldname' => 'forum_replies',
84 'to_type' => 'forum',
85 'to_fieldname' => '_bbp_total_reply_count'
86 );
87
88 // Forum title.
89 $this->field_map[] = array(
90 'from_tablename' => 'forum',
91 'from_fieldname' => 'forum_name',
92 'to_type' => 'forum',
93 'to_fieldname' => 'post_title'
94 );
95
96 // Forum slug (Clean name to avoid conflicts)
97 $this->field_map[] = array(
98 'from_tablename' => 'forum',
99 'from_fieldname' => 'forum_name',
100 'to_type' => 'forum',
101 'to_fieldname' => 'post_name',
102 'callback_method' => 'callback_slug'
103 );
104
105 // Forum description.
106 $this->field_map[] = array(
107 'from_tablename' => 'forum',
108 'from_fieldname' => 'forum_description',
109 'to_type' => 'forum',
110 'to_fieldname' => 'post_content',
111 'callback_method' => 'callback_null'
112 );
113
114 // Forum display order (Starts from 1)
115 $this->field_map[] = array(
116 'from_tablename' => 'forum',
117 'from_fieldname' => 'forum_order',
118 'to_type' => 'forum',
119 'to_fieldname' => 'menu_order'
120 );
121
122 // Forum type (Category = 0 or Forum > 0, Stored in postmeta)
123 $this->field_map[] = array(
124 'from_tablename' => 'forum',
125 'from_fieldname' => 'forum_parent',
126 'to_type' => 'forum',
127 'to_fieldname' => '_bbp_forum_type',
128 'callback_method' => 'callback_forum_type'
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 'to_type' => 'forum',
141 'to_fieldname' => 'post_date',
142 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
143 );
144 $this->field_map[] = array(
145 'to_type' => 'forum',
146 'to_fieldname' => 'post_date_gmt',
147 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
148 );
149 $this->field_map[] = array(
150 'to_type' => 'forum',
151 'to_fieldname' => 'post_modified',
152 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
153 );
154 $this->field_map[] = array(
155 'to_type' => 'forum',
156 'to_fieldname' => 'post_modified_gmt',
157 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
158 );
159
160 /** Topic Section *****************************************************/
161
162 // Old topic id (Stored in postmeta)
163 $this->field_map[] = array(
164 'from_tablename' => 'forum_t',
165 'from_fieldname' => 'thread_id',
166 'from_expression' => 'WHERE thread_parent = 0',
167 'to_type' => 'topic',
168 'to_fieldname' => '_bbp_old_topic_id'
169 );
170
171 // Topic reply count (Stored in postmeta)
172 $this->field_map[] = array(
173 'from_tablename' => 'forum_t',
174 'from_fieldname' => 'thread_total_replies',
175 'to_type' => 'topic',
176 'to_fieldname' => '_bbp_reply_count',
177 'callback_method' => 'callback_topic_reply_count'
178 );
179
180 // Topic total reply count (Includes unpublished replies, Stored in postmeta)
181 $this->field_map[] = array(
182 'from_tablename' => 'forum_t',
183 'from_fieldname' => 'thread_total_replies',
184 'to_type' => 'topic',
185 'to_fieldname' => '_bbp_total_reply_count',
186 'callback_method' => 'callback_topic_reply_count'
187 );
188
189 // Topic parent forum id (If no parent, then 0. Stored in postmeta)
190 $this->field_map[] = array(
191 'from_tablename' => 'forum_t',
192 'from_fieldname' => 'thread_forum_id',
193 'to_type' => 'topic',
194 'to_fieldname' => '_bbp_forum_id',
195 'callback_method' => 'callback_forumid'
196 );
197
198 // Topic author.
199 // Note: Uses a custom callback to transform user id from '1.Administrator e107v1' to numeric user id.
200 $this->field_map[] = array(
201 'from_tablename' => 'forum_t',
202 'from_fieldname' => 'thread_user',
203 'to_type' => 'topic',
204 'to_fieldname' => 'post_author',
205 'callback_method' => 'callback_e107v1_userid'
206 );
207
208 // Topic content.
209 $this->field_map[] = array(
210 'from_tablename' => 'forum_t',
211 'from_fieldname' => 'thread_thread',
212 'to_type' => 'topic',
213 'to_fieldname' => 'post_content',
214 'callback_method' => 'callback_html'
215 );
216
217 // Topic title.
218 $this->field_map[] = array(
219 'from_tablename' => 'forum_t',
220 'from_fieldname' => 'thread_name',
221 'to_type' => 'topic',
222 'to_fieldname' => 'post_title'
223 );
224
225 // Topic slug (Clean name to avoid conflicts)
226 $this->field_map[] = array(
227 'from_tablename' => 'forum_t',
228 'from_fieldname' => 'thread_name',
229 'to_type' => 'topic',
230 'to_fieldname' => 'post_name',
231 'callback_method' => 'callback_slug'
232 );
233
234 // Topic status (Open or Closed, e107 v1.x open = 1 & closed = 0)
235 $this->field_map[] = array(
236 'from_tablename' => 'forum_t',
237 'from_fieldname' => 'thread_active',
238 'to_type' => 'topic',
239 'to_fieldname' => '_bbp_old_closed_status_id',
240 'callback_method' => 'callback_topic_status'
241 );
242
243 // Topic parent forum id (If no parent, then 0)
244 $this->field_map[] = array(
245 'from_tablename' => 'forum_t',
246 'from_fieldname' => 'thread_forum_id',
247 'to_type' => 'topic',
248 'to_fieldname' => 'post_parent',
249 'callback_method' => 'callback_forumid'
250 );
251
252 // Sticky status (Stored in postmeta)
253 $this->field_map[] = array(
254 'from_tablename' => 'forum_t',
255 'from_fieldname' => 'thread_s',
256 'to_type' => 'topic',
257 'to_fieldname' => '_bbp_old_sticky_status_id',
258 'callback_method' => 'callback_sticky_status'
259 );
260
261 // Topic dates.
262 $this->field_map[] = array(
263 'from_tablename' => 'forum_t',
264 'from_fieldname' => 'thread_datestamp',
265 'to_type' => 'topic',
266 'to_fieldname' => 'post_date',
267 'callback_method' => 'callback_datetime'
268 );
269 $this->field_map[] = array(
270 'from_tablename' => 'forum_t',
271 'from_fieldname' => 'thread_datestamp',
272 'to_type' => 'topic',
273 'to_fieldname' => 'post_date_gmt',
274 'callback_method' => 'callback_datetime'
275 );
276 $this->field_map[] = array(
277 'from_tablename' => 'forum_t',
278 'from_fieldname' => 'thread_datestamp',
279 'to_type' => 'topic',
280 'to_fieldname' => 'post_modified',
281 'callback_method' => 'callback_datetime'
282 );
283 $this->field_map[] = array(
284 'from_tablename' => 'forum_t',
285 'from_fieldname' => 'thread_datestamp',
286 'to_type' => 'topic',
287 'to_fieldname' => 'post_modified_gmt',
288 'callback_method' => 'callback_datetime'
289 );
290 $this->field_map[] = array(
291 'from_tablename' => 'forum_t',
292 'from_fieldname' => 'thread_datestamp',
293 'to_type' => 'topic',
294 'to_fieldname' => '_bbp_last_active_time',
295 'callback_method' => 'callback_datetime'
296 );
297
298 /** Tags Section ******************************************************/
299
300 /**
301 * e107 v1.x Forums do not support topic tags out of the box
302 */
303
304 /** Reply Section *****************************************************/
305
306 // Old reply id (Stored in postmeta)
307 $this->field_map[] = array(
308 'from_tablename' => 'forum_t',
309 'from_fieldname' => 'thread_id',
310 'from_expression' => 'WHERE thread_parent != 0',
311 'to_type' => 'reply',
312 'to_fieldname' => '_bbp_old_reply_id'
313 );
314
315 // Reply parent forum id (If no parent, then 0. Stored in postmeta)
316 $this->field_map[] = array(
317 'from_tablename' => 'forum_t',
318 'from_fieldname' => 'thread_forum_id',
319 'to_type' => 'reply',
320 'to_fieldname' => '_bbp_forum_id',
321 'callback_method' => 'callback_topicid_to_forumid'
322 );
323
324 // Reply parent topic id (If no parent, then 0. Stored in postmeta)
325 $this->field_map[] = array(
326 'from_tablename' => 'forum_t',
327 'from_fieldname' => 'thread_parent',
328 'to_type' => 'reply',
329 'to_fieldname' => '_bbp_topic_id',
330 'callback_method' => 'callback_topicid'
331 );
332
333 // Reply author.
334 // Note: Uses a custom callback to transform user id from '1.Administrator e107v1' to numeric user id.
335 $this->field_map[] = array(
336 'from_tablename' => 'forum_t',
337 'from_fieldname' => 'thread_user',
338 'to_type' => 'reply',
339 'to_fieldname' => 'post_author',
340 'callback_method' => 'callback_e107v1_userid'
341 );
342
343 // Reply content.
344 $this->field_map[] = array(
345 'from_tablename' => 'forum_t',
346 'from_fieldname' => 'thread_thread',
347 'to_type' => 'reply',
348 'to_fieldname' => 'post_content',
349 'callback_method' => 'callback_html'
350 );
351
352 // Reply parent topic id (If no parent, then 0)
353 $this->field_map[] = array(
354 'from_tablename' => 'forum_t',
355 'from_fieldname' => 'thread_parent',
356 'to_type' => 'reply',
357 'to_fieldname' => 'post_parent',
358 'callback_method' => 'callback_topicid'
359 );
360
361 // Reply dates.
362 $this->field_map[] = array(
363 'from_tablename' => 'forum_t',
364 'from_fieldname' => 'thread_datestamp',
365 'to_type' => 'reply',
366 'to_fieldname' => 'post_date',
367 'callback_method' => 'callback_datetime'
368 );
369 $this->field_map[] = array(
370 'from_tablename' => 'forum_t',
371 'from_fieldname' => 'thread_datestamp',
372 'to_type' => 'reply',
373 'to_fieldname' => 'post_date_gmt',
374 'callback_method' => 'callback_datetime'
375 );
376 $this->field_map[] = array(
377 'from_tablename' => 'forum_t',
378 'from_fieldname' => 'thread_datestamp',
379 'to_type' => 'reply',
380 'to_fieldname' => 'post_modified',
381 'callback_method' => 'callback_datetime'
382 );
383 $this->field_map[] = array(
384 'from_tablename' => 'forum_t',
385 'from_fieldname' => 'thread_datestamp',
386 'to_type' => 'reply',
387 'to_fieldname' => 'post_modified_gmt',
388 'callback_method' => 'callback_datetime'
389 );
390
391 /** User Section ******************************************************/
392
393 // Store old user id (Stored in usermeta)
394 $this->field_map[] = array(
395 'from_tablename' => 'user',
396 'from_fieldname' => 'user_id',
397 'to_type' => 'user',
398 'to_fieldname' => '_bbp_old_user_id'
399 );
400
401 // Store old user password (Stored in usermeta serialized with salt)
402 $this->field_map[] = array(
403 'from_tablename' => 'user',
404 'from_fieldname' => 'user_password',
405 'to_type' => 'user',
406 'to_fieldname' => '_bbp_password',
407 'callback_method' => 'callback_savepass'
408 );
409
410 // User password verify class (Stored in usermeta for verifying password)
411 $this->field_map[] = array(
412 'to_type' => 'user',
413 'to_fieldname' => '_bbp_class',
414 'default' => 'e107v1'
415 );
416
417 // User name.
418 $this->field_map[] = array(
419 'from_tablename' => 'user',
420 'from_fieldname' => 'user_loginname',
421 'to_type' => 'user',
422 'to_fieldname' => 'user_login'
423 );
424
425 // User nice name.
426 $this->field_map[] = array(
427 'from_tablename' => 'user',
428 'from_fieldname' => 'user_loginname',
429 'to_type' => 'user',
430 'to_fieldname' => 'user_nicename'
431 );
432
433 // User email.
434 $this->field_map[] = array(
435 'from_tablename' => 'user',
436 'from_fieldname' => 'user_email',
437 'to_type' => 'user',
438 'to_fieldname' => 'user_email'
439 );
440
441 // User registered.
442 $this->field_map[] = array(
443 'from_tablename' => 'user',
444 'from_fieldname' => 'user_join',
445 'to_type' => 'user',
446 'to_fieldname' => 'user_registered',
447 'callback_method' => 'callback_datetime'
448 );
449
450 // User display name.
451 $this->field_map[] = array(
452 'from_tablename' => 'user',
453 'from_fieldname' => 'user_name',
454 'to_type' => 'user',
455 'to_fieldname' => 'display_name'
456 );
457
458 // Store Signature (Stored in usermeta)
459 $this->field_map[] = array(
460 'from_tablename' => 'user',
461 'from_fieldname' => 'user_signature',
462 'to_fieldname' => '_bbp_e107v1_user_sig',
463 'to_type' => 'user',
464 'callback_method' => 'callback_html'
465 );
466 }
467
468 /**
469 * This method allows us to indicates what is or is not converted for each
470 * converter.
471 */
472 public function info() {
473 return '';
474 }
475
476 /**
477 * This method is to save the salt and password together. That
478 * way when we authenticate it we can get it out of the database
479 * as one value. Array values are auto sanitized by WordPress.
480 */
481 public function callback_savepass( $field, $row ) {
482 $pass_array = array(
483 'hash' => $field,
484 'salt' => $row['salt']
485 );
486
487 return $pass_array;
488 }
489
490 /**
491 * This method is to take the pass out of the database and compare
492 * to a pass the user has typed in.
493 */
494 public function authenticate_pass( $password, $serialized_pass ) {
495
496 // Unserialize the password, with safeguards
497 $pass_array = unserialize(
498 $serialized_pass,
499 array(
500 'allowed_classes' => false,
501 'max_depth' => 1
502 )
503 );
504
505 // Bail if missing values
506 if ( ! is_array( $pass_array ) || ! isset( $pass_array['hash'], $pass_array['salt'] ) ) {
507 return false;
508 }
509
510 // Return comparison
511 return hash_equals(
512 $pass_array['hash'],
513 md5( md5( $password ) . $pass_array['salt'] )
514 );
515 }
516
517 /**
518 * Translate the forum type from e107 v1.x numerics to WordPress's strings.
519 *
520 * @param int $status e107 v1.x numeric forum type
521 * @return string WordPress safe
522 */
523 public function callback_forum_type( $status = 0 ) {
524 if ( empty( $status ) ) {
525 $status = 'category';
526 } else {
527 $status = 'forum';
528 }
529 return $status;
530 }
531
532 /**
533 * Translate the post status from e107 v1.x numerics to WordPress's strings.
534 *
535 * @param int $status e107 v1.x numeric topic status
536 * @return string WordPress safe
537 */
538 public function callback_topic_status( $status = 1 ) {
539 switch ( $status ) {
540 case 0 :
541 $status = 'closed';
542 break;
543
544 case 1 :
545 default :
546 $status = 'publish';
547 break;
548 }
549 return $status;
550 }
551
552 /**
553 * Translate the topic sticky status type from e107 v1.x numerics to WordPress's strings.
554 *
555 * @param int $status e107 v1.x numeric forum type
556 * @return string WordPress safe
557 */
558 public function callback_sticky_status( $status = 0 ) {
559 switch ( $status ) {
560 case 2 :
561 $status = 'super-sticky'; // e107 Announcement Sticky 'thread_s = 2'
562 break;
563
564 case 1 :
565 $status = 'sticky'; // e107 Sticky 'thread_s = 1'
566 break;
567
568 case 0 :
569 default :
570 $status = 'normal'; // e107 normal topic 'thread_s = 0'
571 break;
572 }
573 return $status;
574 }
575
576 /**
577 * Verify the topic/reply count.
578 *
579 * @param int $count e107 v1.x topic/reply counts
580 * @return string WordPress safe
581 */
582 public function callback_topic_reply_count( $count = 1 ) {
583 $count = absint( (int) $count - 1 );
584 return $count;
585 }
586
587 /**
588 * Override the `callback_user` function in 'converter.php' for custom e107v1 imports
589 *
590 * A mini cache system to reduce database calls to user ID's
591 *
592 * @param string $field
593 * @return string
594 */
595 protected function callback_e107v1_userid( $field ) {
596
597 // Strip only the user id from the topic and reply authors
598 $field = preg_replace( '/(\d+?)+\.[\S\s]+/', '$1', $field );
599
600 if ( ! isset( $this->map_userid[ $field ] ) ) {
601
602 // phpcs:disable
603 if ( ! empty( $this->sync_table ) ) {
604 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_user_id', $field ) );
605 } else {
606 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT user_id AS value_id FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_user_id', $field ) );
607 }
608 // phpcs:enable
609
610 if ( ! is_null( $row ) ) {
611 $this->map_userid[ $field ] = $row->value_id;
612 } elseif ( true === $this->convert_users ) {
613 $this->map_userid[ $field ] = 0;
614 } else {
615 $this->map_userid[ $field ] = $field;
616 }
617 }
618
619 return $this->map_userid[ $field ];
620 }
621
622 /**
623 * This callback processes any custom parser.php attributes and custom code with preg_replace
624 */
625 protected function callback_html( $field ) {
626
627 // Strips custom e107v1 'magic_url' and 'bbcode_uid' first from $field before parsing $field to parser.php
628 $e107v1_markup = $field;
629 $e107v1_markup = html_entity_decode( $e107v1_markup );
630
631 // Replace '[blockquote]' with '<blockquote>'
632 $e107v1_markup = preg_replace( '/\[blockquote\]/', '<blockquote>', $e107v1_markup );
633 // Replace '[/blockquote]' with '</blockquote>'
634 $e107v1_markup = preg_replace( '/\[\/blockquote\]/', '</blockquote>', $e107v1_markup );
635
636 // Replace '[quote$1=$2]' with '<em>$2 wrote:</em><blockquote>"
637 $e107v1_markup = preg_replace( '/\[quote(.*?)=(.*?)\]/', '<em>@$2 wrote:</em><blockquote>', $e107v1_markup );
638 // Replace '[/quote$1]' with '</blockquote>"
639 $e107v1_markup = preg_replace( '/\[\/quote(.*?)\]/', '</blockquote>', $e107v1_markup );
640
641 // Remove '[justify]'
642 $e107v1_markup = preg_replace( '/\[justify\]/', '', $e107v1_markup );
643 // Remove '[/justify]'
644 $e107v1_markup = preg_replace( '/\[\/justify\]/', '', $e107v1_markup );
645
646 // Replace '[link=(https|http)://$2]$3[/link]' with '<a href="$1://$2">$3</a>'
647 $e107v1_markup = preg_replace( '/\[link\=(https|http)\:\/\/(.*?)\](.*?)\[\/link\]/i', '<a href="$1://$2">$3</a>', $e107v1_markup );
648
649 // Replace '[list=(decimal|lower-roman|upper-roman|lower-alpha|upper-alpha)]' with '[list]'
650 $e107v1_markup = preg_replace( '/\[list\=(decimal|lower-roman|upper-roman|lower-alpha|upper-alpha)\]/i', '[list]', $e107v1_markup );
651
652 // Replace '[youtube]$1[/youtube]' with '$1"
653 $e107v1_markup = preg_replace( '/\[youtube\](.*?)\[\/youtube\]/', 'https://youtu.be/$1', $e107v1_markup );
654
655 // Now that e107v1 custom HTML has been stripped put the cleaned HTML back in $field
656 $field = $e107v1_markup;
657
658 // Parse out any bbCodes in $field with the BBCode 'parser.php'
659 return parent::callback_html( $field );
660 }
661 }
662