PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.0.0
Forumax – AI Powered Advanced Community Forum Plugin v2.0.0
2.5.1 2.5.0 2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 All 31 releases
bbp-core / vendor / bbpress / includes / admin / converters / Invision.php

Invision.php in Forumax – AI Powered Advanced Community Forum Plugin 2.0.0, at vendor/bbpress/includes/admin/converters/Invision.php

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