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

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

652 lines 19.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Invision Converter
5 *
6 * @package bbPress
7 * @subpackage Converters
8 */
9
10 /**
11 * Implementation of Invision Power Board v3.x converter.
12 *
13 * @since 2.3.0 bbPress (r4713)
14 *
15 * @link Codex Docs https://codex.bbpress.org/import-forums/invision
16 */
17 class Invision extends BBP_Converter_Base {
18
19 /**
20 * Sets up the field mappings
21 */
22 public function setup_globals() {
23
24 // Setup smiley URL & path
25 $this->bbcode_parser_properties = array(
26 'smiley_url' => false,
27 'smiley_dir' => false
28 );
29
30 /** Forum Section *****************************************************/
31
32 // Old forum id (Stored in postmeta)
33 $this->field_map[] = array(
34 'from_tablename' => 'forums',
35 'from_fieldname' => 'id',
36 'to_type' => 'forum',
37 'to_fieldname' => '_bbp_old_forum_id'
38 );
39
40 // Forum parent id (If no parent, then 0, Stored in postmeta)
41 $this->field_map[] = array(
42 'from_tablename' => 'forums',
43 'from_fieldname' => 'parent_id',
44 'to_type' => 'forum',
45 'to_fieldname' => '_bbp_old_forum_parent_id'
46 );
47
48 // Forum topic count (Stored in postmeta)
49 $this->field_map[] = array(
50 'from_tablename' => 'forums',
51 'from_fieldname' => 'topics',
52 'to_type' => 'forum',
53 'to_fieldname' => '_bbp_topic_count'
54 );
55
56 // Forum reply count (Stored in postmeta)
57 $this->field_map[] = array(
58 'from_tablename' => 'forums',
59 'from_fieldname' => 'posts',
60 'to_type' => 'forum',
61 'to_fieldname' => '_bbp_reply_count'
62 );
63
64 // Forum total topic count (Stored in postmeta)
65 $this->field_map[] = array(
66 'from_tablename' => 'forums',
67 'from_fieldname' => 'topics',
68 'to_type' => 'forum',
69 'to_fieldname' => '_bbp_total_topic_count'
70 );
71
72 // Forum total reply count (Stored in postmeta)
73 $this->field_map[] = array(
74 'from_tablename' => 'forums',
75 'from_fieldname' => 'posts',
76 'to_type' => 'forum',
77 'to_fieldname' => '_bbp_total_reply_count'
78 );
79
80 // Forum title.
81 $this->field_map[] = array(
82 'from_tablename' => 'forums',
83 'from_fieldname' => 'name',
84 'to_type' => 'forum',
85 'to_fieldname' => 'post_title'
86 );
87
88 // Forum slug (Clean name to avoid conflicts)
89 $this->field_map[] = array(
90 'from_tablename' => 'forums',
91 'from_fieldname' => 'name_seo',
92 'to_type' => 'forum',
93 'to_fieldname' => 'post_name',
94 'callback_method' => 'callback_slug'
95 );
96
97 // Forum description.
98 $this->field_map[] = array(
99 'from_tablename' => 'forums',
100 'from_fieldname' => 'description',
101 'to_type' => 'forum',
102 'to_fieldname' => 'post_content',
103 'callback_method' => 'callback_null'
104 );
105
106 // Forum display order (Starts from 1)
107 $this->field_map[] = array(
108 'from_tablename' => 'forums',
109 'from_fieldname' => 'position',
110 'to_type' => 'forum',
111 'to_fieldname' => 'menu_order'
112 );
113
114 // Forum type (Forum = 0 or Category = -1, Stored in postmeta)
115 $this->field_map[] = array(
116 'from_tablename' => 'forums',
117 'from_fieldname' => 'parent_id',
118 'to_type' => 'forum',
119 'to_fieldname' => '_bbp_forum_type',
120 'callback_method' => 'callback_forum_type'
121 );
122
123 // Forum status (Set a default value 'open', Stored in postmeta)
124 $this->field_map[] = array(
125 'to_type' => 'forum',
126 'to_fieldname' => '_bbp_status',
127 'default' => 'open'
128 );
129
130 // Forum dates.
131 $this->field_map[] = array(
132 'to_type' => 'forum',
133 'to_fieldname' => 'post_date',
134 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore
135 );
136 $this->field_map[] = array(
137 'to_type' => 'forum',
138 'to_fieldname' => 'post_date_gmt',
139 'default' => gmdate( 'Y-m-d H:i:s' )
140 );
141 $this->field_map[] = array(
142 'to_type' => 'forum',
143 'to_fieldname' => 'post_modified',
144 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore
145 );
146 $this->field_map[] = array(
147 'to_type' => 'forum',
148 'to_fieldname' => 'post_modified_gmt',
149 'default' => gmdate( 'Y-m-d H:i:s' )
150 );
151
152 /** Topic Section *****************************************************/
153
154 // Old topic id (Stored in postmeta)
155 $this->field_map[] = array(
156 'from_tablename' => 'topics',
157 'from_fieldname' => 'tid',
158 'to_type' => 'topic',
159 'to_fieldname' => '_bbp_old_topic_id'
160 );
161
162 // Topic reply count (Stored in postmeta)
163 $this->field_map[] = array(
164 'from_tablename' => 'topics',
165 'from_fieldname' => 'posts',
166 'to_type' => 'topic',
167 'to_fieldname' => '_bbp_reply_count',
168 'callback_method' => 'callback_topic_reply_count'
169 );
170
171 // Topic parent forum id (If no parent, then 0. Stored in postmeta)
172 $this->field_map[] = array(
173 'from_tablename' => 'topics',
174 'from_fieldname' => 'forum_id',
175 'to_type' => 'topic',
176 'to_fieldname' => '_bbp_forum_id',
177 'callback_method' => 'callback_forumid'
178 );
179
180 // Topic author.
181 $this->field_map[] = array(
182 'from_tablename' => 'topics',
183 'from_fieldname' => 'starter_id',
184 'to_type' => 'topic',
185 'to_fieldname' => 'post_author',
186 'callback_method' => 'callback_userid'
187 );
188
189 // Topic content.
190 // Note: We join the posts table because topics do not have content.
191 $this->field_map[] = array(
192 'from_tablename' => 'posts',
193 'from_fieldname' => 'post',
194 'join_tablename' => 'topics',
195 'join_type' => 'INNER',
196 'join_expression' => 'ON(topics.tid = posts.topic_id) WHERE posts.new_topic = 1',
197 'to_type' => 'topic',
198 'to_fieldname' => 'post_content',
199 'callback_method' => 'callback_html'
200 );
201
202 // Topic title.
203 $this->field_map[] = array(
204 'from_tablename' => 'topics',
205 'from_fieldname' => 'title',
206 'to_type' => 'topic',
207 'to_fieldname' => 'post_title'
208 );
209
210 // Topic slug (Clean name to avoid conflicts)
211 $this->field_map[] = array(
212 'from_tablename' => 'topics',
213 'from_fieldname' => 'title',
214 'to_type' => 'topic',
215 'to_fieldname' => 'post_name',
216 'callback_method' => 'callback_slug'
217 );
218
219 // Topic parent forum id (If no parent, then 0)
220 $this->field_map[] = array(
221 'from_tablename' => 'topics',
222 'from_fieldname' => 'forum_id',
223 'to_type' => 'topic',
224 'to_fieldname' => 'post_parent',
225 'callback_method' => 'callback_forumid'
226 );
227
228 // Sticky status (Stored in postmeta)
229 $this->field_map[] = array(
230 'from_tablename' => 'topics',
231 'from_fieldname' => 'pinned',
232 'to_type' => 'topic',
233 'to_fieldname' => '_bbp_old_sticky_status_id',
234 'callback_method' => 'callback_sticky_status'
235 );
236
237 // Topic dates.
238 $this->field_map[] = array(
239 'from_tablename' => 'topics',
240 'from_fieldname' => 'start_date',
241 'to_type' => 'topic',
242 'to_fieldname' => 'post_date',
243 'callback_method' => 'callback_datetime'
244 );
245 $this->field_map[] = array(
246 'from_tablename' => 'topics',
247 'from_fieldname' => 'start_date',
248 'to_type' => 'topic',
249 'to_fieldname' => 'post_date_gmt',
250 'callback_method' => 'callback_datetime'
251 );
252 $this->field_map[] = array(
253 'from_tablename' => 'topics',
254 'from_fieldname' => 'last_post',
255 'to_type' => 'topic',
256 'to_fieldname' => 'post_modified',
257 'callback_method' => 'callback_datetime'
258 );
259 $this->field_map[] = array(
260 'from_tablename' => 'topics',
261 'from_fieldname' => 'last_post',
262 'to_type' => 'topic',
263 'to_fieldname' => 'post_modified_gmt',
264 'callback_method' => 'callback_datetime'
265 );
266 $this->field_map[] = array(
267 'from_tablename' => 'topics',
268 'from_fieldname' => 'last_post',
269 'to_type' => 'topic',
270 'to_fieldname' => '_bbp_last_active_time',
271 'callback_method' => 'callback_datetime'
272 );
273
274 /** Tags Section ******************************************************/
275
276 // Topic id.
277 $this->field_map[] = array(
278 'from_tablename' => 'core_tags',
279 'from_fieldname' => 'tag_meta_id',
280 'to_type' => 'tags',
281 'to_fieldname' => 'objectid',
282 'callback_method' => 'callback_topicid'
283 );
284
285 // Term text.
286 $this->field_map[] = array(
287 'from_tablename' => 'core_tags',
288 'from_fieldname' => 'tag_text',
289 'to_type' => 'tags',
290 'to_fieldname' => 'name'
291 );
292
293 /** Reply Section *****************************************************/
294
295 // Old reply id (Stored in postmeta)
296 $this->field_map[] = array(
297 'from_tablename' => 'posts',
298 'from_fieldname' => 'pid',
299 'to_type' => 'reply',
300 'to_fieldname' => '_bbp_old_reply_id'
301 );
302
303 // Reply parent forum id (If no parent, then 0. Stored in postmeta)
304 $this->field_map[] = array(
305 'from_tablename' => 'posts',
306 'from_fieldname' => 'topic_id',
307 'to_type' => 'reply',
308 'to_fieldname' => '_bbp_forum_id',
309 'callback_method' => 'callback_topicid_to_forumid'
310 );
311
312 // Reply parent topic id (If no parent, then 0. Stored in postmeta)
313 $this->field_map[] = array(
314 'from_tablename' => 'posts',
315 'from_fieldname' => 'topic_id',
316 'to_type' => 'reply',
317 'to_fieldname' => '_bbp_topic_id',
318 'callback_method' => 'callback_topicid'
319 );
320
321 // Reply author ip (Stored in postmeta)
322 $this->field_map[] = array(
323 'from_tablename' => 'posts',
324 'from_fieldname' => 'ip_address',
325 'to_type' => 'reply',
326 'to_fieldname' => '_bbp_author_ip'
327 );
328
329 // Reply author.
330 $this->field_map[] = array(
331 'from_tablename' => 'posts',
332 'from_fieldname' => 'author_id',
333 'to_type' => 'reply',
334 'to_fieldname' => 'post_author',
335 'callback_method' => 'callback_userid'
336 );
337
338 // Reply content.
339 $this->field_map[] = array(
340 'from_tablename' => 'posts',
341 'from_fieldname' => 'post',
342 'to_type' => 'reply',
343 'to_fieldname' => 'post_content',
344 'callback_method' => 'callback_html'
345 );
346
347 // Reply parent topic id (If no parent, then 0)
348 $this->field_map[] = array(
349 'from_tablename' => 'posts',
350 'from_fieldname' => 'topic_id',
351 'to_type' => 'reply',
352 'to_fieldname' => 'post_parent',
353 'callback_method' => 'callback_topicid'
354 );
355
356 // Reply dates.
357 $this->field_map[] = array(
358 'from_tablename' => 'posts',
359 'from_fieldname' => 'post_date',
360 'to_type' => 'reply',
361 'to_fieldname' => 'post_date',
362 'callback_method' => 'callback_datetime'
363 );
364 $this->field_map[] = array(
365 'from_tablename' => 'posts',
366 'from_fieldname' => 'post_date',
367 'to_type' => 'reply',
368 'to_fieldname' => 'post_date_gmt',
369 'callback_method' => 'callback_datetime'
370 );
371 $this->field_map[] = array(
372 'from_tablename' => 'posts',
373 'from_fieldname' => 'edit_time',
374 'to_type' => 'reply',
375 'to_fieldname' => 'post_modified',
376 'callback_method' => 'callback_datetime'
377 );
378 $this->field_map[] = array(
379 'from_tablename' => 'posts',
380 'from_fieldname' => 'edit_time',
381 'to_type' => 'reply',
382 'to_fieldname' => 'post_modified_gmt',
383 'callback_method' => 'callback_datetime'
384 );
385
386 /** User Section ******************************************************/
387
388 // Store old user id (Stored in usermeta)
389 $this->field_map[] = array(
390 'from_tablename' => 'members',
391 'from_fieldname' => 'member_id',
392 'to_type' => 'user',
393 'to_fieldname' => '_bbp_old_user_id'
394 );
395
396 // Store old user password (Stored in usermeta serialized with salt)
397 $this->field_map[] = array(
398 'from_tablename' => 'members',
399 'from_fieldname' => 'members_pass_hash',
400 'to_type' => 'user',
401 'to_fieldname' => '_bbp_password',
402 'callback_method' => 'callback_savepass'
403 );
404
405 // Store old user salt (This is only used for the SELECT row info for the above password save)
406 $this->field_map[] = array(
407 'from_tablename' => 'members',
408 'from_fieldname' => 'members_pass_salt',
409 'to_type' => 'user',
410 'to_fieldname' => ''
411 );
412
413 // User password verify class (Stored in usermeta for verifying password)
414 $this->field_map[] = array(
415 'to_type' => 'user',
416 'to_fieldname' => '_bbp_class',
417 'default' => 'Invision'
418 );
419
420 // User name.
421 $this->field_map[] = array(
422 'from_tablename' => 'members',
423 'from_fieldname' => 'name',
424 'to_type' => 'user',
425 'to_fieldname' => 'user_login'
426 );
427
428 // User nice name.
429 $this->field_map[] = array(
430 'from_tablename' => 'members',
431 'from_fieldname' => 'name',
432 'to_type' => 'user',
433 'to_fieldname' => 'user_nicename'
434 );
435
436 // User email.
437 $this->field_map[] = array(
438 'from_tablename' => 'members',
439 'from_fieldname' => 'email',
440 'to_type' => 'user',
441 'to_fieldname' => 'user_email'
442 );
443
444 // User registered.
445 $this->field_map[] = array(
446 'from_tablename' => 'members',
447 'from_fieldname' => 'joined',
448 'to_type' => 'user',
449 'to_fieldname' => 'user_registered',
450 'callback_method' => 'callback_datetime'
451 );
452
453 // User display name.
454 $this->field_map[] = array(
455 'from_tablename' => 'members',
456 'from_fieldname' => 'members_display_name',
457 'to_type' => 'user',
458 'to_fieldname' => 'display_name'
459 );
460 }
461
462 /**
463 * This method allows us to indicates what is or is not converted for each
464 * converter.
465 */
466 public function info() {
467 return '';
468 }
469
470 /**
471 * Translate the forum type from Invision numerics to WordPress's strings.
472 *
473 * @param int $status Invision numeric forum type
474 * @return string WordPress safe
475 */
476 public function callback_forum_type( $status = 0 ) {
477 if ( -1 === (int) $status ) {
478 $status = 'category';
479 } else {
480 $status = 'forum';
481 }
482 return $status;
483 }
484
485 /**
486 * Translate the topic sticky status type from Invision numerics to WordPress's strings.
487 *
488 * @param int $status Invision numeric forum type
489 * @return string WordPress safe
490 */
491 public function callback_sticky_status( $status = 0 ) {
492 switch ( $status ) {
493 case 1 :
494 $status = 'sticky'; // Invision Pinned Topic 'pinned = 1'
495 break;
496
497 case 0 :
498 default :
499 $status = 'normal'; // Invision Normal Topic 'pinned = 0'
500 break;
501 }
502 return $status;
503 }
504
505 /**
506 * Verify the topic reply count.
507 *
508 * @param int $count Invision reply count
509 * @return string WordPress safe
510 */
511 public function callback_topic_reply_count( $count = 1 ) {
512 $count = absint( (int) $count - 1 );
513 return $count;
514 }
515
516 /**
517 * This method is to save the salt and password together. That
518 * way when we authenticate it we can get it out of the database
519 * as one value. Array values are auto sanitized by WordPress.
520 */
521 public function callback_savepass( $field, $row ) {
522 return array(
523 'hash' => $field,
524 'salt' => $row['members_pass_salt']
525 );
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( $pass_array['salt'] ) . md5( $this->to_char( $password ) ) )
552 );
553 }
554
555 private function to_char( $input ) {
556 $output = '';
557 $length = strlen( $input );
558 for ( $i = 0; $i < $length; $i++ ) {
559 $j = ord( $input[ $i ] );
560 if ( ( $j >= 65 && $j <= 90 )
561 || ( $j >= 97 && $j <= 122 )
562 || ( $j >= 48 && $j <= 57 ) ) {
563 $output .= $input[ $i ];
564 } else {
565 $output .= '&#' . ord( $input[ $i ] ) . ';';
566 }
567 }
568 return $output;
569 }
570
571 /**
572 * This callback processes any custom BBCodes with parser.php
573 */
574 protected function callback_html( $field ) {
575
576 // Strips Invision custom HTML first from $field before parsing $field to parser.php
577 $invision_markup = $field;
578 $invision_markup = html_entity_decode( $invision_markup );
579
580 // Replace '[html]' with '<pre><code>'
581 $invision_markup = preg_replace( '/\[html\]/', '<pre><code>', $invision_markup );
582 // Replace '[/html]' with '</code></pre>'
583 $invision_markup = preg_replace( '/\[\/html\]/', '</code></pre>', $invision_markup );
584 // Replace '[sql]' with '<pre><code>'
585 $invision_markup = preg_replace( '/\[sql\]/', '<pre><code>', $invision_markup );
586 // Replace '[/sql]' with '</code></pre>'
587 $invision_markup = preg_replace( '/\[\/sql\]/', '</code></pre>', $invision_markup );
588 // Replace '[php]' with '<pre><code>'
589 $invision_markup = preg_replace( '/\[php\]/', '<pre><code>', $invision_markup );
590 // Replace '[/php]' with '</code></pre>'
591 $invision_markup = preg_replace( '/\[\/php\]/', '</code></pre>', $invision_markup );
592 // Replace '[xml]' with '<pre><code>'
593 $invision_markup = preg_replace( '/\[xml\]/', '<pre><code>', $invision_markup );
594 // Replace '[/xml]' with '</code></pre>'
595 $invision_markup = preg_replace( '/\[\/xml\]/', '</code></pre>', $invision_markup );
596 // Replace '[CODE]' with '<pre><code>'
597 $invision_markup = preg_replace( '/\[CODE\]/', '<pre><code>', $invision_markup );
598 // Replace '[/CODE]' with '</code></pre>'
599 $invision_markup = preg_replace( '/\[\/CODE\]/', '</code></pre>', $invision_markup );
600
601 // Replace '[quote:XXXXXXX]' with '<blockquote>'
602 $invision_markup = preg_replace( '/\[quote:(.*?)\]/', '<blockquote>', $invision_markup );
603 // Replace '[quote="$1"]' with '<em>@$1 wrote:</em><blockquote>'
604 $invision_markup = preg_replace( '/\[quote="(.*?)":(.*?)\]/', '<em>@$1 wrote:</em><blockquote>', $invision_markup );
605 // Replace '[/quote:XXXXXXX]' with '</blockquote>'
606 $invision_markup = preg_replace( '/\[\/quote:(.*?)\]/', '</blockquote>', $invision_markup );
607
608 // Replace '[twitter]$1[/twitter]' with '<a href="https://twitter.com/$1">@$1</a>"
609 $invision_markup = preg_replace( '/\[twitter\](.*?)\[\/twitter\]/', '<a href="https://twitter.com/$1">@$1</a>', $invision_markup );
610
611 // Replace '[member='username']' with '@username"
612 $invision_markup = preg_replace( '/\[member=\'(.*?)\'\]/', '@$1 ', $invision_markup );
613
614 // Replace '[media]' with ''
615 $invision_markup = preg_replace( '/\[media\]/', '', $invision_markup );
616 // Replace '[/media]' with ''
617 $invision_markup = preg_replace( '/\[\/media\]/', '', $invision_markup );
618
619 // Replace '[list:XXXXXXX]' with '<ul>'
620 $invision_markup = preg_replace( '/\[list\]/', '<ul>', $invision_markup );
621 // Replace '[list=1:XXXXXXX]' with '<ul>'
622 $invision_markup = preg_replace( '/\[list=1\]/', '<ul>', $invision_markup );
623 // Replace '[*:XXXXXXX]' with '<li>'
624 $invision_markup = preg_replace( '/\[\*\](.*?)\<br \/\>/', '<li>$1</li>', $invision_markup );
625 // Replace '[/list:u:XXXXXXX]' with '</ul>'
626 $invision_markup = preg_replace( '/\[\/list\]/', '</ul>', $invision_markup );
627
628 // Replace '[hr]' with '<hr>"
629 $invision_markup = preg_replace( '/\[hr\]/', '<hr>', $invision_markup );
630
631 // Replace '[font=XXXXXXX]' with ''
632 $invision_markup = preg_replace( '/\[font=(.*?)\]/', '', $invision_markup );
633 // Replace '[/font]' with ''
634 $invision_markup = preg_replace( '/\[\/font\]/', '', $invision_markup );
635
636 // Replace any Invision smilies from path '/sp-resources/forum-smileys/sf-smily.gif' with the equivelant WordPress Smilie
637 $invision_markup = preg_replace( '/\<img src=(.*?)EMO\_DIR(.*?)bbc_emoticon(.*?)alt=\'(.*?)\' \/\>/', '$4', $invision_markup );
638 $invision_markup = preg_replace( '/\:angry\:/', ':mad:', $invision_markup );
639 $invision_markup = preg_replace( '/\:mellow\:/', ':neutral:', $invision_markup );
640 $invision_markup = preg_replace( '/\:blink\:/', ':eek:', $invision_markup );
641 $invision_markup = preg_replace( '/B\)/', ':cool:', $invision_markup );
642 $invision_markup = preg_replace( '/\:rolleyes\:/', ':roll:', $invision_markup );
643 $invision_markup = preg_replace( '/\:unsure\:/', ':???:', $invision_markup );
644
645 // Now that Invision custom HTML has been stripped put the cleaned HTML back in $field
646 $field = $invision_markup;
647
648 // Parse out any bbCodes in $field with the BBCode 'parser.php'
649 return parent::callback_html( $field );
650 }
651 }
652