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

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

569 lines 16.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 Kunena 2.x Converter
5 *
6 * @package bbPress
7 * @subpackage Converters
8 */
9
10 /**
11 * Implementation of Kunena v2.x Forums for Joomla Forum converter.
12 *
13 * @since 2.5.0 bbPress (r5145)
14 *
15 * @link Codex Docs https://codex.bbpress.org/import-forums/kunena/
16 */
17 class Kunena2 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 /** Forum Section *****************************************************/
33
34 // Old forum id (Stored in postmeta)
35 $this->field_map[] = array(
36 'from_tablename' => 'kunena_categories',
37 'from_fieldname' => 'id',
38 'to_type' => 'forum',
39 'to_fieldname' => '_bbp_old_forum_id'
40 );
41
42 // Forum parent id (If no parent, then 0, Stored in postmeta)
43 $this->field_map[] = array(
44 'from_tablename' => 'kunena_categories',
45 'from_fieldname' => 'parent_id',
46 'to_type' => 'forum',
47 'to_fieldname' => '_bbp_old_forum_parent_id'
48 );
49
50 // Forum topic count (Stored in postmeta)
51 $this->field_map[] = array(
52 'from_tablename' => 'kunena_categories',
53 'from_fieldname' => 'numTopics',
54 'to_type' => 'forum',
55 'to_fieldname' => '_bbp_topic_count'
56 );
57
58 // Forum reply count (Stored in postmeta)
59 $this->field_map[] = array(
60 'from_tablename' => 'kunena_categories',
61 'from_fieldname' => 'numPosts',
62 'to_type' => 'forum',
63 'to_fieldname' => '_bbp_reply_count'
64 );
65
66 // Forum total topic count (Includes unpublished topics, Stored in postmeta)
67 $this->field_map[] = array(
68 'from_tablename' => 'kunena_categories',
69 'from_fieldname' => 'numTopics',
70 'to_type' => 'forum',
71 'to_fieldname' => '_bbp_total_topic_count'
72 );
73
74 // Forum total reply count (Includes unpublished replies, Stored in postmeta)
75 $this->field_map[] = array(
76 'from_tablename' => 'kunena_categories',
77 'from_fieldname' => 'numPosts',
78 'to_type' => 'forum',
79 'to_fieldname' => '_bbp_total_reply_count'
80 );
81
82 // Forum title.
83 $this->field_map[] = array(
84 'from_tablename' => 'kunena_categories',
85 'from_fieldname' => 'name',
86 'to_type' => 'forum',
87 'to_fieldname' => 'post_title'
88 );
89
90 // Forum slug (Clean name to avoid conflicts)
91 $this->field_map[] = array(
92 'from_tablename' => 'kunena_categories',
93 'from_fieldname' => 'alias',
94 'to_type' => 'forum',
95 'to_fieldname' => 'post_name',
96 'callback_method' => 'callback_slug'
97 );
98
99 // Forum description.
100 $this->field_map[] = array(
101 'from_tablename' => 'kunena_categories',
102 'from_fieldname' => 'description',
103 'to_type' => 'forum',
104 'to_fieldname' => 'post_content',
105 'callback_method' => 'callback_null'
106 );
107
108 // Forum display order (Starts from 1)
109 $this->field_map[] = array(
110 'from_tablename' => 'kunena_categories',
111 'from_fieldname' => 'ordering',
112 'to_type' => 'forum',
113 'to_fieldname' => 'menu_order'
114 );
115
116 // Forum type (Category = 0 or Forum = >0, Stored in postmeta)
117 $this->field_map[] = array(
118 'from_tablename' => 'kunena_categories',
119 'from_fieldname' => 'parent_id',
120 'to_type' => 'forum',
121 'to_fieldname' => '_bbp_forum_type',
122 'callback_method' => 'callback_forum_type'
123 );
124
125 // Forum status (Open = 0 or Closed = 1, Stored in postmeta)
126 $this->field_map[] = array(
127 'from_tablename' => 'kunena_categories',
128 'from_fieldname' => 'locked',
129 'to_type' => 'forum',
130 'to_fieldname' => '_bbp_status',
131 'callback_method' => 'callback_forum_status'
132 );
133
134 // Forum dates.
135 $this->field_map[] = array(
136 'to_type' => 'forum',
137 'to_fieldname' => 'post_date',
138 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
139 );
140 $this->field_map[] = array(
141 'to_type' => 'forum',
142 'to_fieldname' => 'post_date_gmt',
143 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
144 );
145 $this->field_map[] = array(
146 'to_type' => 'forum',
147 'to_fieldname' => 'post_modified',
148 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
149 );
150 $this->field_map[] = array(
151 'to_type' => 'forum',
152 'to_fieldname' => 'post_modified_gmt',
153 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
154 );
155
156 /** Topic Section *****************************************************/
157
158 // Old topic id (Stored in postmeta)
159 $this->field_map[] = array(
160 'from_tablename' => 'kunena_topics',
161 'from_fieldname' => 'id',
162 'to_type' => 'topic',
163 'to_fieldname' => '_bbp_old_topic_id'
164 );
165
166 // Topic reply count (Stored in postmeta)
167 $this->field_map[] = array(
168 'from_tablename' => 'kunena_topics',
169 'from_fieldname' => 'posts',
170 'to_type' => 'topic',
171 'to_fieldname' => '_bbp_reply_count',
172 'callback_method' => 'callback_topic_reply_count'
173 );
174
175 // Topic total reply count (Includes unpublished replies, Stored in postmeta)
176 $this->field_map[] = array(
177 'from_tablename' => 'kunena_topics',
178 'from_fieldname' => 'posts',
179 'to_type' => 'topic',
180 'to_fieldname' => '_bbp_total_reply_count',
181 'callback_method' => 'callback_topic_reply_count'
182 );
183
184 // Topic parent forum id (If no parent, then 0. Stored in postmeta)
185 $this->field_map[] = array(
186 'from_tablename' => 'kunena_topics',
187 'from_fieldname' => 'category_id',
188 'to_type' => 'topic',
189 'to_fieldname' => '_bbp_forum_id',
190 'callback_method' => 'callback_forumid'
191 );
192
193 // Topic author.
194 $this->field_map[] = array(
195 'from_tablename' => 'kunena_topics',
196 'from_fieldname' => 'first_post_userid',
197 'to_type' => 'topic',
198 'to_fieldname' => 'post_author',
199 'callback_method' => 'callback_userid'
200 );
201
202 // Topic Author ip (Stored in postmeta)
203 // Note: We join the 'kunena_messages' table because 'kunena_topics' table does not include author ip.
204 $this->field_map[] = array(
205 'from_tablename' => 'kunena_messages',
206 'from_fieldname' => 'ip',
207 'join_tablename' => 'kunena_topics',
208 'join_type' => 'LEFT',
209 'join_expression' => 'USING (id)',
210 'to_type' => 'topic',
211 'to_fieldname' => '_bbp_author_ip'
212 );
213
214 // Topic content.
215 $this->field_map[] = array(
216 'from_tablename' => 'kunena_topics',
217 'from_fieldname' => 'first_post_message',
218 'to_type' => 'topic',
219 'to_fieldname' => 'post_content',
220 'callback_method' => 'callback_html'
221 );
222
223 // Topic title.
224 $this->field_map[] = array(
225 'from_tablename' => 'kunena_topics',
226 'from_fieldname' => 'subject',
227 'to_type' => 'topic',
228 'to_fieldname' => 'post_title'
229 );
230
231 // Topic slug (Clean name to avoid conflicts)
232 $this->field_map[] = array(
233 'from_tablename' => 'kunena_topics',
234 'from_fieldname' => 'subject',
235 'to_type' => 'topic',
236 'to_fieldname' => 'post_name',
237 'callback_method' => 'callback_slug'
238 );
239
240 // Topic parent forum id (If no parent, then 0)
241 $this->field_map[] = array(
242 'from_tablename' => 'kunena_topics',
243 'from_fieldname' => 'category_id',
244 'to_type' => 'topic',
245 'to_fieldname' => 'post_parent',
246 'callback_method' => 'callback_forumid'
247 );
248
249 // Topic dates.
250 $this->field_map[] = array(
251 'from_tablename' => 'kunena_topics',
252 'from_fieldname' => 'first_post_time',
253 'to_type' => 'topic',
254 'to_fieldname' => 'post_date',
255 'callback_method' => 'callback_datetime'
256 );
257 $this->field_map[] = array(
258 'from_tablename' => 'kunena_topics',
259 'from_fieldname' => 'first_post_time',
260 'to_type' => 'topic',
261 'to_fieldname' => 'post_date_gmt',
262 'callback_method' => 'callback_datetime'
263 );
264 $this->field_map[] = array(
265 'from_tablename' => 'kunena_topics',
266 'from_fieldname' => 'last_post_time',
267 'to_type' => 'topic',
268 'to_fieldname' => 'post_modified',
269 'callback_method' => 'callback_datetime'
270 );
271 $this->field_map[] = array(
272 'from_tablename' => 'kunena_topics',
273 'from_fieldname' => 'last_post_time',
274 'to_type' => 'topic',
275 'to_fieldname' => 'post_modified_gmt',
276 'callback_method' => 'callback_datetime'
277 );
278 $this->field_map[] = array(
279 'from_tablename' => 'kunena_topics',
280 'from_fieldname' => 'last_post_time',
281 'to_type' => 'topic',
282 'to_fieldname' => '_bbp_last_active_time',
283 'callback_method' => 'callback_datetime'
284 );
285
286 // Topic status (Open or Closed, Kunena v2.x 0=open & 1=closed)
287 $this->field_map[] = array(
288 'from_tablename' => 'kunena_topics',
289 'from_fieldname' => 'locked',
290 'to_type' => 'topic',
291 'to_fieldname' => '_bbp_old_closed_status_id',
292 'callback_method' => 'callback_topic_status'
293 );
294
295 /** Tags Section ******************************************************/
296
297 /**
298 * Kunena v2.x Forums do not support topic tags out of the box
299 */
300
301 /** Reply Section *****************************************************/
302
303 // Old reply id (Stored in postmeta)
304 $this->field_map[] = array(
305 'from_tablename' => 'kunena_messages',
306 'from_fieldname' => 'id',
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' => 'kunena_messages',
314 'from_fieldname' => 'catid',
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' => 'kunena_messages',
323 'from_fieldname' => 'thread',
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' => 'kunena_messages',
332 'from_fieldname' => 'ip',
333 'to_type' => 'reply',
334 'to_fieldname' => '_bbp_author_ip'
335 );
336
337 // Reply author.
338 $this->field_map[] = array(
339 'from_tablename' => 'kunena_messages',
340 'from_fieldname' => 'userid',
341 'to_type' => 'reply',
342 'to_fieldname' => 'post_author',
343 'callback_method' => 'callback_userid'
344 );
345
346 // Reply content.
347 // Note: We join the 'kunena_messages_text' table because 'kunena_messages' table does not include reply content.
348 $this->field_map[] = array(
349 'from_tablename' => 'kunena_messages_text',
350 'from_fieldname' => 'message',
351 'join_tablename' => 'kunena_messages',
352 'join_type' => 'LEFT',
353 'join_expression' => 'ON kunena_messages_text.mesid = kunena_messages.id LEFT JOIN jos_kunena_topics AS kunena_topics ON kunena_messages.thread = kunena_topics.id WHERE kunena_messages.parent != 0',
354 'to_type' => 'reply',
355 'to_fieldname' => 'post_content',
356 'callback_method' => 'callback_html'
357 );
358
359 // Reply parent topic id (If no parent, then 0)
360 $this->field_map[] = array(
361 'from_tablename' => 'kunena_messages',
362 'from_fieldname' => 'thread',
363 'to_type' => 'reply',
364 'to_fieldname' => 'post_parent',
365 'callback_method' => 'callback_topicid'
366 );
367
368 // Reply dates.
369 $this->field_map[] = array(
370 'from_tablename' => 'kunena_messages',
371 'from_fieldname' => 'time',
372 'to_type' => 'reply',
373 'to_fieldname' => 'post_date',
374 'callback_method' => 'callback_datetime'
375 );
376 $this->field_map[] = array(
377 'from_tablename' => 'kunena_messages',
378 'from_fieldname' => 'time',
379 'to_type' => 'reply',
380 'to_fieldname' => 'post_date_gmt',
381 'callback_method' => 'callback_datetime'
382 );
383 $this->field_map[] = array(
384 'from_tablename' => 'kunena_messages',
385 'from_fieldname' => 'time',
386 'to_type' => 'reply',
387 'to_fieldname' => 'post_modified',
388 'callback_method' => 'callback_datetime'
389 );
390 $this->field_map[] = array(
391 'from_tablename' => 'kunena_messages',
392 'from_fieldname' => 'time',
393 'to_type' => 'reply',
394 'to_fieldname' => 'post_modified_gmt',
395 'callback_method' => 'callback_datetime'
396 );
397
398 /** User Section ******************************************************/
399
400 //Note: We are importing the Joomla User details and the Kunena v2.x user profile details.
401
402 // Store old user id (Stored in usermeta)
403 $this->field_map[] = array(
404 'from_tablename' => 'users',
405 'from_fieldname' => 'id',
406 'to_type' => 'user',
407 'to_fieldname' => '_bbp_old_user_id'
408 );
409
410 // Store old user password (Stored in serialized usermeta)
411 $this->field_map[] = array(
412 'from_tablename' => 'users',
413 'from_fieldname' => 'password',
414 'to_type' => 'user',
415 'to_fieldname' => '_bbp_password',
416 'callback_method' => 'callback_savepass'
417 );
418
419 // User password verify class. Stores in usermeta for verifying password.
420 $this->field_map[] = array(
421 'to_type' => 'user',
422 'to_fieldname' => '_bbp_class',
423 'default' => 'Kunena2'
424 );
425
426 // User name.
427 $this->field_map[] = array(
428 'from_tablename' => 'users',
429 'from_fieldname' => 'username',
430 'to_type' => 'user',
431 'to_fieldname' => 'user_login'
432 );
433
434 // User email.
435 $this->field_map[] = array(
436 'from_tablename' => 'users',
437 'from_fieldname' => 'email',
438 'to_type' => 'user',
439 'to_fieldname' => 'user_email'
440 );
441
442 // User registered.
443 $this->field_map[] = array(
444 'from_tablename' => 'users',
445 'from_fieldname' => 'registerDate',
446 'to_type' => 'user',
447 'to_fieldname' => 'user_registered',
448 'callback_method' => 'callback_datetime'
449 );
450
451 // User display name.
452 $this->field_map[] = array(
453 'from_tablename' => 'users',
454 'from_fieldname' => 'name',
455 'to_type' => 'user',
456 'to_fieldname' => 'display_name'
457 );
458 }
459
460 /**
461 * This method allows us to indicates what is or is not converted for each
462 * converter.
463 */
464 public function info() {
465 return '';
466 }
467
468 /**
469 * This method is to save the salt and password together. That
470 * way when we authenticate it we can get it out of the database
471 * as one value. Array values are auto sanitized by WordPress.
472 */
473 public function callback_savepass( $field, $row ) {
474 return array( 'hash' => $field );
475 }
476
477 /**
478 * This method is to take the pass out of the database and compare
479 * to a pass the user has typed in.
480 */
481 public function authenticate_pass( $password, $serialized_pass ) {
482
483 // Unserialize the password, with safeguards
484 $pass_array = $this->unserialize_pass( $serialized_pass );
485
486 // Bail if missing or invalid values
487 if ( ! is_string( $password ) || ! is_array( $pass_array ) || ! isset( $pass_array['hash'] ) || ! is_string( $pass_array['hash'] ) ) {
488 return false;
489 }
490
491 // Joomla 2.5.18 and newer portable password hashes
492 if ( 0 === strpos( $pass_array['hash'], '$P$' ) ) {
493 return wp_check_password( $password, $pass_array['hash'] );
494 }
495
496 // Legacy Joomla MD5 passwords
497 $parts = explode( ':', $pass_array['hash'], 2 );
498 $salt = isset( $parts[1] ) ? $parts[1] : '';
499
500 return hash_equals( $parts[0], md5( $password . $salt ) );
501 }
502
503 /**
504 * Translate the forum type from Kunena v2.x numerics to WordPress's strings.
505 *
506 * @param int $status Kunena v2.x numeric forum type
507 * @return string WordPress safe
508 */
509 public function callback_forum_type( $status = 0 ) {
510 if ( empty( $status ) ) {
511 $status = 'category';
512 } else {
513 $status = 'forum';
514 }
515 return $status;
516 }
517
518 /**
519 * Translate the forum status from Kunena v2.x numerics to WordPress's strings.
520 *
521 * @param int $status Kunena v2.x numeric forum status
522 * @return string WordPress safe
523 */
524 public function callback_forum_status( $status = 0 ) {
525 switch ( $status ) {
526 case 1 :
527 $status = 'closed';
528 break;
529
530 case 0 :
531 default :
532 $status = 'open';
533 break;
534 }
535 return $status;
536 }
537
538 /**
539 * Translate the post status from Kunena v2.x numerics to WordPress's strings.
540 *
541 * @param int $status Kunena v2.x numeric topic status
542 * @return string WordPress safe
543 */
544 public function callback_topic_status( $status = 0 ) {
545 switch ( $status ) {
546 case 1 :
547 $status = 'closed';
548 break;
549
550 case 0 :
551 default :
552 $status = 'publish';
553 break;
554 }
555 return $status;
556 }
557
558 /**
559 * Verify the topic/reply count.
560 *
561 * @param int $count Kunena v2.x topic/reply counts
562 * @return string WordPress safe
563 */
564 public function callback_topic_reply_count( $count = 1 ) {
565 $count = absint( (int) $count - 1 );
566 return $count;
567 }
568 }
569