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

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

526 lines 15.0 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 1.x Converter
5 *
6 * @package bbPress
7 * @subpackage Converters
8 */
9
10 /**
11 * Implementation of Kunena v1.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 Kunena1 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',
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' => 'name',
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',
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_messages',
161 'from_fieldname' => 'thread',
162 'to_type' => 'topic',
163 'to_fieldname' => '_bbp_old_topic_id'
164 );
165
166 // Topic parent forum id (If no parent, then 0. Stored in postmeta)
167 $this->field_map[] = array(
168 'from_tablename' => 'kunena_messages',
169 'from_fieldname' => 'catid',
170 'to_type' => 'topic',
171 'to_fieldname' => '_bbp_forum_id',
172 'callback_method' => 'callback_forumid'
173 );
174
175 // Topic author.
176 $this->field_map[] = array(
177 'from_tablename' => 'kunena_messages',
178 'from_fieldname' => 'userid',
179 'to_type' => 'topic',
180 'to_fieldname' => 'post_author',
181 'callback_method' => 'callback_userid'
182 );
183
184 // Topic Author ip (Stored in postmeta)
185 $this->field_map[] = array(
186 'from_tablename' => 'kunena_messages',
187 'from_fieldname' => 'ip',
188 'to_type' => 'topic',
189 'to_fieldname' => '_bbp_author_ip'
190 );
191
192 // Topic content.
193 // Note: We join the 'kunena_messages_text' table because 'kunena_messages' table does not include topic content.
194 $this->field_map[] = array(
195 'from_tablename' => 'kunena_messages_text',
196 'from_fieldname' => 'message',
197 'join_tablename' => 'kunena_messages',
198 'join_type' => 'INNER',
199 'join_expression' => 'ON kunena_messages_text.mesid = kunena_messages.id WHERE kunena_messages.parent = 0',
200 'to_type' => 'topic',
201 'to_fieldname' => 'post_content',
202 'callback_method' => 'callback_html'
203 );
204
205 // Topic title.
206 $this->field_map[] = array(
207 'from_tablename' => 'kunena_messages',
208 'from_fieldname' => 'subject',
209 'to_type' => 'topic',
210 'to_fieldname' => 'post_title'
211 );
212
213 // Topic slug (Clean name to avoid conflicts)
214 $this->field_map[] = array(
215 'from_tablename' => 'kunena_messages',
216 'from_fieldname' => 'subject',
217 'to_type' => 'topic',
218 'to_fieldname' => 'post_name',
219 'callback_method' => 'callback_slug'
220 );
221
222 // Topic parent forum id (If no parent, then 0)
223 $this->field_map[] = array(
224 'from_tablename' => 'kunena_messages',
225 'from_fieldname' => 'catid',
226 'to_type' => 'topic',
227 'to_fieldname' => 'post_parent',
228 'callback_method' => 'callback_forumid'
229 );
230
231 // Topic dates.
232 $this->field_map[] = array(
233 'from_tablename' => 'kunena_messages',
234 'from_fieldname' => 'time',
235 'to_type' => 'topic',
236 'to_fieldname' => 'post_date',
237 'callback_method' => 'callback_datetime'
238 );
239 $this->field_map[] = array(
240 'from_tablename' => 'kunena_messages',
241 'from_fieldname' => 'time',
242 'to_type' => 'topic',
243 'to_fieldname' => 'post_date_gmt',
244 'callback_method' => 'callback_datetime'
245 );
246 $this->field_map[] = array(
247 'from_tablename' => 'kunena_messages',
248 'from_fieldname' => 'time',
249 'to_type' => 'topic',
250 'to_fieldname' => 'post_modified',
251 'callback_method' => 'callback_datetime'
252 );
253 $this->field_map[] = array(
254 'from_tablename' => 'kunena_messages',
255 'from_fieldname' => 'time',
256 'to_type' => 'topic',
257 'to_fieldname' => 'post_modified_gmt',
258 'callback_method' => 'callback_datetime'
259 );
260 $this->field_map[] = array(
261 'from_tablename' => 'kunena_messages',
262 'from_fieldname' => 'time',
263 'to_type' => 'topic',
264 'to_fieldname' => '_bbp_last_active_time',
265 'callback_method' => 'callback_datetime'
266 );
267
268 // Topic status (Open or Closed, Kunena v3.x 0=open & 1=closed)
269 $this->field_map[] = array(
270 'from_tablename' => 'kunena_messages',
271 'from_fieldname' => 'locked',
272 'to_type' => 'topic',
273 'to_fieldname' => '_bbp_old_closed_status_id',
274 'callback_method' => 'callback_topic_status'
275 );
276
277 /** Tags Section ******************************************************/
278
279 /**
280 * Kunena v1.x Forums do not support topic tags out of the box
281 */
282
283 /** Reply Section *****************************************************/
284
285 // Old reply id (Stored in postmeta)
286 $this->field_map[] = array(
287 'from_tablename' => 'kunena_messages',
288 'from_fieldname' => 'id',
289 'to_type' => 'reply',
290 'to_fieldname' => '_bbp_old_reply_id'
291 );
292
293 // Reply parent forum id (If no parent, then 0. Stored in postmeta)
294 $this->field_map[] = array(
295 'from_tablename' => 'kunena_messages',
296 'from_fieldname' => 'catid',
297 'to_type' => 'reply',
298 'to_fieldname' => '_bbp_forum_id',
299 'callback_method' => 'callback_topicid_to_forumid'
300 );
301
302 // Reply parent topic id (If no parent, then 0. Stored in postmeta)
303 $this->field_map[] = array(
304 'from_tablename' => 'kunena_messages',
305 'from_fieldname' => 'thread',
306 'to_type' => 'reply',
307 'to_fieldname' => '_bbp_topic_id',
308 'callback_method' => 'callback_topicid'
309 );
310
311 // Reply author ip (Stored in postmeta)
312 $this->field_map[] = array(
313 'from_tablename' => 'kunena_messages',
314 'from_fieldname' => 'ip',
315 'to_type' => 'reply',
316 'to_fieldname' => '_bbp_author_ip'
317 );
318
319 // Reply author.
320 $this->field_map[] = array(
321 'from_tablename' => 'kunena_messages',
322 'from_fieldname' => 'userid',
323 'to_type' => 'reply',
324 'to_fieldname' => 'post_author',
325 'callback_method' => 'callback_userid'
326 );
327
328 // Reply content.
329 // Note: We join the 'kunena_messages_text' table because 'kunena_messages' table does not include reply content.
330 $this->field_map[] = array(
331 'from_tablename' => 'kunena_messages_text',
332 'from_fieldname' => 'message',
333 'join_tablename' => 'kunena_messages',
334 'join_type' => 'INNER',
335 'join_expression' => 'ON kunena_messages.id = kunena_messages_text.mesid WHERE kunena_messages.parent != 0',
336 'to_type' => 'reply',
337 'to_fieldname' => 'post_content',
338 'callback_method' => 'callback_html'
339 );
340
341 // Reply parent topic id (If no parent, then 0)
342 $this->field_map[] = array(
343 'from_tablename' => 'kunena_messages',
344 'from_fieldname' => 'thread',
345 'to_type' => 'reply',
346 'to_fieldname' => 'post_parent',
347 'callback_method' => 'callback_topicid'
348 );
349
350 // Reply dates.
351 $this->field_map[] = array(
352 'from_tablename' => 'kunena_messages',
353 'from_fieldname' => 'time',
354 'to_type' => 'reply',
355 'to_fieldname' => 'post_date',
356 'callback_method' => 'callback_datetime'
357 );
358 $this->field_map[] = array(
359 'from_tablename' => 'kunena_messages',
360 'from_fieldname' => 'time',
361 'to_type' => 'reply',
362 'to_fieldname' => 'post_date_gmt',
363 'callback_method' => 'callback_datetime'
364 );
365 $this->field_map[] = array(
366 'from_tablename' => 'kunena_messages',
367 'from_fieldname' => 'time',
368 'to_type' => 'reply',
369 'to_fieldname' => 'post_modified',
370 'callback_method' => 'callback_datetime'
371 );
372 $this->field_map[] = array(
373 'from_tablename' => 'kunena_messages',
374 'from_fieldname' => 'time',
375 'to_type' => 'reply',
376 'to_fieldname' => 'post_modified_gmt',
377 'callback_method' => 'callback_datetime'
378 );
379
380 /** User Section ******************************************************/
381
382 //Note: We are importing the Joomla User details and the Kunena v1.x user profile details.
383
384 // Store old user id (Stored in usermeta)
385 $this->field_map[] = array(
386 'from_tablename' => 'users',
387 'from_fieldname' => 'id',
388 'to_type' => 'user',
389 'to_fieldname' => '_bbp_old_user_id'
390 );
391
392 // Store old user password (Stored in usermeta serialized with salt)
393 $this->field_map[] = array(
394 'from_tablename' => 'users',
395 'from_fieldname' => 'password',
396 'to_type' => 'user',
397 'to_fieldname' => '_bbp_password',
398 'callback_method' => 'callback_savepass'
399 );
400
401 // User password verify class (Stored in usermeta for verifying password)
402 $this->field_map[] = array(
403 'to_type' => 'user',
404 'to_fieldname' => '_bbp_class',
405 'default' => 'Kunena1'
406 );
407
408 // User name.
409 $this->field_map[] = array(
410 'from_tablename' => 'users',
411 'from_fieldname' => 'username',
412 'to_type' => 'user',
413 'to_fieldname' => 'user_login'
414 );
415
416 // User email.
417 $this->field_map[] = array(
418 'from_tablename' => 'users',
419 'from_fieldname' => 'email',
420 'to_type' => 'user',
421 'to_fieldname' => 'user_email'
422 );
423
424 // User registered.
425 $this->field_map[] = array(
426 'from_tablename' => 'users',
427 'from_fieldname' => 'registerDate',
428 'to_type' => 'user',
429 'to_fieldname' => 'user_registered',
430 'callback_method' => 'callback_datetime'
431 );
432 }
433
434 /**
435 * This method allows us to indicates what is or is not converted for each
436 * converter.
437 */
438 public function info() {
439 return '';
440 }
441
442 /**
443 * This method is to save the salt and password together. That
444 * way when we authenticate it we can get it out of the database
445 * as one value. Array values are auto sanitized by WordPress.
446 */
447 public function callback_savepass( $field, $row ) {
448 return array( 'hash' => $field );
449 }
450
451 /**
452 * This method is to take the pass out of the database and compare
453 * to a pass the user has typed in.
454 */
455 public function authenticate_pass( $password, $serialized_pass ) {
456
457 // Unserialize the password, with safeguards
458 $pass_array = $this->unserialize_pass( $serialized_pass );
459
460 // Bail if missing or invalid values
461 if ( ! is_string( $password ) || ! is_array( $pass_array ) || ! isset( $pass_array['hash'] ) || ! is_string( $pass_array['hash'] ) ) {
462 return false;
463 }
464
465 $parts = explode( ':', $pass_array['hash'], 2 );
466 $salt = isset( $parts[1] ) ? $parts[1] : '';
467
468 return hash_equals( $parts[0], md5( $password . $salt ) );
469 }
470
471 /**
472 * Translate the forum type from Kunena v1.x numerics to WordPress's strings.
473 *
474 * @param int $status Kunena v1.x numeric forum type
475 * @return string WordPress safe
476 */
477 public function callback_forum_type( $status = 0 ) {
478 if ( empty( $status ) ) {
479 $status = 'category';
480 } else {
481 $status = 'forum';
482 }
483 return $status;
484 }
485
486 /**
487 * Translate the forum status from Kunena v1.x numerics to WordPress's strings.
488 *
489 * @param int $status Kunena v1.x numeric forum status
490 * @return string WordPress safe
491 */
492 public function callback_forum_status( $status = 0 ) {
493 switch ( $status ) {
494 case 1 :
495 $status = 'closed';
496 break;
497
498 case 0 :
499 default :
500 $status = 'open';
501 break;
502 }
503 return $status;
504 }
505
506 /**
507 * Translate the post status from Kunena v1.x numerics to WordPress's strings.
508 *
509 * @param int $status Kunena v1.x numeric topic status
510 * @return string WordPress safe
511 */
512 public function callback_topic_status( $status = 0 ) {
513 switch ( $status ) {
514 case 1 :
515 $status = 'closed';
516 break;
517
518 case 0 :
519 default :
520 $status = 'publish';
521 break;
522 }
523 return $status;
524 }
525 }
526