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

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

668 lines 19.7 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)
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 * Store the old password hash as an array. Array values are auto
478 * sanitized by WordPress.
479 */
480 public function callback_savepass( $field, $row ) {
481 return array( 'hash' => $field );
482 }
483
484 /**
485 * This method is to take the pass out of the database and compare
486 * to a pass the user has typed in.
487 */
488 public function authenticate_pass( $password, $serialized_pass ) {
489
490 // Unserialize the password, with safeguards
491 $pass_array = $this->unserialize_pass( $serialized_pass );
492
493 // Bail if missing or invalid values
494 if ( ! is_string( $password ) || ! is_array( $pass_array ) || ! isset( $pass_array['hash'] ) || ! is_string( $pass_array['hash'] ) ) {
495 return false;
496 }
497
498 // Standard e107 v1 password comparison
499 if ( hash_equals( $pass_array['hash'], md5( $password ) ) ) {
500 return true;
501 }
502
503 // e107 also converted UTF-8 passwords for upgraded legacy sites
504 if ( function_exists( 'mb_convert_encoding' ) && function_exists( 'mb_substitute_character' ) ) {
505 $substitute_character = mb_substitute_character();
506
507 if ( false === $substitute_character || ! mb_substitute_character( 0x3F ) ) {
508 return false;
509 }
510
511 try {
512 $legacy_password = mb_convert_encoding( $password, 'ISO-8859-1', 'UTF-8' );
513 } finally {
514 mb_substitute_character( $substitute_character );
515 }
516
517 return hash_equals( $pass_array['hash'], md5( $legacy_password ) );
518 }
519
520 return false;
521 }
522
523 /**
524 * Translate the forum type from e107 v1.x numerics to WordPress's strings.
525 *
526 * @param int $status e107 v1.x numeric forum type
527 * @return string WordPress safe
528 */
529 public function callback_forum_type( $status = 0 ) {
530 if ( empty( $status ) ) {
531 $status = 'category';
532 } else {
533 $status = 'forum';
534 }
535 return $status;
536 }
537
538 /**
539 * Translate the post status from e107 v1.x numerics to WordPress's strings.
540 *
541 * @param int $status e107 v1.x numeric topic status
542 * @return string WordPress safe
543 */
544 public function callback_topic_status( $status = 1 ) {
545 switch ( $status ) {
546 case 0 :
547 $status = 'closed';
548 break;
549
550 case 1 :
551 default :
552 $status = 'publish';
553 break;
554 }
555 return $status;
556 }
557
558 /**
559 * Translate the topic sticky status type from e107 v1.x numerics to WordPress's strings.
560 *
561 * @param int $status e107 v1.x numeric forum type
562 * @return string WordPress safe
563 */
564 public function callback_sticky_status( $status = 0 ) {
565 switch ( $status ) {
566 case 2 :
567 $status = 'super-sticky'; // e107 Announcement Sticky 'thread_s = 2'
568 break;
569
570 case 1 :
571 $status = 'sticky'; // e107 Sticky 'thread_s = 1'
572 break;
573
574 case 0 :
575 default :
576 $status = 'normal'; // e107 normal topic 'thread_s = 0'
577 break;
578 }
579 return $status;
580 }
581
582 /**
583 * Verify the topic/reply count.
584 *
585 * @param int $count e107 v1.x topic/reply counts
586 * @return string WordPress safe
587 */
588 public function callback_topic_reply_count( $count = 1 ) {
589 $count = absint( (int) $count - 1 );
590 return $count;
591 }
592
593 /**
594 * Override the `callback_user` function in 'converter.php' for custom e107v1 imports
595 *
596 * A mini cache system to reduce database calls to user ID's
597 *
598 * @param string $field
599 * @return string
600 */
601 protected function callback_e107v1_userid( $field ) {
602
603 // Strip only the user id from the topic and reply authors
604 $field = preg_replace( '/(\d+?)+\.[\S\s]+/', '$1', $field );
605
606 if ( ! isset( $this->map_userid[ $field ] ) ) {
607
608 // phpcs:disable
609 if ( ! empty( $this->sync_table ) ) {
610 $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 ) );
611 } else {
612 $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 ) );
613 }
614 // phpcs:enable
615
616 if ( ! is_null( $row ) ) {
617 $this->map_userid[ $field ] = $row->value_id;
618 } elseif ( true === $this->convert_users ) {
619 $this->map_userid[ $field ] = 0;
620 } else {
621 $this->map_userid[ $field ] = $field;
622 }
623 }
624
625 return $this->map_userid[ $field ];
626 }
627
628 /**
629 * This callback processes any custom parser.php attributes and custom code with preg_replace
630 */
631 protected function callback_html( $field ) {
632
633 // Strips custom e107v1 'magic_url' and 'bbcode_uid' first from $field before parsing $field to parser.php
634 $e107v1_markup = $field;
635 $e107v1_markup = html_entity_decode( $e107v1_markup );
636
637 // Replace '[blockquote]' with '<blockquote>'
638 $e107v1_markup = preg_replace( '/\[blockquote\]/', '<blockquote>', $e107v1_markup );
639 // Replace '[/blockquote]' with '</blockquote>'
640 $e107v1_markup = preg_replace( '/\[\/blockquote\]/', '</blockquote>', $e107v1_markup );
641
642 // Replace '[quote$1=$2]' with '<em>$2 wrote:</em><blockquote>"
643 $e107v1_markup = preg_replace( '/\[quote(.*?)=(.*?)\]/', '<em>@$2 wrote:</em><blockquote>', $e107v1_markup );
644 // Replace '[/quote$1]' with '</blockquote>"
645 $e107v1_markup = preg_replace( '/\[\/quote(.*?)\]/', '</blockquote>', $e107v1_markup );
646
647 // Remove '[justify]'
648 $e107v1_markup = preg_replace( '/\[justify\]/', '', $e107v1_markup );
649 // Remove '[/justify]'
650 $e107v1_markup = preg_replace( '/\[\/justify\]/', '', $e107v1_markup );
651
652 // Replace '[link=(https|http)://$2]$3[/link]' with '<a href="$1://$2">$3</a>'
653 $e107v1_markup = preg_replace( '/\[link\=(https|http)\:\/\/(.*?)\](.*?)\[\/link\]/i', '<a href="$1://$2">$3</a>', $e107v1_markup );
654
655 // Replace '[list=(decimal|lower-roman|upper-roman|lower-alpha|upper-alpha)]' with '[list]'
656 $e107v1_markup = preg_replace( '/\[list\=(decimal|lower-roman|upper-roman|lower-alpha|upper-alpha)\]/i', '[list]', $e107v1_markup );
657
658 // Replace '[youtube]$1[/youtube]' with '$1"
659 $e107v1_markup = preg_replace( '/\[youtube\](.*?)\[\/youtube\]/', 'https://youtu.be/$1', $e107v1_markup );
660
661 // Now that e107v1 custom HTML has been stripped put the cleaned HTML back in $field
662 $field = $e107v1_markup;
663
664 // Parse out any bbCodes in $field with the BBCode 'parser.php'
665 return parent::callback_html( $field );
666 }
667 }
668