| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* bbPress Mingle Converter |
| 5 |
* |
| 6 |
* @package bbPress |
| 7 |
* @subpackage Converters |
| 8 |
*/ |
| 9 |
|
| 10 |
/** |
| 11 |
* Implementation of Mingle Forums converter. |
| 12 |
* |
| 13 |
* @since 2.3.0 bbPress (r4691) |
| 14 |
* |
| 15 |
* @link Codex Docs https://codex.bbpress.org/import-forums/mingle |
| 16 |
*/ |
| 17 |
class Mingle 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' => 'forum_forums', |
| 35 |
'from_fieldname' => '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' => 'forum_forums', |
| 43 |
'from_fieldname' => 'parent_id', |
| 44 |
'to_type' => 'forum', |
| 45 |
'to_fieldname' => '_bbp_old_forum_parent_id' |
| 46 |
); |
| 47 |
|
| 48 |
// Forum title. |
| 49 |
$this->field_map[] = array( |
| 50 |
'from_tablename' => 'forum_forums', |
| 51 |
'from_fieldname' => 'name', |
| 52 |
'to_type' => 'forum', |
| 53 |
'to_fieldname' => 'post_title' |
| 54 |
); |
| 55 |
|
| 56 |
// Forum slug (Clean name to avoid conflicts) |
| 57 |
$this->field_map[] = array( |
| 58 |
'from_tablename' => 'forum_forums', |
| 59 |
'from_fieldname' => 'name', |
| 60 |
'to_type' => 'forum', |
| 61 |
'to_fieldname' => 'post_name', |
| 62 |
'callback_method' => 'callback_slug' |
| 63 |
); |
| 64 |
// Forum description. |
| 65 |
$this->field_map[] = array( |
| 66 |
'from_tablename' => 'forum_forums', |
| 67 |
'from_fieldname' => 'description', |
| 68 |
'to_type' => 'forum', |
| 69 |
'to_fieldname' => 'post_content', |
| 70 |
'callback_method' => 'callback_null' |
| 71 |
); |
| 72 |
|
| 73 |
// Forum display order (Starts from 1) |
| 74 |
$this->field_map[] = array( |
| 75 |
'from_tablename' => 'forum_forums', |
| 76 |
'from_fieldname' => 'sort', |
| 77 |
'to_type' => 'forum', |
| 78 |
'to_fieldname' => 'menu_order' |
| 79 |
); |
| 80 |
|
| 81 |
// Forum type (Set a default value 'forum', Stored in postmeta) |
| 82 |
$this->field_map[] = array( |
| 83 |
'to_type' => 'forum', |
| 84 |
'to_fieldname' => '_bbp_forum_type', |
| 85 |
'default' => 'forum' |
| 86 |
); |
| 87 |
|
| 88 |
// Forum status (Set a default value 'open', Stored in postmeta) |
| 89 |
$this->field_map[] = array( |
| 90 |
'to_type' => 'forum', |
| 91 |
'to_fieldname' => '_bbp_status', |
| 92 |
'default' => 'open' |
| 93 |
); |
| 94 |
|
| 95 |
// Forum dates. |
| 96 |
$this->field_map[] = array( |
| 97 |
'to_type' => 'forum', |
| 98 |
'to_fieldname' => 'post_date', |
| 99 |
'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore |
| 100 |
); |
| 101 |
$this->field_map[] = array( |
| 102 |
'to_type' => 'forum', |
| 103 |
'to_fieldname' => 'post_date_gmt', |
| 104 |
'default' => gmdate( 'Y-m-d H:i:s' ) |
| 105 |
); |
| 106 |
$this->field_map[] = array( |
| 107 |
'to_type' => 'forum', |
| 108 |
'to_fieldname' => 'post_modified', |
| 109 |
'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore |
| 110 |
); |
| 111 |
$this->field_map[] = array( |
| 112 |
'to_type' => 'forum', |
| 113 |
'to_fieldname' => 'post_modified_gmt', |
| 114 |
'default' => gmdate( 'Y-m-d H:i:s' ) |
| 115 |
); |
| 116 |
|
| 117 |
/** Topic Section ******************************************************/ |
| 118 |
|
| 119 |
// Old topic id (Stored in postmeta) |
| 120 |
$this->field_map[] = array( |
| 121 |
'from_tablename' => 'forum_threads', |
| 122 |
'from_fieldname' => 'id', |
| 123 |
'to_type' => 'topic', |
| 124 |
'to_fieldname' => '_bbp_old_topic_id' |
| 125 |
); |
| 126 |
|
| 127 |
// Topic parent forum id (If no parent, then 0. Stored in postmeta) |
| 128 |
$this->field_map[] = array( |
| 129 |
'from_tablename' => 'forum_threads', |
| 130 |
'from_fieldname' => 'parent_id', |
| 131 |
'to_type' => 'topic', |
| 132 |
'to_fieldname' => '_bbp_forum_id', |
| 133 |
'callback_method' => 'callback_forumid' |
| 134 |
); |
| 135 |
|
| 136 |
// Topic author. |
| 137 |
$this->field_map[] = array( |
| 138 |
'from_tablename' => 'forum_threads', |
| 139 |
'from_fieldname' => 'starter', |
| 140 |
'to_type' => 'topic', |
| 141 |
'to_fieldname' => 'post_author', |
| 142 |
'callback_method' => 'callback_userid' |
| 143 |
); |
| 144 |
|
| 145 |
// Topic content. |
| 146 |
// Note: We join the forum_posts table because forum_topics do not have topic content. |
| 147 |
$this->field_map[] = array( |
| 148 |
'from_tablename' => 'forum_posts', |
| 149 |
'from_fieldname' => 'text', |
| 150 |
'join_tablename' => 'forum_threads', |
| 151 |
'join_type' => 'INNER', |
| 152 |
'join_expression' => 'ON forum_posts.parent_id = forum_threads.id GROUP BY forum_threads.id', |
| 153 |
'to_type' => 'topic', |
| 154 |
'to_fieldname' => 'post_content', |
| 155 |
'callback_method' => 'callback_html' |
| 156 |
); |
| 157 |
// Topic title. |
| 158 |
$this->field_map[] = array( |
| 159 |
'from_tablename' => 'forum_threads', |
| 160 |
'from_fieldname' => 'subject', |
| 161 |
'to_type' => 'topic', |
| 162 |
'to_fieldname' => 'post_title' |
| 163 |
); |
| 164 |
|
| 165 |
// Topic slug (Clean name to avoid conflicts) |
| 166 |
$this->field_map[] = array( |
| 167 |
'from_tablename' => 'forum_threads', |
| 168 |
'from_fieldname' => 'subject', |
| 169 |
'to_type' => 'topic', |
| 170 |
'to_fieldname' => 'post_name', |
| 171 |
'callback_method' => 'callback_slug' |
| 172 |
); |
| 173 |
|
| 174 |
// Topic parent forum id (If no parent, then 0) |
| 175 |
$this->field_map[] = array( |
| 176 |
'from_tablename' => 'forum_threads', |
| 177 |
'from_fieldname' => 'parent_id', |
| 178 |
'to_type' => 'topic', |
| 179 |
'to_fieldname' => 'post_parent', |
| 180 |
'callback_method' => 'callback_forumid' |
| 181 |
); |
| 182 |
|
| 183 |
// Sticky status (Stored in postmeta) |
| 184 |
$this->field_map[] = array( |
| 185 |
'from_tablename' => 'forum_threads', |
| 186 |
'from_fieldname' => 'status', |
| 187 |
'to_type' => 'topic', |
| 188 |
'to_fieldname' => '_bbp_old_sticky_status_id', |
| 189 |
'callback_method' => 'callback_sticky_status' |
| 190 |
); |
| 191 |
|
| 192 |
// Topic dates. |
| 193 |
$this->field_map[] = array( |
| 194 |
'from_tablename' => 'forum_threads', |
| 195 |
'from_fieldname' => 'date', |
| 196 |
'to_type' => 'topic', |
| 197 |
'to_fieldname' => 'post_date' |
| 198 |
); |
| 199 |
$this->field_map[] = array( |
| 200 |
'from_tablename' => 'forum_threads', |
| 201 |
'from_fieldname' => 'date', |
| 202 |
'to_type' => 'topic', |
| 203 |
'to_fieldname' => 'post_date_gmt' |
| 204 |
); |
| 205 |
$this->field_map[] = array( |
| 206 |
'from_tablename' => 'forum_threads', |
| 207 |
'from_fieldname' => 'last_post', |
| 208 |
'to_type' => 'topic', |
| 209 |
'to_fieldname' => 'post_modified' |
| 210 |
); |
| 211 |
$this->field_map[] = array( |
| 212 |
'from_tablename' => 'forum_threads', |
| 213 |
'from_fieldname' => 'last_post', |
| 214 |
'to_type' => 'topic', |
| 215 |
'to_fieldname' => 'post_modified_gmt' |
| 216 |
); |
| 217 |
$this->field_map[] = array( |
| 218 |
'from_tablename' => 'forum_threads', |
| 219 |
'from_fieldname' => 'last_post', |
| 220 |
'to_type' => 'topic', |
| 221 |
'to_fieldname' => '_bbp_last_active_time' |
| 222 |
); |
| 223 |
|
| 224 |
// Topic status (Open or Closed) |
| 225 |
$this->field_map[] = array( |
| 226 |
'from_tablename' => 'forum_threads', |
| 227 |
'from_fieldname' => 'closed', |
| 228 |
'to_type' => 'topic', |
| 229 |
'to_fieldname' => '_bbp_old_closed_status_id', |
| 230 |
'callback_method' => 'callback_topic_status' |
| 231 |
); |
| 232 |
|
| 233 |
/** Tags Section ******************************************************/ |
| 234 |
|
| 235 |
/** |
| 236 |
* Mingle Forums do not support topic tags |
| 237 |
*/ |
| 238 |
|
| 239 |
/** Reply Section ******************************************************/ |
| 240 |
|
| 241 |
// Old reply id (Stored in postmeta) |
| 242 |
$this->field_map[] = array( |
| 243 |
'from_tablename' => 'forum_posts', |
| 244 |
'from_fieldname' => 'id', |
| 245 |
'to_type' => 'reply', |
| 246 |
'to_fieldname' => '_bbp_old_reply_id' |
| 247 |
); |
| 248 |
|
| 249 |
// Setup reply section table joins |
| 250 |
// We need join the 'forum_threads' table to only import replies |
| 251 |
$this->field_map[] = array( |
| 252 |
'from_tablename' => 'forum_threads', |
| 253 |
'from_fieldname' => 'date', |
| 254 |
'join_tablename' => 'forum_posts', |
| 255 |
'join_type' => 'INNER', |
| 256 |
'join_expression' => 'ON forum_posts.parent_id = forum_threads.id', |
| 257 |
'from_expression' => 'WHERE forum_threads.subject != forum_posts.subject', |
| 258 |
'to_type' => 'reply', |
| 259 |
'to_fieldname' => '_bbp_last_active_time' |
| 260 |
); |
| 261 |
|
| 262 |
// Reply parent forum id (If no parent, then 0. Stored in postmeta) |
| 263 |
$this->field_map[] = array( |
| 264 |
'from_tablename' => 'forum_posts', |
| 265 |
'from_fieldname' => 'parent_id', |
| 266 |
'to_type' => 'reply', |
| 267 |
'to_fieldname' => '_bbp_forum_id', |
| 268 |
'callback_method' => 'callback_topicid_to_forumid' |
| 269 |
); |
| 270 |
|
| 271 |
// Reply parent topic id (If no parent, then 0. Stored in postmeta) |
| 272 |
$this->field_map[] = array( |
| 273 |
'from_tablename' => 'forum_posts', |
| 274 |
'from_fieldname' => 'parent_id', |
| 275 |
'to_type' => 'reply', |
| 276 |
'to_fieldname' => '_bbp_topic_id', |
| 277 |
'callback_method' => 'callback_topicid' |
| 278 |
); |
| 279 |
|
| 280 |
// Reply author. |
| 281 |
$this->field_map[] = array( |
| 282 |
'from_tablename' => 'forum_posts', |
| 283 |
'from_fieldname' => 'author_id', |
| 284 |
'to_type' => 'reply', |
| 285 |
'to_fieldname' => 'post_author', |
| 286 |
'callback_method' => 'callback_userid' |
| 287 |
); |
| 288 |
|
| 289 |
// Reply content. |
| 290 |
$this->field_map[] = array( |
| 291 |
'from_tablename' => 'forum_posts', |
| 292 |
'from_fieldname' => 'text', |
| 293 |
'to_type' => 'reply', |
| 294 |
'to_fieldname' => 'post_content', |
| 295 |
'callback_method' => 'callback_html' |
| 296 |
); |
| 297 |
|
| 298 |
// Reply parent topic id (If no parent, then 0) |
| 299 |
$this->field_map[] = array( |
| 300 |
'from_tablename' => 'forum_posts', |
| 301 |
'from_fieldname' => 'parent_id', |
| 302 |
'to_type' => 'reply', |
| 303 |
'to_fieldname' => 'post_parent', |
| 304 |
'callback_method' => 'callback_topicid' |
| 305 |
); |
| 306 |
|
| 307 |
// Reply dates. |
| 308 |
$this->field_map[] = array( |
| 309 |
'from_tablename' => 'forum_posts', |
| 310 |
'from_fieldname' => 'date', |
| 311 |
'to_type' => 'reply', |
| 312 |
'to_fieldname' => 'post_date' |
| 313 |
); |
| 314 |
$this->field_map[] = array( |
| 315 |
'from_tablename' => 'forum_posts', |
| 316 |
'from_fieldname' => 'date', |
| 317 |
'to_type' => 'reply', |
| 318 |
'to_fieldname' => 'post_date_gmt' |
| 319 |
); |
| 320 |
$this->field_map[] = array( |
| 321 |
'from_tablename' => 'forum_posts', |
| 322 |
'from_fieldname' => 'date', |
| 323 |
'to_type' => 'reply', |
| 324 |
'to_fieldname' => 'post_modified' |
| 325 |
); |
| 326 |
$this->field_map[] = array( |
| 327 |
'from_tablename' => 'forum_posts', |
| 328 |
'from_fieldname' => 'date', |
| 329 |
'to_type' => 'reply', |
| 330 |
'to_fieldname' => 'post_modified_gmt' |
| 331 |
); |
| 332 |
|
| 333 |
/** User Section ******************************************************/ |
| 334 |
|
| 335 |
// Store old user id (Stored in usermeta) |
| 336 |
$this->field_map[] = array( |
| 337 |
'from_tablename' => 'users', |
| 338 |
'from_fieldname' => 'ID', |
| 339 |
'to_type' => 'user', |
| 340 |
'to_fieldname' => '_bbp_old_user_id' |
| 341 |
); |
| 342 |
|
| 343 |
// Store old user password (Stored in usermeta) |
| 344 |
$this->field_map[] = array( |
| 345 |
'from_tablename' => 'users', |
| 346 |
'from_fieldname' => 'user_pass', |
| 347 |
'to_type' => 'user', |
| 348 |
'to_fieldname' => '_bbp_password' |
| 349 |
); |
| 350 |
|
| 351 |
// User name. |
| 352 |
$this->field_map[] = array( |
| 353 |
'from_tablename' => 'users', |
| 354 |
'from_fieldname' => 'user_login', |
| 355 |
'to_type' => 'user', |
| 356 |
'to_fieldname' => 'user_login' |
| 357 |
); |
| 358 |
|
| 359 |
// User nice name. |
| 360 |
$this->field_map[] = array( |
| 361 |
'from_tablename' => 'users', |
| 362 |
'from_fieldname' => 'user_nicename', |
| 363 |
'to_type' => 'user', |
| 364 |
'to_fieldname' => 'user_nicename' |
| 365 |
); |
| 366 |
|
| 367 |
// User email. |
| 368 |
$this->field_map[] = array( |
| 369 |
'from_tablename' => 'users', |
| 370 |
'from_fieldname' => 'user_email', |
| 371 |
'to_type' => 'user', |
| 372 |
'to_fieldname' => 'user_email' |
| 373 |
); |
| 374 |
|
| 375 |
// User homepage. |
| 376 |
$this->field_map[] = array( |
| 377 |
'from_tablename' => 'users', |
| 378 |
'from_fieldname' => 'user_url', |
| 379 |
'to_type' => 'user', |
| 380 |
'to_fieldname' => 'user_url' |
| 381 |
); |
| 382 |
|
| 383 |
// User registered. |
| 384 |
$this->field_map[] = array( |
| 385 |
'from_tablename' => 'users', |
| 386 |
'from_fieldname' => 'user_registered', |
| 387 |
'to_type' => 'user', |
| 388 |
'to_fieldname' => 'user_registered' |
| 389 |
); |
| 390 |
|
| 391 |
// User status. |
| 392 |
$this->field_map[] = array( |
| 393 |
'from_tablename' => 'users', |
| 394 |
'from_fieldname' => 'user_status', |
| 395 |
'to_type' => 'user', |
| 396 |
'to_fieldname' => 'user_status' |
| 397 |
); |
| 398 |
|
| 399 |
// User display name. |
| 400 |
$this->field_map[] = array( |
| 401 |
'from_tablename' => 'users', |
| 402 |
'from_fieldname' => 'display_name', |
| 403 |
'to_type' => 'user', |
| 404 |
'to_fieldname' => 'display_name' |
| 405 |
); |
| 406 |
} |
| 407 |
|
| 408 |
/** |
| 409 |
* This method allows us to indicates what is or is not converted for each |
| 410 |
* converter. |
| 411 |
*/ |
| 412 |
public function info() { |
| 413 |
return ''; |
| 414 |
} |
| 415 |
|
| 416 |
/** |
| 417 |
* This method is to save the salt and password together. That |
| 418 |
* way when we authenticate it we can get it out of the database |
| 419 |
* as one value. Array values are auto sanitized by WordPress. |
| 420 |
*/ |
| 421 |
public function callback_savepass( $field, $row ) { |
| 422 |
return false; |
| 423 |
} |
| 424 |
|
| 425 |
/** |
| 426 |
* This method is to take the pass out of the database and compare |
| 427 |
* to a pass the user has typed in. |
| 428 |
*/ |
| 429 |
public function authenticate_pass( $password, $serialized_pass ) { |
| 430 |
return false; |
| 431 |
} |
| 432 |
|
| 433 |
/** |
| 434 |
* Translate the topic status from Mingle numerics to WordPress's strings. |
| 435 |
* |
| 436 |
* @param int $status Mingle v1.x numeric topic status |
| 437 |
* @return string WordPress safe |
| 438 |
*/ |
| 439 |
public function callback_topic_status( $status = 0 ) { |
| 440 |
switch ( $status ) { |
| 441 |
case 1 : |
| 442 |
$status = 'closed'; |
| 443 |
break; |
| 444 |
|
| 445 |
case 0 : |
| 446 |
default : |
| 447 |
$status = 'publish'; |
| 448 |
break; |
| 449 |
} |
| 450 |
return $status; |
| 451 |
} |
| 452 |
|
| 453 |
/** |
| 454 |
* Translate the topic sticky status type from Mingle numerics to WordPress's strings. |
| 455 |
* |
| 456 |
* @param int $status Mingle numeric forum type |
| 457 |
* @return string WordPress safe |
| 458 |
*/ |
| 459 |
public function callback_sticky_status( $status = 0 ) { |
| 460 |
switch ( $status ) { |
| 461 |
case 'sticky' : |
| 462 |
$status = 'sticky'; // Mingle Sticky 'status = sticky' |
| 463 |
break; |
| 464 |
|
| 465 |
case 'open' : |
| 466 |
default : |
| 467 |
$status = 'normal'; // Mingle Normal Topic 'status = open' |
| 468 |
break; |
| 469 |
} |
| 470 |
return $status; |
| 471 |
} |
| 472 |
} |
| 473 |
|