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

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

609 lines 18.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress SimplePress5 Converter
5 *
6 * @package bbPress
7 * @subpackage Converters
8 */
9
10 /**
11 * Implementation of SimplePress v5 converter.
12 *
13 * @since 2.3.0 bbPress (r4638)
14 *
15 * @link Codex Docs https://codex.bbpress.org/import-forums/simplepress/
16 */
17 class SimplePress5 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' => 'sfforums',
35 'from_fieldname' => 'forum_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' => 'sfforums',
43 'from_fieldname' => 'parent',
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' => 'sfforums',
51 'from_fieldname' => 'topic_count',
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' => 'sfforums',
59 'from_fieldname' => 'post_count',
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' => 'sfforums',
67 'from_fieldname' => 'topic_count',
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' => 'sfforums',
75 'from_fieldname' => 'post_count',
76 'to_type' => 'forum',
77 'to_fieldname' => '_bbp_total_reply_count'
78 );
79
80 // Forum title.
81 $this->field_map[] = array(
82 'from_tablename' => 'sfforums',
83 'from_fieldname' => 'forum_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' => 'sfforums',
91 'from_fieldname' => 'forum_name',
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' => 'sfforums',
100 'from_fieldname' => 'forum_desc',
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' => 'sfforums',
109 'from_fieldname' => 'forum_seq',
110 'to_type' => 'forum',
111 'to_fieldname' => 'menu_order'
112 );
113
114 // Forum type (Set a default value 'forum', Stored in postmeta)
115 $this->field_map[] = array(
116 'to_type' => 'forum',
117 'to_fieldname' => '_bbp_forum_type',
118 'default' => 'forum'
119 );
120
121 // Forum status (Set a default value 'open', Stored in postmeta)
122 $this->field_map[] = array(
123 'to_type' => 'forum',
124 'to_fieldname' => '_bbp_status',
125 'default' => 'open'
126 );
127
128 // Forum dates.
129 $this->field_map[] = array(
130 'to_type' => 'forums',
131 'to_fieldname' => 'post_date',
132 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore
133 );
134 $this->field_map[] = array(
135 'to_type' => 'forums',
136 'to_fieldname' => 'post_date_gmt',
137 'default' => gmdate( 'Y-m-d H:i:s' )
138 );
139 $this->field_map[] = array(
140 'to_type' => 'forums',
141 'to_fieldname' => 'post_modified',
142 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore
143 );
144 $this->field_map[] = array(
145 'to_type' => 'forums',
146 'to_fieldname' => 'post_modified_gmt',
147 'default' => gmdate( 'Y-m-d H:i:s' )
148 );
149
150 /** Topic Section *****************************************************/
151
152 // Old topic id (Stored in postmeta)
153 $this->field_map[] = array(
154 'from_tablename' => 'sftopics',
155 'from_fieldname' => 'topic_id',
156 'to_type' => 'topic',
157 'to_fieldname' => '_bbp_old_topic_id'
158 );
159
160 // Topic reply count (Stored in postmeta)
161 $this->field_map[] = array(
162 'from_tablename' => 'sftopics',
163 'from_fieldname' => 'post_count',
164 'to_type' => 'topic',
165 'to_fieldname' => '_bbp_reply_count',
166 'callback_method' => 'callback_topic_reply_count'
167 );
168
169 // Topic parent forum id (If no parent, then 0. Stored in postmeta)
170 $this->field_map[] = array(
171 'from_tablename' => 'sftopics',
172 'from_fieldname' => 'forum_id',
173 'to_type' => 'topic',
174 'to_fieldname' => '_bbp_forum_id',
175 'callback_method' => 'callback_forumid'
176 );
177
178 // Topic author.
179 $this->field_map[] = array(
180 'from_tablename' => 'sftopics',
181 'from_fieldname' => 'user_id',
182 'to_type' => 'topic',
183 'to_fieldname' => 'post_author',
184 'callback_method' => 'callback_userid'
185 );
186
187 // Topic author ip (Stored in postmeta)
188 $this->field_map[] = array(
189 'from_tablename' => 'sfposts',
190 'from_fieldname' => 'poster_ip',
191 'join_tablename' => 'sftopics',
192 'join_type' => 'INNER',
193 'join_expression' => 'USING (topic_id) WHERE sfposts.post_index = 1',
194 'to_type' => 'topic',
195 'to_fieldname' => '_bbp_author_ip'
196 );
197
198 // Topic author name (Stored in postmeta as _bbp_anonymous_name)
199 $this->field_map[] = array(
200 'from_tablename' => 'sfposts',
201 'from_fieldname' => 'guest_name',
202 'join_tablename' => 'sftopics',
203 'join_type' => 'INNER',
204 'join_expression' => 'USING (topic_id) WHERE sfposts.post_index = 1',
205 'to_type' => 'topic',
206 'to_fieldname' => '_bbp_old_topic_author_name_id'
207 );
208
209 // Is the topic anonymous (Stored in postmeta)
210 $this->field_map[] = array(
211 'from_tablename' => 'sftopics',
212 'from_fieldname' => 'user_id',
213 'to_type' => 'topic',
214 'to_fieldname' => '_bbp_old_is_topic_anonymous_id',
215 'callback_method' => 'callback_check_anonymous'
216 );
217
218 // Topic content.
219 // Note: We join the sfposts table because sftopics do not have content.
220 $this->field_map[] = array(
221 'from_tablename' => 'sfposts',
222 'from_fieldname' => 'post_content',
223 'join_tablename' => 'sftopics',
224 'join_type' => 'INNER',
225 'join_expression' => 'USING (topic_id) WHERE sfposts.post_index = 1',
226 'to_type' => 'topic',
227 'to_fieldname' => 'post_content',
228 'callback_method' => 'callback_html'
229 );
230
231 // Topic title.
232 $this->field_map[] = array(
233 'from_tablename' => 'sftopics',
234 'from_fieldname' => 'topic_name',
235 'to_type' => 'topic',
236 'to_fieldname' => 'post_title'
237 );
238
239 // Topic slug (Clean name to avoid conflicts)
240 $this->field_map[] = array(
241 'from_tablename' => 'sftopics',
242 'from_fieldname' => 'topic_name',
243 'to_type' => 'topic',
244 'to_fieldname' => 'post_name',
245 'callback_method' => 'callback_slug'
246 );
247
248 // Topic parent forum id (If no parent, then 0)
249 $this->field_map[] = array(
250 'from_tablename' => 'sftopics',
251 'from_fieldname' => 'forum_id',
252 'to_type' => 'topic',
253 'to_fieldname' => 'post_parent',
254 'callback_method' => 'callback_forumid'
255 );
256
257 // Topic status (Open or Closed)
258 $this->field_map[] = array(
259 'from_tablename' => 'sftopics',
260 'from_fieldname' => 'topic_status',
261 'to_type' => 'topic',
262 'to_fieldname' => '_bbp_old_closed_status_id',
263 'callback_method' => 'callback_status'
264 );
265
266 // Sticky status (Stored in postmeta)
267 $this->field_map[] = array(
268 'from_tablename' => 'sftopics',
269 'from_fieldname' => 'topic_pinned',
270 'to_type' => 'topic',
271 'to_fieldname' => '_bbp_old_sticky_status_id',
272 'callback_method' => 'callback_sticky_status'
273 );
274
275 // Topic dates.
276 $this->field_map[] = array(
277 'from_tablename' => 'sftopics',
278 'from_fieldname' => 'topic_date',
279 'to_type' => 'topic',
280 'to_fieldname' => 'post_date'
281 );
282 $this->field_map[] = array(
283 'from_tablename' => 'sftopics',
284 'from_fieldname' => 'topic_date',
285 'to_type' => 'topic',
286 'to_fieldname' => 'post_date_gmt'
287 );
288 $this->field_map[] = array(
289 'from_tablename' => 'sftopics',
290 'from_fieldname' => 'topic_date',
291 'to_type' => 'topic',
292 'to_fieldname' => 'post_modified'
293 );
294 $this->field_map[] = array(
295 'from_tablename' => 'sftopics',
296 'from_fieldname' => 'topic_date',
297 'to_type' => 'topic',
298 'to_fieldname' => 'post_modified_gmt'
299 );
300 $this->field_map[] = array(
301 'from_tablename' => 'sftopics',
302 'from_fieldname' => 'topic_date',
303 'to_type' => 'topic',
304 'to_fieldname' => '_bbp_last_active_time'
305 );
306
307 /** Tags Section ******************************************************/
308
309 /**
310 * SimplePress Forums do not support topic tags without paid extensions
311 */
312
313 /** Reply Section *****************************************************/
314
315 // Old reply id (Stored in postmeta)
316 $this->field_map[] = array(
317 'from_tablename' => 'sfposts',
318 'from_fieldname' => 'post_id',
319 'to_type' => 'reply',
320 'to_fieldname' => '_bbp_old_reply_id'
321 );
322
323 // Reply parent forum id (If no parent, then 0. Stored in postmeta)
324 $this->field_map[] = array(
325 'from_tablename' => 'sfposts',
326 'from_fieldname' => 'forum_id',
327 'from_expression' => 'WHERE post_index != 1',
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' => 'sfposts',
336 'from_fieldname' => 'topic_id',
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' => 'sfposts',
345 'from_fieldname' => 'poster_ip',
346 'to_type' => 'reply',
347 'to_fieldname' => '_bbp_author_ip'
348 );
349
350 // Reply author.
351 $this->field_map[] = array(
352 'from_tablename' => 'sfposts',
353 'from_fieldname' => 'user_id',
354 'to_type' => 'reply',
355 'to_fieldname' => 'post_author',
356 'callback_method' => 'callback_userid'
357 );
358
359 // Reply author name (Stored in postmeta as _bbp_anonymous_name)
360 $this->field_map[] = array(
361 'from_tablename' => 'sfposts',
362 'from_fieldname' => 'guest_name',
363 'to_type' => 'reply',
364 'to_fieldname' => '_bbp_old_reply_author_name_id'
365 );
366
367 // Is the reply anonymous (Stored in postmeta)
368 $this->field_map[] = array(
369 'from_tablename' => 'sfposts',
370 'from_fieldname' => 'user_id',
371 'to_type' => 'reply',
372 'to_fieldname' => '_bbp_old_is_reply_anonymous_id',
373 'callback_method' => 'callback_check_anonymous'
374 );
375
376 // Reply content.
377 $this->field_map[] = array(
378 'from_tablename' => 'sfposts',
379 'from_fieldname' => 'post_content',
380 'to_type' => 'reply',
381 'to_fieldname' => 'post_content',
382 'callback_method' => 'callback_html'
383 );
384
385 // Reply parent topic id (If no parent, then 0)
386 $this->field_map[] = array(
387 'from_tablename' => 'sfposts',
388 'from_fieldname' => 'topic_id',
389 'to_type' => 'reply',
390 'to_fieldname' => 'post_parent',
391 'callback_method' => 'callback_topicid'
392 );
393
394 // Reply dates.
395 $this->field_map[] = array(
396 'from_tablename' => 'sfposts',
397 'from_fieldname' => 'post_date',
398 'to_type' => 'reply',
399 'to_fieldname' => 'post_date'
400 );
401 $this->field_map[] = array(
402 'from_tablename' => 'sfposts',
403 'from_fieldname' => 'post_date',
404 'to_type' => 'reply',
405 'to_fieldname' => 'post_date_gmt'
406 );
407 $this->field_map[] = array(
408 'from_tablename' => 'sfposts',
409 'from_fieldname' => 'post_date',
410 'to_type' => 'reply',
411 'to_fieldname' => 'post_modified'
412 );
413 $this->field_map[] = array(
414 'from_tablename' => 'sfposts',
415 'from_fieldname' => 'post_date',
416 'to_type' => 'reply',
417 'to_fieldname' => 'post_modified_gmt'
418 );
419
420 /** User Section ******************************************************/
421
422 // Store old user id (Stored in usermeta)
423 $this->field_map[] = array(
424 'from_tablename' => 'users',
425 'from_fieldname' => 'ID',
426 'to_type' => 'user',
427 'to_fieldname' => '_bbp_old_user_id'
428 );
429
430 // Store old user password (Stored in usermeta)
431 $this->field_map[] = array(
432 'from_tablename' => 'users',
433 'from_fieldname' => 'user_pass',
434 'to_type' => 'user',
435 'to_fieldname' => '_bbp_password'
436 );
437
438 // User name.
439 $this->field_map[] = array(
440 'from_tablename' => 'users',
441 'from_fieldname' => 'user_login',
442 'to_type' => 'user',
443 'to_fieldname' => 'user_login'
444 );
445
446 // User nice name.
447 $this->field_map[] = array(
448 'from_tablename' => 'users',
449 'from_fieldname' => 'user_nicename',
450 'to_type' => 'user',
451 'to_fieldname' => 'user_nicename'
452 );
453
454 // User email.
455 $this->field_map[] = array(
456 'from_tablename' => 'users',
457 'from_fieldname' => 'user_email',
458 'to_type' => 'user',
459 'to_fieldname' => 'user_email'
460 );
461
462 // User homepage.
463 $this->field_map[] = array(
464 'from_tablename' => 'users',
465 'from_fieldname' => 'user_url',
466 'to_type' => 'user',
467 'to_fieldname' => 'user_url'
468 );
469
470 // User registered.
471 $this->field_map[] = array(
472 'from_tablename' => 'users',
473 'from_fieldname' => 'user_registered',
474 'to_type' => 'user',
475 'to_fieldname' => 'user_registered'
476 );
477
478 // User status.
479 $this->field_map[] = array(
480 'from_tablename' => 'users',
481 'from_fieldname' => 'user_status',
482 'to_type' => 'user',
483 'to_fieldname' => 'user_status'
484 );
485
486 // User display name.
487 $this->field_map[] = array(
488 'from_tablename' => 'users',
489 'from_fieldname' => 'display_name',
490 'to_type' => 'user',
491 'to_fieldname' => 'display_name'
492 );
493 }
494
495 /**
496 * This method allows us to indicates what is or is not converted for each
497 * converter.
498 */
499 public function info() {
500 return '';
501 }
502
503 /**
504 * This method is to save the salt and password together. That
505 * way when we authenticate it we can get it out of the database
506 * as one value. Array values are auto sanitized by WordPress.
507 */
508 public function callback_savepass( $field, $row ) {
509 return false;
510 }
511
512 /**
513 * This method is to take the pass out of the database and compare
514 * to a pass the user has typed in.
515 */
516 public function authenticate_pass( $password, $serialized_pass ) {
517 return false;
518 }
519
520 /**
521 * Translate the post status from Simple:Press v5.x numerics to WordPress's strings.
522 *
523 * @param int $status Simple:Press numeric status
524 * @return string WordPress safe
525 */
526 public function callback_status( $status = 0 ) {
527 switch ( $status ) {
528 case 1 :
529 $status = 'closed';
530 break;
531
532 case 0 :
533 default :
534 $status = 'publish';
535 break;
536 }
537 return $status;
538 }
539
540 /**
541 * Translate the topic sticky status type from Simple:Press v5.x numerics to WordPress's strings.
542 *
543 * @param int $status Simple:Press v5.x numeric forum type
544 * @return string WordPress safe
545 */
546 public function callback_sticky_status( $status = 0 ) {
547 switch ( $status ) {
548 case 1 :
549 $status = 'sticky'; // Simple:Press Sticky 'topic_sticky = 1'
550 break;
551
552 case 0 :
553 default :
554 $status = 'normal'; // Simple:Press Normal Topic 'topic_sticky = 0'
555 break;
556 }
557 return $status;
558 }
559
560 /**
561 * Verify the topic reply count.
562 *
563 * @param int $count Simple:Press v5.x reply count
564 * @return string WordPress safe
565 */
566 public function callback_topic_reply_count( $count = 1 ) {
567 $count = absint( (int) $count - 1 );
568 return $count;
569 }
570
571 /**
572 * This callback processes any custom parser.php attributes and custom HTML code with preg_replace
573 */
574 protected function callback_html( $field ) {
575
576 // Strip any custom HTML not supported by parser.php first from $field before parsing $field to parser.php
577 $simplepress_markup = $field;
578 $simplepress_markup = html_entity_decode( $simplepress_markup );
579
580 // Replace any SimplePress smilies from path '/sp-resources/forum-smileys/sf-smily.gif' with the equivelant WordPress Smilie
581 $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-confused\.gif(.*?)\" \/>/', ':?', $simplepress_markup );
582 $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-cool\.gif(.*?)\" \/>/', ':cool:', $simplepress_markup );
583 $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-cry\.gif(.*?)\" \/>/', ':cry:', $simplepress_markup );
584 $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-embarassed\.gif(.*?)\" \/>/', ':oops:', $simplepress_markup );
585 $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-frown\.gif(.*?)\" \/>/', ':(', $simplepress_markup );
586 $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-kiss\.gif(.*?)\" \/>/', ':P', $simplepress_markup );
587 $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-laugh\.gif(.*?)\" \/>/', ':D', $simplepress_markup );
588 $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-smile\.gif(.*?)\" \/>/', ':smile:', $simplepress_markup );
589 $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-surprised\.gif(.*?)\" \/>/', ':o', $simplepress_markup );
590 $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-wink\.gif(.*?)\" \/>/', ':wink:', $simplepress_markup );
591 $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-yell\.gif(.*?)\" \/>/', ':x', $simplepress_markup );
592
593 // Replace '<div class="sfcode">example code</div>' with '<code>*</code>'
594 $simplepress_markup = preg_replace( '/\<div class\=\"sfcode\"\>(.*?)\<\/div\>/', '<code>$1</code>', $simplepress_markup );
595
596 // Replace '<strong>username said </strong>' with '@username said:'
597 $simplepress_markup = preg_replace( '/\<strong\>(.*?)\ said\ \<\/strong\>/', '@$1 said:', $simplepress_markup );
598
599 // Replace '<p>&nbsp;</p>' with '<p>&nbsp;</p>'
600 $simplepress_markup = preg_replace( '/\n(&nbsp;|[\s\p{Z}\xA0\x{00A0}]+)\r/', '<br>', $simplepress_markup );
601
602 // Now that SimplePress' custom HTML codes have been stripped put the cleaned HTML back in $field
603 $field = $simplepress_markup;
604
605 // Parse out any bbCodes in $field with the BBCode 'parser.php'
606 return parent::callback_html( $field );
607 }
608 }
609