| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* bbPress SMF Converter |
| 5 |
* |
| 6 |
* @package bbPress |
| 7 |
* @subpackage Converters |
| 8 |
*/ |
| 9 |
|
| 10 |
/** |
| 11 |
* Implementation of SMF Forum converter. |
| 12 |
* |
| 13 |
* @since 2.5.0 bbPress (r5189) |
| 14 |
* |
| 15 |
* @link Codex Docs https://codex.bbpress.org/import-forums/smf |
| 16 |
*/ |
| 17 |
class SMF 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' => 'boards', |
| 35 |
'from_fieldname' => 'id_board', |
| 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' => 'boards', |
| 43 |
'from_fieldname' => 'id_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' => 'boards', |
| 51 |
'from_fieldname' => 'num_topics', |
| 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' => 'boards', |
| 59 |
'from_fieldname' => 'num_posts', |
| 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' => 'boards', |
| 67 |
'from_fieldname' => 'num_topics', |
| 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' => 'boards', |
| 75 |
'from_fieldname' => 'num_posts', |
| 76 |
'to_type' => 'forum', |
| 77 |
'to_fieldname' => '_bbp_total_reply_count' |
| 78 |
); |
| 79 |
|
| 80 |
// Forum title. |
| 81 |
$this->field_map[] = array( |
| 82 |
'from_tablename' => 'boards', |
| 83 |
'from_fieldname' => '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' => 'boards', |
| 91 |
'from_fieldname' => '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' => 'boards', |
| 100 |
'from_fieldname' => 'description', |
| 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' => 'boards', |
| 109 |
'from_fieldname' => 'board_order', |
| 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' => 'forum', |
| 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' => 'forum', |
| 136 |
'to_fieldname' => 'post_date_gmt', |
| 137 |
'default' => gmdate( 'Y-m-d H:i:s' ) |
| 138 |
); |
| 139 |
$this->field_map[] = array( |
| 140 |
'to_type' => 'forum', |
| 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' => 'forum', |
| 146 |
'to_fieldname' => 'post_modified_gmt', |
| 147 |
'default' => gmdate( 'Y-m-d H:i:s' ) |
| 148 |
); |
| 149 |
|
| 150 |
/** Forum Subscriptions Section ***************************************/ |
| 151 |
|
| 152 |
// Subscribed forum ID (Stored in usermeta) |
| 153 |
$this->field_map[] = array( |
| 154 |
'from_tablename' => 'log_notify', |
| 155 |
'from_fieldname' => 'id_board', |
| 156 |
'from_expression' => 'WHERE log_notify.id_board != 0', |
| 157 |
'to_type' => 'forum_subscriptions', |
| 158 |
'to_fieldname' => '_bbp_forum_subscriptions' |
| 159 |
); |
| 160 |
|
| 161 |
// Subscribed user ID (Stored in usermeta) |
| 162 |
$this->field_map[] = array( |
| 163 |
'from_tablename' => 'log_notify', |
| 164 |
'from_fieldname' => 'id_member', |
| 165 |
'from_expression' => 'WHERE log_notify.id_board != 0', |
| 166 |
'to_type' => 'forum_subscriptions', |
| 167 |
'to_fieldname' => 'user_id', |
| 168 |
'callback_method' => 'callback_userid' |
| 169 |
); |
| 170 |
|
| 171 |
/** Topic Section ******************************************************/ |
| 172 |
|
| 173 |
// Old topic id (Stored in postmeta) |
| 174 |
$this->field_map[] = array( |
| 175 |
'from_tablename' => 'topics', |
| 176 |
'from_fieldname' => 'id_topic', |
| 177 |
'to_type' => 'topic', |
| 178 |
'to_fieldname' => '_bbp_old_topic_id' |
| 179 |
); |
| 180 |
|
| 181 |
// Topic reply count (Stored in postmeta) |
| 182 |
$this->field_map[] = array( |
| 183 |
'from_tablename' => 'topics', |
| 184 |
'from_fieldname' => 'num_replies', |
| 185 |
'to_type' => 'topic', |
| 186 |
'to_fieldname' => '_bbp_reply_count', |
| 187 |
'callback_method' => 'callback_topic_reply_count' |
| 188 |
); |
| 189 |
|
| 190 |
// Topic total reply count (Includes unpublished replies, Stored in postmeta) |
| 191 |
$this->field_map[] = array( |
| 192 |
'from_tablename' => 'topics', |
| 193 |
'from_fieldname' => 'num_replies', |
| 194 |
'to_type' => 'topic', |
| 195 |
'to_fieldname' => '_bbp_total_reply_count', |
| 196 |
'callback_method' => 'callback_topic_reply_count' |
| 197 |
); |
| 198 |
|
| 199 |
// Topic parent forum id (If no parent, then 0. Stored in postmeta) |
| 200 |
$this->field_map[] = array( |
| 201 |
'from_tablename' => 'topics', |
| 202 |
'from_fieldname' => 'id_board', |
| 203 |
'to_type' => 'topic', |
| 204 |
'to_fieldname' => '_bbp_forum_id', |
| 205 |
'callback_method' => 'callback_forumid' |
| 206 |
); |
| 207 |
|
| 208 |
// Topic author. |
| 209 |
$this->field_map[] = array( |
| 210 |
'from_tablename' => 'topics', |
| 211 |
'from_fieldname' => 'id_member_started', |
| 212 |
'to_type' => 'topic', |
| 213 |
'to_fieldname' => 'post_author', |
| 214 |
'callback_method' => 'callback_userid' |
| 215 |
); |
| 216 |
|
| 217 |
// Topic author name (Stored in postmeta as _bbp_anonymous_name) |
| 218 |
$this->field_map[] = array( |
| 219 |
'from_tablename' => 'messages', |
| 220 |
'from_fieldname' => 'poster_name', |
| 221 |
'join_tablename' => 'topics', |
| 222 |
'join_type' => 'LEFT', |
| 223 |
'join_expression' => 'ON topics.id_first_msg = messages.id_msg', |
| 224 |
'to_type' => 'topic', |
| 225 |
'to_fieldname' => '_bbp_old_topic_author_name_id' |
| 226 |
); |
| 227 |
|
| 228 |
// Is the topic anonymous (Stored in postmeta) |
| 229 |
$this->field_map[] = array( |
| 230 |
'from_tablename' => 'topics', |
| 231 |
'from_fieldname' => 'id_member_started', |
| 232 |
'to_type' => 'topic', |
| 233 |
'to_fieldname' => '_bbp_old_is_topic_anonymous_id', |
| 234 |
'callback_method' => 'callback_check_anonymous' |
| 235 |
); |
| 236 |
|
| 237 |
// Topic Author ip (Stored in postmeta) |
| 238 |
$this->field_map[] = array( |
| 239 |
'from_tablename' => 'messages', |
| 240 |
'from_fieldname' => 'poster_ip', |
| 241 |
'join_tablename' => 'topics', |
| 242 |
'join_type' => 'LEFT', |
| 243 |
'join_expression' => 'ON topics.id_first_msg = messages.id_msg', |
| 244 |
'to_type' => 'topic', |
| 245 |
'to_fieldname' => '_bbp_author_ip' |
| 246 |
); |
| 247 |
|
| 248 |
// Topic content. |
| 249 |
// Note: We join the 'messages' table because 'topics' table does not have content. |
| 250 |
$this->field_map[] = array( |
| 251 |
'from_tablename' => 'messages', |
| 252 |
'from_fieldname' => 'body', |
| 253 |
'join_tablename' => 'topics', |
| 254 |
'join_type' => 'LEFT', |
| 255 |
'join_expression' => 'ON topics.id_first_msg = messages.id_msg', |
| 256 |
'to_type' => 'topic', |
| 257 |
'to_fieldname' => 'post_content', |
| 258 |
'callback_method' => 'callback_html' |
| 259 |
); |
| 260 |
|
| 261 |
// Topic title. |
| 262 |
$this->field_map[] = array( |
| 263 |
'from_tablename' => 'messages', |
| 264 |
'from_fieldname' => 'subject', |
| 265 |
'join_tablename' => 'topics', |
| 266 |
'join_type' => 'LEFT', |
| 267 |
'join_expression' => 'ON topics.id_first_msg = messages.id_msg', |
| 268 |
'to_type' => 'topic', |
| 269 |
'to_fieldname' => 'post_title' |
| 270 |
); |
| 271 |
|
| 272 |
// Topic slug (Clean name to avoid conflicts) |
| 273 |
$this->field_map[] = array( |
| 274 |
'from_tablename' => 'messages', |
| 275 |
'from_fieldname' => 'subject', |
| 276 |
'join_tablename' => 'topics', |
| 277 |
'join_type' => 'LEFT', |
| 278 |
'join_expression' => 'ON topics.id_first_msg = messages.id_msg', |
| 279 |
'to_type' => 'topic', |
| 280 |
'to_fieldname' => 'post_name', |
| 281 |
'callback_method' => 'callback_slug' |
| 282 |
); |
| 283 |
|
| 284 |
// Topic parent forum id (If no parent, then 0) |
| 285 |
$this->field_map[] = array( |
| 286 |
'from_tablename' => 'topics', |
| 287 |
'from_fieldname' => 'id_board', |
| 288 |
'to_type' => 'topic', |
| 289 |
'to_fieldname' => 'post_parent', |
| 290 |
'callback_method' => 'callback_forumid' |
| 291 |
); |
| 292 |
|
| 293 |
// Topic status (Open or Closed, SMF v2.0.4 0=open & 1=closed) |
| 294 |
$this->field_map[] = array( |
| 295 |
'from_tablename' => 'topics', |
| 296 |
'from_fieldname' => 'locked', |
| 297 |
'to_type' => 'topic', |
| 298 |
'to_fieldname' => '_bbp_old_closed_status_id', |
| 299 |
'callback_method' => 'callback_topic_status' |
| 300 |
); |
| 301 |
|
| 302 |
// Sticky status (Stored in postmeta) |
| 303 |
$this->field_map[] = array( |
| 304 |
'from_tablename' => 'topics', |
| 305 |
'from_fieldname' => 'is_sticky', |
| 306 |
'to_type' => 'topic', |
| 307 |
'to_fieldname' => '_bbp_old_sticky_status_id', |
| 308 |
'callback_method' => 'callback_sticky_status' |
| 309 |
); |
| 310 |
|
| 311 |
// Topic dates. |
| 312 |
$this->field_map[] = array( |
| 313 |
'from_tablename' => 'messages', |
| 314 |
'from_fieldname' => 'poster_time', |
| 315 |
'join_tablename' => 'topics', |
| 316 |
'join_type' => 'LEFT', |
| 317 |
'join_expression' => 'ON topics.id_first_msg = messages.id_msg', |
| 318 |
'to_type' => 'topic', |
| 319 |
'to_fieldname' => 'post_date', |
| 320 |
'callback_method' => 'callback_datetime' |
| 321 |
); |
| 322 |
$this->field_map[] = array( |
| 323 |
'from_tablename' => 'messages', |
| 324 |
'from_fieldname' => 'poster_time', |
| 325 |
'join_tablename' => 'topics', |
| 326 |
'join_type' => 'LEFT', |
| 327 |
'join_expression' => 'ON topics.id_first_msg = messages.id_msg', |
| 328 |
'to_type' => 'topic', |
| 329 |
'to_fieldname' => 'post_date_gmt', |
| 330 |
'callback_method' => 'callback_datetime' |
| 331 |
); |
| 332 |
$this->field_map[] = array( |
| 333 |
'from_tablename' => 'messages', |
| 334 |
'from_fieldname' => 'poster_time', |
| 335 |
'join_tablename' => 'topics', |
| 336 |
'join_type' => 'LEFT', |
| 337 |
'join_expression' => 'ON topics.id_first_msg = messages.id_msg', |
| 338 |
'to_type' => 'topic', |
| 339 |
'to_fieldname' => 'post_modified', |
| 340 |
'callback_method' => 'callback_datetime' |
| 341 |
); |
| 342 |
$this->field_map[] = array( |
| 343 |
'from_tablename' => 'messages', |
| 344 |
'from_fieldname' => 'poster_time', |
| 345 |
'join_tablename' => 'topics', |
| 346 |
'join_type' => 'LEFT', |
| 347 |
'join_expression' => 'ON topics.id_first_msg = messages.id_msg', |
| 348 |
'to_type' => 'topic', |
| 349 |
'to_fieldname' => 'post_modified_gmt', |
| 350 |
'callback_method' => 'callback_datetime' |
| 351 |
); |
| 352 |
$this->field_map[] = array( |
| 353 |
'from_tablename' => 'messages', |
| 354 |
'from_fieldname' => 'poster_time', |
| 355 |
'join_tablename' => 'topics', |
| 356 |
'join_type' => 'LEFT', |
| 357 |
'join_expression' => 'ON topics.id_first_msg = messages.id_msg', |
| 358 |
'to_type' => 'topic', |
| 359 |
'to_fieldname' => '_bbp_last_active_time', |
| 360 |
'callback_method' => 'callback_datetime' |
| 361 |
); |
| 362 |
|
| 363 |
/** Tags Section ******************************************************/ |
| 364 |
|
| 365 |
/** |
| 366 |
* SMF v2.0.4 Forums do not support topic tags out of the box |
| 367 |
*/ |
| 368 |
|
| 369 |
/** Topic Subscriptions Section ***************************************/ |
| 370 |
|
| 371 |
// Subscribed topic ID (Stored in usermeta) |
| 372 |
$this->field_map[] = array( |
| 373 |
'from_tablename' => 'log_notify', |
| 374 |
'from_fieldname' => 'id_topic', |
| 375 |
'from_expression' => 'WHERE log_notify.id_topic != 0', |
| 376 |
'to_type' => 'topic_subscriptions', |
| 377 |
'to_fieldname' => '_bbp_subscriptions' |
| 378 |
); |
| 379 |
|
| 380 |
// Subscribed user ID (Stored in usermeta) |
| 381 |
$this->field_map[] = array( |
| 382 |
'from_tablename' => 'log_notify', |
| 383 |
'from_fieldname' => 'id_member', |
| 384 |
'from_expression' => 'WHERE log_notify.id_topic != 0', |
| 385 |
'to_type' => 'topic_subscriptions', |
| 386 |
'to_fieldname' => 'user_id', |
| 387 |
'callback_method' => 'callback_userid' |
| 388 |
); |
| 389 |
|
| 390 |
/** Reply Section *****************************************************/ |
| 391 |
|
| 392 |
// Old reply id (Stored in postmeta) |
| 393 |
$this->field_map[] = array( |
| 394 |
'from_tablename' => 'messages', |
| 395 |
'from_fieldname' => 'id_msg', |
| 396 |
'to_type' => 'reply', |
| 397 |
'to_fieldname' => '_bbp_old_reply_id' |
| 398 |
); |
| 399 |
|
| 400 |
// Reply parent forum id (If no parent, then 0. Stored in postmeta) |
| 401 |
$this->field_map[] = array( |
| 402 |
'from_tablename' => 'topics', |
| 403 |
'from_fieldname' => 'id_board', |
| 404 |
'join_tablename' => 'messages', |
| 405 |
'join_type' => 'LEFT', |
| 406 |
'join_expression' => 'USING (id_topic) WHERE topics.id_first_msg != messages.id_msg', |
| 407 |
'to_type' => 'reply', |
| 408 |
'to_fieldname' => '_bbp_forum_id', |
| 409 |
'callback_method' => 'callback_topicid_to_forumid' |
| 410 |
); |
| 411 |
|
| 412 |
// Reply parent topic id (If no parent, then 0. Stored in postmeta) |
| 413 |
$this->field_map[] = array( |
| 414 |
'from_tablename' => 'messages', |
| 415 |
'from_fieldname' => 'id_topic', |
| 416 |
'to_type' => 'reply', |
| 417 |
'to_fieldname' => '_bbp_topic_id', |
| 418 |
'callback_method' => 'callback_topicid' |
| 419 |
); |
| 420 |
|
| 421 |
// Reply author ip (Stored in postmeta) |
| 422 |
$this->field_map[] = array( |
| 423 |
'from_tablename' => 'messages', |
| 424 |
'from_fieldname' => 'poster_ip', |
| 425 |
'to_type' => 'reply', |
| 426 |
'to_fieldname' => '_bbp_author_ip' |
| 427 |
); |
| 428 |
|
| 429 |
// Reply author. |
| 430 |
$this->field_map[] = array( |
| 431 |
'from_tablename' => 'messages', |
| 432 |
'from_fieldname' => 'id_member', |
| 433 |
'to_type' => 'reply', |
| 434 |
'to_fieldname' => 'post_author', |
| 435 |
'callback_method' => 'callback_userid' |
| 436 |
); |
| 437 |
|
| 438 |
// Reply author name (Stored in postmeta as _bbp_anonymous_name) |
| 439 |
$this->field_map[] = array( |
| 440 |
'from_tablename' => 'messages', |
| 441 |
'from_fieldname' => 'poster_name', |
| 442 |
'to_type' => 'reply', |
| 443 |
'to_fieldname' => '_bbp_old_reply_author_name_id' |
| 444 |
); |
| 445 |
|
| 446 |
// Is the reply anonymous (Stored in postmeta) |
| 447 |
$this->field_map[] = array( |
| 448 |
'from_tablename' => 'messages', |
| 449 |
'from_fieldname' => 'id_member', |
| 450 |
'to_type' => 'reply', |
| 451 |
'to_fieldname' => '_bbp_old_is_reply_anonymous_id', |
| 452 |
'callback_method' => 'callback_check_anonymous' |
| 453 |
); |
| 454 |
|
| 455 |
// Reply content. |
| 456 |
$this->field_map[] = array( |
| 457 |
'from_tablename' => 'messages', |
| 458 |
'from_fieldname' => 'body', |
| 459 |
'to_type' => 'reply', |
| 460 |
'to_fieldname' => 'post_content', |
| 461 |
'callback_method' => 'callback_html' |
| 462 |
); |
| 463 |
|
| 464 |
// Reply parent topic id (If no parent, then 0) |
| 465 |
$this->field_map[] = array( |
| 466 |
'from_tablename' => 'messages', |
| 467 |
'from_fieldname' => 'id_topic', |
| 468 |
'to_type' => 'reply', |
| 469 |
'to_fieldname' => 'post_parent', |
| 470 |
'callback_method' => 'callback_topicid' |
| 471 |
); |
| 472 |
|
| 473 |
// Reply dates. |
| 474 |
$this->field_map[] = array( |
| 475 |
'from_tablename' => 'messages', |
| 476 |
'from_fieldname' => 'poster_time', |
| 477 |
'to_type' => 'reply', |
| 478 |
'to_fieldname' => 'post_date', |
| 479 |
'callback_method' => 'callback_datetime' |
| 480 |
); |
| 481 |
$this->field_map[] = array( |
| 482 |
'from_tablename' => 'messages', |
| 483 |
'from_fieldname' => 'poster_time', |
| 484 |
'to_type' => 'reply', |
| 485 |
'to_fieldname' => 'post_date_gmt', |
| 486 |
'callback_method' => 'callback_datetime' |
| 487 |
); |
| 488 |
$this->field_map[] = array( |
| 489 |
'from_tablename' => 'messages', |
| 490 |
'from_fieldname' => 'poster_time', |
| 491 |
'to_type' => 'reply', |
| 492 |
'to_fieldname' => 'post_modified', |
| 493 |
'callback_method' => 'callback_datetime' |
| 494 |
); |
| 495 |
$this->field_map[] = array( |
| 496 |
'from_tablename' => 'messages', |
| 497 |
'from_fieldname' => 'poster_time', |
| 498 |
'to_type' => 'reply', |
| 499 |
'to_fieldname' => 'post_modified_gmt', |
| 500 |
'callback_method' => 'callback_datetime' |
| 501 |
); |
| 502 |
|
| 503 |
/** User Section ******************************************************/ |
| 504 |
|
| 505 |
// Store old user id (Stored in usermeta) |
| 506 |
$this->field_map[] = array( |
| 507 |
'from_tablename' => 'members', |
| 508 |
'from_fieldname' => 'id_member', |
| 509 |
'to_type' => 'user', |
| 510 |
'to_fieldname' => '_bbp_old_user_id' |
| 511 |
); |
| 512 |
|
| 513 |
// Store old user password (Stored in usermeta serialized with salt) |
| 514 |
$this->field_map[] = array( |
| 515 |
'from_tablename' => 'members', |
| 516 |
'from_fieldname' => 'passwd', |
| 517 |
'to_type' => 'user', |
| 518 |
'to_fieldname' => '_bbp_password', |
| 519 |
'callback_method' => 'callback_savepass' |
| 520 |
); |
| 521 |
|
| 522 |
// User password verify class (Stored in usermeta for verifying password) |
| 523 |
$this->field_map[] = array( |
| 524 |
'to_type' => 'user', |
| 525 |
'to_fieldname' => '_bbp_class', |
| 526 |
'default' => 'SMF' |
| 527 |
); |
| 528 |
|
| 529 |
// User name. |
| 530 |
$this->field_map[] = array( |
| 531 |
'from_tablename' => 'members', |
| 532 |
'from_fieldname' => 'member_name', |
| 533 |
'to_type' => 'user', |
| 534 |
'to_fieldname' => 'user_login' |
| 535 |
); |
| 536 |
|
| 537 |
// User nice name. |
| 538 |
$this->field_map[] = array( |
| 539 |
'from_tablename' => 'members', |
| 540 |
'from_fieldname' => 'member_name', |
| 541 |
'to_type' => 'user', |
| 542 |
'to_fieldname' => 'user_nicename' |
| 543 |
); |
| 544 |
|
| 545 |
// User email. |
| 546 |
$this->field_map[] = array( |
| 547 |
'from_tablename' => 'members', |
| 548 |
'from_fieldname' => 'email_address', |
| 549 |
'to_type' => 'user', |
| 550 |
'to_fieldname' => 'user_email' |
| 551 |
); |
| 552 |
|
| 553 |
// User homepage. |
| 554 |
$this->field_map[] = array( |
| 555 |
'from_tablename' => 'members', |
| 556 |
'from_fieldname' => 'website_url', |
| 557 |
'to_type' => 'user', |
| 558 |
'to_fieldname' => 'user_url' |
| 559 |
); |
| 560 |
|
| 561 |
// User registered. |
| 562 |
$this->field_map[] = array( |
| 563 |
'from_tablename' => 'members', |
| 564 |
'from_fieldname' => 'date_registered', |
| 565 |
'to_type' => 'user', |
| 566 |
'to_fieldname' => 'user_registered', |
| 567 |
'callback_method' => 'callback_datetime' |
| 568 |
); |
| 569 |
|
| 570 |
// User display name. |
| 571 |
$this->field_map[] = array( |
| 572 |
'from_tablename' => 'members', |
| 573 |
'from_fieldname' => 'real_name', |
| 574 |
'to_type' => 'user', |
| 575 |
'to_fieldname' => 'display_name' |
| 576 |
); |
| 577 |
|
| 578 |
// User AIM (Stored in usermeta) |
| 579 |
$this->field_map[] = array( |
| 580 |
'from_tablename' => 'members', |
| 581 |
'from_fieldname' => 'aim', |
| 582 |
'to_type' => 'user', |
| 583 |
'to_fieldname' => '_bbp_smf_user_aim' |
| 584 |
); |
| 585 |
|
| 586 |
// User Yahoo (Stored in usermeta) |
| 587 |
$this->field_map[] = array( |
| 588 |
'from_tablename' => 'members', |
| 589 |
'from_fieldname' => 'yim', |
| 590 |
'to_type' => 'user', |
| 591 |
'to_fieldname' => '_bbp_smf_user_yim' |
| 592 |
); |
| 593 |
|
| 594 |
// Store ICQ (Stored in usermeta) |
| 595 |
$this->field_map[] = array( |
| 596 |
'from_tablename' => 'members', |
| 597 |
'from_fieldname' => 'icq', |
| 598 |
'to_type' => 'user', |
| 599 |
'to_fieldname' => '_bbp_smf_user_icq' |
| 600 |
); |
| 601 |
|
| 602 |
// Store MSN (Stored in usermeta) |
| 603 |
$this->field_map[] = array( |
| 604 |
'from_tablename' => 'members', |
| 605 |
'from_fieldname' => 'msn', |
| 606 |
'to_type' => 'user', |
| 607 |
'to_fieldname' => '_bbp_smf_user_msn' |
| 608 |
); |
| 609 |
|
| 610 |
// Store Signature (Stored in usermeta) |
| 611 |
$this->field_map[] = array( |
| 612 |
'from_tablename' => 'members', |
| 613 |
'from_fieldname' => 'signature', |
| 614 |
'to_type' => 'user', |
| 615 |
'to_fieldname' => '_bbp_smf_user_sig', |
| 616 |
'callback_method' => 'callback_html' |
| 617 |
); |
| 618 |
|
| 619 |
// Store Avatar (Stored in usermeta) |
| 620 |
$this->field_map[] = array( |
| 621 |
'from_tablename' => 'members', |
| 622 |
'from_fieldname' => 'avatar', |
| 623 |
'to_type' => 'user', |
| 624 |
'to_fieldname' => '_bbp_smf_user_avatar', |
| 625 |
'callback_method' => 'callback_html' |
| 626 |
); |
| 627 |
|
| 628 |
// Store Location (Stored in usermeta) |
| 629 |
$this->field_map[] = array( |
| 630 |
'from_tablename' => 'members', |
| 631 |
'from_fieldname' => 'location', |
| 632 |
'to_type' => 'user', |
| 633 |
'to_fieldname' => '_bbp_smf_user_location', |
| 634 |
'callback_method' => 'callback_html' |
| 635 |
); |
| 636 |
|
| 637 |
// Store Personal Text (Stored in usermeta) |
| 638 |
$this->field_map[] = array( |
| 639 |
'from_tablename' => 'members', |
| 640 |
'from_fieldname' => 'personal_text', |
| 641 |
'to_type' => 'user', |
| 642 |
'to_fieldname' => '_bbp_smf_user_personal_text', |
| 643 |
'callback_method' => 'callback_html' |
| 644 |
); |
| 645 |
} |
| 646 |
|
| 647 |
/** |
| 648 |
* This method allows us to indicates what is or is not converted for each |
| 649 |
* converter. |
| 650 |
*/ |
| 651 |
public function info() { |
| 652 |
return ''; |
| 653 |
} |
| 654 |
|
| 655 |
/** |
| 656 |
* This method is to save the salt and password together. That |
| 657 |
* way when we authenticate it we can get it out of the database |
| 658 |
* as one value. Array values are auto sanitized by WordPress. |
| 659 |
*/ |
| 660 |
public function callback_savepass( $field, $row ) { |
| 661 |
$pass_array = array( |
| 662 |
'hash' => $field, |
| 663 |
'username' => $row['member_name'] |
| 664 |
); |
| 665 |
|
| 666 |
return $pass_array; |
| 667 |
} |
| 668 |
|
| 669 |
/** |
| 670 |
* This method is to take the pass out of the database and compare |
| 671 |
* to a pass the user has typed in. |
| 672 |
*/ |
| 673 |
public function authenticate_pass( $password, $serialized_pass ) { |
| 674 |
|
| 675 |
// Unserialize the password, with safeguards |
| 676 |
$pass_array = unserialize( |
| 677 |
$serialized_pass, |
| 678 |
array( |
| 679 |
'allowed_classes' => false, |
| 680 |
'max_depth' => 1, |
| 681 |
) |
| 682 |
); |
| 683 |
|
| 684 |
// Bail if missing values |
| 685 |
if ( ! is_array( $pass_array ) || ! isset( $pass_array['hash'], $pass_array['username'] ) ) { |
| 686 |
return false; |
| 687 |
} |
| 688 |
|
| 689 |
// Return comparison |
| 690 |
return hash_equals( |
| 691 |
$pass_array['hash'], |
| 692 |
sha1( strtolower( $pass_array['username'] ) . $password ) |
| 693 |
); |
| 694 |
} |
| 695 |
|
| 696 |
/** |
| 697 |
* Translate the post status from SMF v2.0.4 numerics to WordPress's strings. |
| 698 |
* |
| 699 |
* @param int $status SMF v2.0.4 numeric topic status |
| 700 |
* @return string WordPress safe |
| 701 |
*/ |
| 702 |
public function callback_topic_status( $status = 0 ) { |
| 703 |
switch ( $status ) { |
| 704 |
case 1 : |
| 705 |
$status = 'closed'; |
| 706 |
break; |
| 707 |
|
| 708 |
case 0 : |
| 709 |
default : |
| 710 |
$status = 'publish'; |
| 711 |
break; |
| 712 |
} |
| 713 |
return $status; |
| 714 |
} |
| 715 |
|
| 716 |
/** |
| 717 |
* Translate the topic sticky status type from SMF v2.0.4 numerics to WordPress's strings. |
| 718 |
* |
| 719 |
* @param int $status SMF v2.0.4 numeric forum type |
| 720 |
* @return string WordPress safe |
| 721 |
*/ |
| 722 |
public function callback_sticky_status( $status = 0 ) { |
| 723 |
switch ( $status ) { |
| 724 |
case 1 : |
| 725 |
$status = 'sticky'; // SMF Sticky 'is_sticky = 1' |
| 726 |
break; |
| 727 |
|
| 728 |
case 0 : |
| 729 |
default : |
| 730 |
$status = 'normal'; // SMF normal topic 'is_sticky = 0' |
| 731 |
break; |
| 732 |
} |
| 733 |
return $status; |
| 734 |
} |
| 735 |
|
| 736 |
/** |
| 737 |
* Verify the topic/reply count. |
| 738 |
* |
| 739 |
* @param int $count SMF v2.0.4 topic/reply counts |
| 740 |
* @return string WordPress safe |
| 741 |
*/ |
| 742 |
public function callback_topic_reply_count( $count = 1 ) { |
| 743 |
$count = absint( (int) $count - 1 ); |
| 744 |
return $count; |
| 745 |
} |
| 746 |
|
| 747 |
/** |
| 748 |
* This callback processes any custom parser.php attributes and custom code with preg_replace |
| 749 |
* |
| 750 |
* @param string $field HTML field |
| 751 |
*/ |
| 752 |
protected function callback_html( $field ) { |
| 753 |
|
| 754 |
// Strips SMF custom HTML first from $field before parsing $field to parser.php |
| 755 |
$smf_markup = $field; |
| 756 |
$smf_markup = html_entity_decode( $smf_markup ); |
| 757 |
|
| 758 |
// Replace '[quote]' with '<blockquote>' |
| 759 |
$smf_markup = preg_replace( '/\[quote\]/', '<blockquote>', $smf_markup ); |
| 760 |
// Replace '[quote ($1)]' with '<blockquote>" |
| 761 |
$smf_markup = preg_replace( '/\[quote (.*?)\]/', '<blockquote>', $smf_markup ); |
| 762 |
// Replace '[/quote]' with '</blockquote>' |
| 763 |
$smf_markup = preg_replace( '/\[\/quote\]/', '</blockquote>', $smf_markup ); |
| 764 |
|
| 765 |
// Replace '[glow]' with '' |
| 766 |
$smf_markup = preg_replace( '/\[glow\]/', '', $smf_markup ); |
| 767 |
// Replace '[glow]' with '' |
| 768 |
$smf_markup = preg_replace( '/\[glow=(.*?)\]/', '', $smf_markup ); |
| 769 |
// Replace '[/glow]' with '' |
| 770 |
$smf_markup = preg_replace( '/\[\/glow\]/', '', $smf_markup ); |
| 771 |
|
| 772 |
// Replace '[shadow]' with '' |
| 773 |
$smf_markup = preg_replace( '/\[shadow\]/', '', $smf_markup ); |
| 774 |
// Replace '[shadow]' with '' |
| 775 |
$smf_markup = preg_replace( '/\[shadow=(.*?)\]/', '', $smf_markup ); |
| 776 |
// Replace '[/shadow]' with '' |
| 777 |
$smf_markup = preg_replace( '/\[\/shadow\]/', '', $smf_markup ); |
| 778 |
|
| 779 |
// Replace '[move]' with '' |
| 780 |
$smf_markup = preg_replace( '/\[move\]/', '', $smf_markup ); |
| 781 |
// Replace '[/move]' with '' |
| 782 |
$smf_markup = preg_replace( '/\[\/move\]/', '', $smf_markup ); |
| 783 |
|
| 784 |
// Replace '[table]' with '<table>' |
| 785 |
$smf_markup = preg_replace( '/\[table\]/', '<table>', $smf_markup ); |
| 786 |
// Replace '[/table]' with '</table>' |
| 787 |
$smf_markup = preg_replace( '/\[\/table\]/', '</table>', $smf_markup ); |
| 788 |
// Replace '[tr]' with '<tr>' |
| 789 |
$smf_markup = preg_replace( '/\[tr\]/', '<tr>', $smf_markup ); |
| 790 |
// Replace '[/tr]' with '</tr>' |
| 791 |
$smf_markup = preg_replace( '/\[\/tr\]/', '</tr>', $smf_markup ); |
| 792 |
// Replace '[td]' with '<td>' |
| 793 |
$smf_markup = preg_replace( '/\[td\]/', '<td>', $smf_markup ); |
| 794 |
// Replace '[/td]' with '</td>' |
| 795 |
$smf_markup = preg_replace( '/\[\/td\]/', '</td>', $smf_markup ); |
| 796 |
|
| 797 |
// Replace '[list]' with '<ul>' |
| 798 |
$smf_markup = preg_replace( '/\[list\]/', '<ul>', $smf_markup ); |
| 799 |
// Replace '[liist type=decimal]' with '<ol type="a">' |
| 800 |
$smf_markup = preg_replace( '/\[list\ type=decimal\]/', '<ol type="a">', $smf_markup ); |
| 801 |
// Replace '[li]' with '<li>' |
| 802 |
$smf_markup = preg_replace( '/\[li\]/', '<li>', $smf_markup ); |
| 803 |
// Replace '[/li]' with '</li>' |
| 804 |
$smf_markup = preg_replace( '/\[\/li\]/', '</li>', $smf_markup ); |
| 805 |
|
| 806 |
// Replace '[tt]' with '<tt>' |
| 807 |
$smf_markup = preg_replace( '/\[tt\]/', '<tt>', $smf_markup ); |
| 808 |
// Replace '[/tt]' with '</tt>' |
| 809 |
$smf_markup = preg_replace( '/\[\/tt\]/', '</tt>', $smf_markup ); |
| 810 |
|
| 811 |
// Replace '<br />' with '<br>' |
| 812 |
$smf_markup = preg_replace( '/\<br \/\>/', '<br>', $smf_markup ); |
| 813 |
|
| 814 |
// Replace '[size=$1]' with '<span style="font-size:$1%;">$3</span>' |
| 815 |
$smf_markup = preg_replace( '/\[size=(.*?)\]/', '<span style="font-size:$1">', $smf_markup ); |
| 816 |
// Replace '[/size]' with '</span>' |
| 817 |
$smf_markup = preg_replace( '/\[\/size\]/', '</span>', $smf_markup ); |
| 818 |
|
| 819 |
// Replace non-break space ' ' with space ' ' |
| 820 |
$smf_markup = preg_replace( '/ /', ' ', $smf_markup ); |
| 821 |
|
| 822 |
// Now that SMF custom HTML has been stripped put the cleaned HTML back in $field |
| 823 |
$field = $smf_markup; |
| 824 |
|
| 825 |
// Parse out any bbCodes in $field with the BBCode 'parser.php' |
| 826 |
return parent::callback_html( $field ); |
| 827 |
} |
| 828 |
} |
| 829 |
|