[ Index ] |
PHP Cross Reference of BBPress |
[Summary view] [Print] [Text view]
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 (r5144) 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') 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') 144 ); 145 $this->field_map[] = array( 146 'to_type' => 'forum', 147 'to_fieldname' => 'post_modified', 148 'default' => date('Y-m-d H:i:s') 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') 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 usermeta serialized with salt) 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 // Store old user salt. This is only used for the SELECT row info for the above password save 420 /* 421 $this->field_map[] = array( 422 'from_tablename' => 'users', 423 'from_fieldname' => 'salt', 424 'to_type' => 'user', 425 'to_fieldname' => '' 426 ); 427 */ 428 429 // User password verify class. Stores in usermeta for verifying password. 430 /* 431 $this->field_map[] = array( 432 'to_type' => 'user', 433 'to_fieldname' => '_bbp_class', 434 'default' => 'Kunena2' 435 ); 436 */ 437 438 // User name. 439 $this->field_map[] = array( 440 'from_tablename' => 'users', 441 'from_fieldname' => 'username', 442 'to_type' => 'user', 443 'to_fieldname' => 'user_login' 444 ); 445 446 // User email. 447 $this->field_map[] = array( 448 'from_tablename' => 'users', 449 'from_fieldname' => 'email', 450 'to_type' => 'user', 451 'to_fieldname' => 'user_email' 452 ); 453 454 // User registered. 455 $this->field_map[] = array( 456 'from_tablename' => 'users', 457 'from_fieldname' => 'registerDate', 458 'to_type' => 'user', 459 'to_fieldname' => 'user_registered', 460 'callback_method' => 'callback_datetime' 461 ); 462 463 // User display name. 464 $this->field_map[] = array( 465 'from_tablename' => 'users', 466 'from_fieldname' => 'name', 467 'to_type' => 'user', 468 'to_fieldname' => 'display_name' 469 ); 470 471 } 472 473 /** 474 * This method allows us to indicates what is or is not converted for each 475 * converter. 476 */ 477 public function info() { 478 return ''; 479 } 480 481 /** 482 * This method is to save the salt and password together. That 483 * way when we authenticate it we can get it out of the database 484 * as one value. Array values are auto sanitized by WordPress. 485 */ 486 public function callback_savepass($field, $row) { 487 $pass_array = array('hash' => $field, 'salt' => $row['salt']); 488 return $pass_array; 489 } 490 491 /** 492 * This method is to take the pass out of the database and compare 493 * to a pass the user has typed in. 494 */ 495 public function authenticate_pass($password, $serialized_pass) { 496 $pass_array = unserialize($serialized_pass); 497 return ( $pass_array['hash'] == md5(md5($password) . $pass_array['salt']) ); 498 } 499 /** 500 * Translate the forum type from Kunena v2.x numerics to WordPress's strings. 501 * 502 * @param int $status Kunena v2.x numeric forum type 503 * @return string WordPress safe 504 */ 505 public function callback_forum_type( $status = 0 ) { 506 if ( $status == 0 ) { 507 $status = 'category'; 508 } else { 509 $status = 'forum'; 510 } 511 return $status; 512 } 513 514 /** 515 * Translate the forum status from Kunena v2.x numerics to WordPress's strings. 516 * 517 * @param int $status Kunena v2.x numeric forum status 518 * @return string WordPress safe 519 */ 520 public function callback_forum_status( $status = 0 ) { 521 switch ( $status ) { 522 case 1 : 523 $status = 'closed'; 524 break; 525 526 case 0 : 527 default : 528 $status = 'open'; 529 break; 530 } 531 return $status; 532 } 533 534 /** 535 * Translate the post status from Kunena v2.x numerics to WordPress's strings. 536 * 537 * @param int $status Kunena v2.x numeric topic status 538 * @return string WordPress safe 539 */ 540 public function callback_topic_status( $status = 0 ) { 541 switch ( $status ) { 542 case 1 : 543 $status = 'closed'; 544 break; 545 546 case 0 : 547 default : 548 $status = 'publish'; 549 break; 550 } 551 return $status; 552 } 553 554 /** 555 * Verify the topic/reply count. 556 * 557 * @param int $count Kunena v2.x topic/reply counts 558 * @return string WordPress safe 559 */ 560 public function callback_topic_reply_count( $count = 1 ) { 561 $count = absint( (int) $count - 1 ); 562 return $count; 563 } 564 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sat Dec 21 01:00:52 2024 | Cross-referenced by PHPXref 0.7.1 |