[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/src/includes/admin/converters/ -> XenForo.php (source)

   1  <?php
   2  
   3  /**
   4   * bbPress XenForo Converter
   5   *
   6   * @package bbPress
   7   * @subpackage Converters
   8   */
   9  
  10  /**
  11   *  Implementation of XenForo converter.
  12   *
  13   * @since 2.5.0 bbPress (r5145)
  14   *
  15   * @link Codex Docs https://codex.bbpress.org/import-forums/xenforo
  16   */
  17  class XenForo 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          // Setup smiley URL & path
  33          $this->bbcode_parser_properties = array(
  34              'smiley_url' => false,
  35              'smiley_dir' => false
  36          );
  37  
  38          /** Forum Section *****************************************************/
  39  
  40          // Old forum id (Stored in postmeta)
  41          $this->field_map[] = array(
  42              'from_tablename'  => 'node',
  43              'from_fieldname'  => 'node_id',
  44              'to_type'         => 'forum',
  45              'to_fieldname'    => '_bbp_old_forum_id'
  46          );
  47  
  48          // Forum parent id (If no parent, then 0. Stored in postmeta)
  49          $this->field_map[] = array(
  50              'from_tablename'  => 'node',
  51              'from_fieldname'  => 'parent_node_id',
  52              'to_type'         => 'forum',
  53              'to_fieldname'    => '_bbp_old_forum_parent_id'
  54          );
  55  
  56          // Forum topic count (Stored in postmeta)
  57          // Note: We join the 'forum' table because 'node' does not include topic counts.
  58          $this->field_map[] = array(
  59              'from_tablename'  => 'forum',
  60              'from_fieldname'  => 'discussion_count',
  61              'join_tablename'  => 'node',
  62              'join_type'       => 'LEFT',
  63              'join_expression' => 'USING (node_id) WHERE node.node_type_id = "Category" OR node.node_type_id = "Forum" ',
  64              'to_type'         => 'forum',
  65              'to_fieldname'    => '_bbp_topic_count'
  66          );
  67  
  68          // Forum reply count (Stored in postmeta)
  69          // Note: We join the 'forum' table because 'node' does not include reply counts.
  70          $this->field_map[] = array(
  71              'from_tablename'  => 'forum',
  72              'from_fieldname'  => 'message_count',
  73              'join_tablename'  => 'node',
  74              'join_type'       => 'LEFT',
  75              'join_expression' => 'USING (node_id) WHERE node.node_type_id = "Category" OR node.node_type_id = "Forum" ',
  76              'to_type'         => 'forum',
  77              'to_fieldname'    => '_bbp_reply_count'
  78          );
  79  
  80          // Forum total topic count (Includes unpublished topics, Stored in postmeta)
  81          // Note: We join the 'forum' table because 'node' does not include topic counts.
  82          $this->field_map[] = array(
  83              'from_tablename'  => 'forum',
  84              'from_fieldname'  => 'discussion_count',
  85              'join_tablename'  => 'node',
  86              'join_type'       => 'LEFT',
  87              'join_expression' => 'USING (node_id) WHERE node.node_type_id = "Category" OR node.node_type_id = "Forum" ',
  88              'to_type'         => 'forum',
  89              'to_fieldname'    => '_bbp_total_topic_count'
  90          );
  91  
  92          // Forum total reply count (Includes unpublished replies, Stored in postmeta)
  93          // Note: We join the 'forum' table because 'node' does not include reply counts.
  94          $this->field_map[] = array(
  95              'from_tablename'  => 'forum',
  96              'from_fieldname'  => 'message_count',
  97              'join_tablename'  => 'node',
  98              'join_type'       => 'LEFT',
  99              'join_expression' => 'USING (node_id) WHERE node.node_type_id = "Category" OR node.node_type_id = "Forum" ',
 100              'to_type'         => 'forum',
 101              'to_fieldname'    => '_bbp_total_reply_count'
 102          );
 103  
 104          // Forum title.
 105          $this->field_map[] = array(
 106              'from_tablename' => 'node',
 107              'from_fieldname' => 'title',
 108              'to_type'        => 'forum',
 109              'to_fieldname'   => 'post_title'
 110          );
 111  
 112          // Forum slug (Clean name to avoid conflicts)
 113          // 'node_name' only has slug for explictly named forums
 114          $this->field_map[] = array(
 115              'from_tablename'  => 'node',
 116              'from_fieldname'  => 'node_name',
 117              'to_type'         => 'forum',
 118              'to_fieldname'    => 'post_name',
 119              'callback_method' => 'callback_slug'
 120          );
 121  
 122          // Forum description.
 123          $this->field_map[] = array(
 124              'from_tablename'  => 'node',
 125              'from_fieldname'  => 'description',
 126              'to_type'         => 'forum',
 127              'to_fieldname'    => 'post_content',
 128              'callback_method' => 'callback_null'
 129          );
 130  
 131          // Forum display order (Starts from 1)
 132          $this->field_map[] = array(
 133              'from_tablename' => 'node',
 134              'from_fieldname' => 'display_order',
 135              'to_type'        => 'forum',
 136              'to_fieldname'   => 'menu_order'
 137          );
 138  
 139          // Forum type (Category = Category or Forum = Forum, Stored in postmeta)
 140          $this->field_map[] = array(
 141              'from_tablename'  => 'node',
 142              'from_fieldname'  => 'node_type_id',
 143              'to_type'         => 'forum',
 144              'to_fieldname'    => '_bbp_forum_type',
 145              'callback_method' => 'callback_forum_type'
 146          );
 147  
 148          // Forum status (Unlocked = 1 or Locked = 0, Stored in postmeta)
 149          // Note: We join the 'forum' table because 'node' does not include forum status.
 150          $this->field_map[] = array(
 151              'from_tablename'  => 'forum',
 152              'from_fieldname'  => 'allow_posting',
 153              'join_tablename'  => 'node',
 154              'join_type'       => 'LEFT',
 155              'join_expression' => 'USING (node_id) WHERE node.node_type_id = "Category" OR node.node_type_id = "Forum" ',
 156              'to_type'         => 'forum',
 157              'to_fieldname'    => '_bbp_status',
 158              'callback_method' => 'callback_forum_status'
 159          );
 160  
 161          // Forum dates.
 162          $this->field_map[] = array(
 163              'to_type'      => 'forum',
 164              'to_fieldname' => 'post_date',
 165              'default'      => date('Y-m-d H:i:s')
 166          );
 167          $this->field_map[] = array(
 168              'to_type'      => 'forum',
 169              'to_fieldname' => 'post_date_gmt',
 170              'default'      => date('Y-m-d H:i:s')
 171          );
 172          $this->field_map[] = array(
 173              'to_type'      => 'forum',
 174              'to_fieldname' => 'post_modified',
 175              'default'      => date('Y-m-d H:i:s')
 176          );
 177          $this->field_map[] = array(
 178              'to_type'      => 'forum',
 179              'to_fieldname' => 'post_modified_gmt',
 180              'default'      => date('Y-m-d H:i:s')
 181          );
 182  
 183          /** Forum Subscriptions Section ***************************************/
 184  
 185          // Subscribed forum ID (Stored in usermeta)
 186          $this->field_map[] = array(
 187              'from_tablename'  => 'forum_watch',
 188              'from_fieldname'  => 'node_id',
 189              'to_type'         => 'forum_subscriptions',
 190              'to_fieldname'    => '_bbp_forum_subscriptions'
 191          );
 192  
 193          // Subscribed user ID (Stored in usermeta)
 194          $this->field_map[] = array(
 195              'from_tablename'  => 'forum_watch',
 196              'from_fieldname'  => 'user_id',
 197              'to_type'         => 'forum_subscriptions',
 198              'to_fieldname'    => 'user_id',
 199              'callback_method' => 'callback_userid'
 200          );
 201  
 202          /** Topic Section *****************************************************/
 203  
 204          // Old topic id (Stored in postmeta)
 205          $this->field_map[] = array(
 206              'from_tablename' => 'thread',
 207              'from_fieldname' => 'thread_id',
 208              'to_type'        => 'topic',
 209              'to_fieldname'   => '_bbp_old_topic_id'
 210          );
 211  
 212          // Topic reply count (Stored in postmeta)
 213          $this->field_map[] = array(
 214              'from_tablename'  => 'thread',
 215              'from_fieldname'  => 'reply_count',
 216              'to_type'         => 'topic',
 217              'to_fieldname'    => '_bbp_reply_count',
 218              'callback_method' => 'callback_topic_reply_count'
 219          );
 220  
 221          // Topic total reply count (Includes unpublished replies, Stored in postmeta)
 222          $this->field_map[] = array(
 223              'from_tablename'  => 'thread',
 224              'from_fieldname'  => 'reply_count',
 225              'to_type'         => 'topic',
 226              'to_fieldname'    => '_bbp_total_reply_count',
 227              'callback_method' => 'callback_topic_reply_count'
 228          );
 229  
 230          // Topic parent forum id (If no parent, then 0. Stored in postmeta)
 231          $this->field_map[] = array(
 232              'from_tablename'  => 'thread',
 233              'from_fieldname'  => 'node_id',
 234              'to_type'         => 'topic',
 235              'to_fieldname'    => '_bbp_forum_id',
 236              'callback_method' => 'callback_forumid'
 237          );
 238  
 239          // Topic author.
 240          $this->field_map[] = array(
 241              'from_tablename'  => 'thread',
 242              'from_fieldname'  => 'user_id',
 243              'to_type'         => 'topic',
 244              'to_fieldname'    => 'post_author',
 245              'callback_method' => 'callback_userid'
 246          );
 247  
 248          // Topic author name (Stored in postmeta as _bbp_anonymous_name)
 249          $this->field_map[] = array(
 250              'from_tablename' => 'thread',
 251              'from_fieldname' => 'username',
 252              'to_type'        => 'topic',
 253              'to_fieldname'   => '_bbp_old_topic_author_name_id'
 254          );
 255  
 256          // Is the topic anonymous (Stored in postmeta)
 257          $this->field_map[] = array(
 258              'from_tablename'  => 'thread',
 259              'from_fieldname'  => 'user_id',
 260              'to_type'         => 'topic',
 261              'to_fieldname'    => '_bbp_old_is_topic_anonymous_id',
 262              'callback_method' => 'callback_check_anonymous'
 263          );
 264  
 265          // Topic title.
 266          $this->field_map[] = array(
 267              'from_tablename' => 'thread',
 268              'from_fieldname' => 'title',
 269              'to_type'        => 'topic',
 270              'to_fieldname'   => 'post_title'
 271          );
 272  
 273          // Topic slug (Clean name to avoid conflicts)
 274          $this->field_map[] = array(
 275              'from_tablename'  => 'thread',
 276              'from_fieldname'  => 'title',
 277              'to_type'         => 'topic',
 278              'to_fieldname'    => 'post_name',
 279              'callback_method' => 'callback_slug'
 280          );
 281  
 282          // Topic content.
 283          // Note: We join the 'post' table because 'thread' table does not include content.
 284          $this->field_map[] = array(
 285              'from_tablename'  => 'post',
 286              'from_fieldname'  => 'message',
 287              'join_tablename'  => 'thread',
 288              'join_type'       => 'INNER',
 289              'join_expression' => 'ON thread.first_post_id = post.post_id',
 290              'to_type'         => 'topic',
 291              'to_fieldname'    => 'post_content',
 292              'callback_method' => 'callback_html'
 293          );
 294  
 295          // Topic status (Visible or Deleted)
 296          $this->field_map[] = array(
 297              'from_tablename'  => 'thread',
 298              'from_fieldname'  => 'discussion_state',
 299              'to_type'         => 'topic',
 300              'to_fieldname'    => 'post_status',
 301              'callback_method' => 'callback_status'
 302          );
 303  
 304          // Topic status (Open = 1 or Closed = 0)
 305          $this->field_map[] = array(
 306              'from_tablename'  => 'thread',
 307              'from_fieldname'  => 'discussion_open',
 308              'to_type'         => 'topic',
 309              'to_fieldname'    => '_bbp_old_closed_status_id',
 310              'callback_method' => 'callback_topic_status'
 311          );
 312  
 313          // Topic parent forum id (If no parent, then 0)
 314          $this->field_map[] = array(
 315              'from_tablename'  => 'thread',
 316              'from_fieldname'  => 'node_id',
 317              'to_type'         => 'topic',
 318              'to_fieldname'    => 'post_parent',
 319              'callback_method' => 'callback_forumid'
 320          );
 321  
 322          // Sticky status (Stored in postmeta)
 323          $this->field_map[] = array(
 324              'from_tablename'  => 'thread',
 325              'from_fieldname'  => 'sticky',
 326              'to_type'         => 'topic',
 327              'to_fieldname'    => '_bbp_old_sticky_status_id',
 328              'callback_method' => 'callback_sticky_status'
 329          );
 330  
 331          // Topic dates.
 332          $this->field_map[] = array(
 333              'from_tablename'  => 'thread',
 334              'from_fieldname'  => 'post_date',
 335              'to_type'         => 'topic',
 336              'to_fieldname'    => 'post_date',
 337              'callback_method' => 'callback_datetime'
 338          );
 339          $this->field_map[] = array(
 340              'from_tablename'  => 'thread',
 341              'from_fieldname'  => 'post_date',
 342              'to_type'         => 'topic',
 343              'to_fieldname'    => 'post_date_gmt',
 344              'callback_method' => 'callback_datetime'
 345          );
 346          $this->field_map[] = array(
 347              'from_tablename'  => 'thread',
 348              'from_fieldname'  => 'last_post_date',
 349              'to_type'         => 'topic',
 350              'to_fieldname'    => 'post_modified',
 351              'callback_method' => 'callback_datetime'
 352          );
 353          $this->field_map[] = array(
 354              'from_tablename'  => 'thread',
 355              'from_fieldname'  => 'last_post_date',
 356              'to_type'         => 'topic',
 357              'to_fieldname'    => 'post_modified_gmt',
 358              'callback_method' => 'callback_datetime'
 359          );
 360          $this->field_map[] = array(
 361              'from_tablename'  => 'thread',
 362              'from_fieldname'  => 'last_post_date',
 363              'to_type'         => 'topic',
 364              'to_fieldname'    => '_bbp_last_active_time',
 365              'callback_method' => 'callback_datetime'
 366          );
 367  
 368          /** Tags Section ******************************************************/
 369  
 370          /**
 371           * XenForo Forums do not support topic tags out of the box
 372           */
 373  
 374          /** Topic Subscriptions Section ***************************************/
 375  
 376          // Subscribed topic ID (Stored in usermeta)
 377          $this->field_map[] = array(
 378              'from_tablename'  => 'thread_watch',
 379              'from_fieldname'  => 'thread_id',
 380              'to_type'         => 'topic_subscriptions',
 381              'to_fieldname'    => '_bbp_subscriptions'
 382          );
 383  
 384          // Subscribed user ID (Stored in usermeta)
 385          $this->field_map[] = array(
 386              'from_tablename'  => 'thread_watch',
 387              'from_fieldname'  => 'user_id',
 388              'to_type'         => 'topic_subscriptions',
 389              'to_fieldname'    => 'user_id',
 390              'callback_method' => 'callback_userid'
 391          );
 392  
 393          /** Reply Section *****************************************************/
 394  
 395          // Old reply id (Stored in postmeta)
 396          $this->field_map[] = array(
 397              'from_tablename' => 'post',
 398              'from_fieldname' => 'post_id',
 399              'to_type'        => 'reply',
 400              'to_fieldname'   => '_bbp_old_reply_id'
 401          );
 402  
 403          // Join the 'thread' table to exclude topics from being imported as replies
 404          $this->field_map[] = array(
 405              'from_tablename'  => 'thread',
 406              'from_fieldname'  => 'thread_id',
 407              'join_tablename'  => 'post',
 408              'join_type'       => 'LEFT',
 409              'join_expression' => 'USING (thread_id) WHERE thread.first_post_id != post.post_id',
 410              'to_type'         => 'reply'
 411          );
 412  
 413          // Reply parent forum id (If no parent, then 0. Stored in postmeta)
 414          $this->field_map[] = array(
 415              'from_tablename'  => 'post',
 416              'from_fieldname'  => 'thread_id',
 417              'to_type'         => 'reply',
 418              'to_fieldname'    => '_bbp_forum_id',
 419              'callback_method' => 'callback_topicid_to_forumid'
 420          );
 421  
 422          // Reply parent topic id (If no parent, then 0. Stored in postmeta)
 423          $this->field_map[] = array(
 424              'from_tablename'  => 'post',
 425              'from_fieldname'  => 'thread_id',
 426              'to_type'         => 'reply',
 427              'to_fieldname'    => '_bbp_topic_id',
 428              'callback_method' => 'callback_topicid'
 429          );
 430  
 431          // Reply author.
 432          $this->field_map[] = array(
 433              'from_tablename'  => 'post',
 434              'from_fieldname'  => 'user_id',
 435              'to_type'         => 'reply',
 436              'to_fieldname'    => 'post_author',
 437              'callback_method' => 'callback_userid'
 438          );
 439  
 440          // Reply status (Visible or Deleted)
 441          $this->field_map[] = array(
 442              'from_tablename'  => 'post',
 443              'from_fieldname'  => 'message_state',
 444              'to_type'         => 'reply',
 445              'to_fieldname'    => 'post_status',
 446              'callback_method' => 'callback_status'
 447          );
 448  
 449          // Reply author name (Stored in postmeta as _bbp_anonymous_name)
 450          $this->field_map[] = array(
 451              'from_tablename'  => 'post',
 452              'from_fieldname'  => 'username',
 453              'to_type'         => 'reply',
 454              'to_fieldname'   => '_bbp_old_reply_author_name_id'
 455          );
 456  
 457          // Is the reply anonymous  (Stored in postmeta)
 458          $this->field_map[] = array(
 459              'from_tablename'  => 'post',
 460              'from_fieldname'  => 'user_id',
 461              'to_type'         => 'reply',
 462              'to_fieldname'    => '_bbp_old_is_reply_anonymous_id',
 463              'callback_method' => 'callback_check_anonymous'
 464          );
 465  
 466          // Reply content.
 467          $this->field_map[] = array(
 468              'from_tablename'  => 'post',
 469              'from_fieldname'  => 'message',
 470              'to_type'         => 'reply',
 471              'to_fieldname'    => 'post_content',
 472              'callback_method' => 'callback_html'
 473          );
 474  
 475          // Reply parent topic id (If no parent, then 0)
 476          $this->field_map[] = array(
 477              'from_tablename'  => 'post',
 478              'from_fieldname'  => 'thread_id',
 479              'to_type'         => 'reply',
 480              'to_fieldname'    => 'post_parent',
 481              'callback_method' => 'callback_topicid'
 482          );
 483  
 484          // Reply dates.
 485          $this->field_map[] = array(
 486              'from_tablename'  => 'post',
 487              'from_fieldname'  => 'post_date',
 488              'to_type'         => 'reply',
 489              'to_fieldname'    => 'post_date',
 490              'callback_method' => 'callback_datetime'
 491          );
 492          $this->field_map[] = array(
 493              'from_tablename'  => 'post',
 494              'from_fieldname'  => 'post_date',
 495              'to_type'         => 'reply',
 496              'to_fieldname'    => 'post_date_gmt',
 497              'callback_method' => 'callback_datetime'
 498          );
 499          $this->field_map[] = array(
 500              'from_tablename'  => 'post',
 501              'from_fieldname'  => 'post_date',
 502              'to_type'         => 'reply',
 503              'to_fieldname'    => 'post_modified',
 504              'callback_method' => 'callback_datetime'
 505          );
 506          $this->field_map[] = array(
 507              'from_tablename'  => 'post',
 508              'from_fieldname'  => 'post_date',
 509              'to_type'         => 'reply',
 510              'to_fieldname'    => 'post_modified_gmt',
 511              'callback_method' => 'callback_datetime'
 512          );
 513  
 514          /** User Section ******************************************************/
 515  
 516          // Store old user id (Stored in usermeta)
 517          $this->field_map[] = array(
 518              'from_tablename' => 'user',
 519              'from_fieldname' => 'user_id',
 520              'to_type'        => 'user',
 521              'to_fieldname'   => '_bbp_old_user_id'
 522          );
 523  
 524  /*        // User password.
 525          // Note: We join the 'user_authenticate' table because 'user' does not include password.
 526          $this->field_map[] = array(
 527              'from_tablename'  => 'user_authenticate',
 528              'from_fieldname'  => 'data',
 529              'join_tablename'  => 'user',
 530              'join_type'       => 'LEFT',
 531              'join_expression' => 'USING (user_id)',
 532              'to_type'         => 'user',
 533              'to_fieldname'    => '_bbp_converter_password'
 534          );
 535  
 536          // Store old User password (Stored in usermeta serialized with salt)
 537          $this->field_map[] = array(
 538              'from_tablename'  => 'user',
 539              'from_fieldname'  => 'password',
 540              'to_type'         => 'user',
 541              'to_fieldname'    => '_bbp_password',
 542              'callback_method' => 'callback_savepass'
 543          );
 544  
 545          // Store old User Salt (This is only used for the SELECT row info for the above password save)
 546          $this->field_map[] = array(
 547              'from_tablename' => 'user',
 548              'from_fieldname' => 'salt',
 549              'to_type'        => 'user',
 550              'to_fieldname'   =>   ''
 551          );
 552  */
 553          // User password verify class (Stored in usermeta for verifying password)
 554          $this->field_map[] = array(
 555              'to_type'        => 'user',
 556              'to_fieldname'   => '_bbp_class',
 557              'default'        => 'XenForo'
 558          );
 559  
 560          // User name.
 561          $this->field_map[] = array(
 562              'from_tablename' => 'user',
 563              'from_fieldname' => 'username',
 564              'to_type'        => 'user',
 565              'to_fieldname'   => 'user_login'
 566          );
 567  
 568          // User email.
 569          $this->field_map[] = array(
 570              'from_tablename' => 'user',
 571              'from_fieldname' => 'email',
 572              'to_type'        => 'user',
 573              'to_fieldname'   => 'user_email'
 574          );
 575  
 576          // User homepage.
 577          // Note: We join the 'user_profile' table because 'user' does not include user homepage.
 578          $this->field_map[] = array(
 579              'from_tablename'  => 'user_profile',
 580              'from_fieldname'  => 'homepage',
 581              'join_tablename'  => 'user',
 582              'join_type'       => 'LEFT',
 583              'join_expression' => 'USING (user_id)',
 584              'to_type'         => 'user',
 585              'to_fieldname'    => 'user_url'
 586          );
 587  
 588          // User registered.
 589          $this->field_map[] = array(
 590              'from_tablename'  => 'user',
 591              'from_fieldname'  => 'register_date',
 592              'to_type'         => 'user',
 593              'to_fieldname'    => 'user_registered',
 594              'callback_method' => 'callback_datetime'
 595          );
 596  
 597          // User display name.
 598          $this->field_map[] = array(
 599              'from_tablename' => 'user',
 600              'from_fieldname' => 'username',
 601              'to_type'        => 'user',
 602              'to_fieldname'   => 'display_name'
 603          );
 604  
 605          // Store Custom Title (Stored in usermeta)
 606          $this->field_map[] = array(
 607              'from_tablename'  => 'user',
 608              'from_fieldname'  => 'custom_title',
 609              'to_type'         => 'user',
 610              'to_fieldname'    => '_bbp_xenforo_user_custom_title'
 611          );
 612  
 613          // Store Status (Stored in usermeta)
 614          // Note: We join the 'user_profile' table because 'user' does not include user custom XenForo field user status.
 615          $this->field_map[] = array(
 616              'from_tablename'  => 'user_profile',
 617              'from_fieldname'  => 'status',
 618              'join_tablename'  => 'user',
 619              'join_type'       => 'LEFT',
 620              'join_expression' => 'USING (user_id)',
 621              'to_type'         => 'user',
 622              'to_fieldname'    => '_bbp_xenforo_user_status'
 623          );
 624  
 625          // Store Signature (Stored in usermeta)
 626          // Note: We join the 'user_profile' table because 'user' does not include user custom XenForo field user signature.
 627          $this->field_map[] = array(
 628              'from_tablename'  => 'user_profile',
 629              'from_fieldname'  => 'signature',
 630              'join_tablename'  => 'user',
 631              'join_type'       => 'LEFT',
 632              'join_expression' => 'USING (user_id)',
 633              'to_fieldname'    => '_bbp_xenforo_user_sig',
 634              'to_type'         => 'user',
 635              'callback_method' => 'callback_html'
 636          );
 637  
 638          // Store Location (Stored in usermeta)
 639          // Note: We join the 'user_profile' table because 'user' does not include user custom XenForo field user location.
 640          $this->field_map[] = array(
 641              'from_tablename'  => 'user_profile',
 642              'from_fieldname'  => 'location',
 643              'join_tablename'  => 'user',
 644              'join_type'       => 'LEFT',
 645              'join_expression' => 'USING (user_id)',
 646              'to_type'         => 'user',
 647              'to_fieldname'    => '_bbp_xenforo_user_location'
 648          );
 649  
 650          // Store Occupation (Stored in usermeta)
 651          // Note: We join the 'user_profile' table because 'user' does not include user custom XenForo field user occupation.
 652          $this->field_map[] = array(
 653              'from_tablename'  => 'user_profile',
 654              'from_fieldname'  => 'occupation',
 655              'join_tablename'  => 'user',
 656              'join_type'       => 'LEFT',
 657              'join_expression' => 'USING (user_id)',
 658              'to_type'         => 'user',
 659              'to_fieldname'    => '_bbp_xenforo_user_occupation'
 660          );
 661  
 662          // Store About (Stored in usermeta)
 663          // Note: We join the 'user_profile' table because 'user' does not include user custom XenForo field user about.
 664          $this->field_map[] = array(
 665              'from_tablename'  => 'user_profile',
 666              'from_fieldname'  => 'about',
 667              'join_tablename'  => 'user',
 668              'join_type'       => 'LEFT',
 669              'join_expression' => 'USING (user_id)',
 670              'to_type'         => 'user',
 671              'to_fieldname'    => '_bbp_xenforo_user_about',
 672              'callback_method' => 'callback_html'
 673          );
 674      }
 675  
 676      /**
 677       * This method allows us to indicates what is or is not converted for each
 678       * converter.
 679       */
 680  	public function info() {
 681          return '';
 682      }
 683  
 684      /**
 685       * This method is to save the salt and password together.  That
 686       * way when we authenticate it we can get it out of the database
 687       * as one value. Array values are auto sanitized by WordPress.
 688       */
 689  	public function translate_savepass( $field, $row ) {
 690          $pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
 691          return $pass_array;
 692      }
 693  
 694      /**
 695       * This method is to take the pass out of the database and compare
 696       * to a pass the user has typed in.
 697       */
 698  	public function authenticate_pass( $password, $serialized_pass ) {
 699          $pass_array = unserialize( $serialized_pass );
 700          switch ( $pass_array['hashFunc'] ) {
 701              case 'sha256':
 702                  return ( $pass_array['hash'] == hash( 'sha256', hash( 'sha256', $password ) . $pass_array['salt'] ) );
 703              case 'sha1':
 704                  return ( $pass_array['hash'] == sha1( sha1( $password ) . $pass_array['salt'] ) );
 705          }
 706      }
 707  
 708      /**
 709       * Translate the forum type from XenForo Capitalised case to WordPress's non-capatilise case strings.
 710       *
 711       * @param int $status XenForo numeric forum type
 712       * @return string WordPress safe
 713       */
 714  	public function callback_forum_type( $status = 1 ) {
 715          switch ( $status ) {
 716              case 'Category' :
 717                  $status = 'category';
 718                  break;
 719  
 720              case 'Forum' :
 721              default :
 722                  $status = 'forum';
 723                  break;
 724          }
 725          return $status;
 726      }
 727  
 728      /**
 729       * Translate the forum status from XenForo numerics to WordPress's strings.
 730       *
 731       * @param int $status XenForo numeric forum status
 732       * @return string WordPress safe
 733       */
 734  	public function callback_forum_status( $status = 1 ) {
 735          switch ( $status ) {
 736              case 0 :
 737                  $status = 'closed';
 738                  break;
 739  
 740              case 1 :
 741              default :
 742                  $status = 'open';
 743                  break;
 744          }
 745          return $status;
 746      }
 747  
 748      /**
 749       * Translate the post status from XenForo to WordPress' strings.
 750       *
 751       * @param int $status XenForo post status
 752       * @return string WordPress safe
 753       */
 754  	public function callback_status( $status = 1 ) {
 755          switch ( $status ) {
 756              case 'deleted' :
 757                  $status = 'pending'; // bbp_get_pending_status_id()
 758                  break;
 759  
 760              case 'visible'  :
 761              default :
 762                  $status = 'publish'; // bbp_get_public_status_id()
 763                  break;
 764          }
 765          return $status;
 766      }
 767  
 768      /**
 769       * Translate the topic status from XenForo numerics to WordPress's strings.
 770       *
 771       * @param int $status XenForo numeric topic status
 772       * @return string WordPress safe
 773       */
 774  	public function callback_topic_status( $status = 1 ) {
 775          switch ( $status ) {
 776              case 0 :
 777                  $status = 'closed';
 778                  break;
 779  
 780              case 1 :
 781              default :
 782                  $status = 'publish';
 783                  break;
 784          }
 785          return $status;
 786      }
 787  
 788      /**
 789       * Translate the topic sticky status type from XenForo numerics to WordPress's strings.
 790       *
 791       * @param int $status XenForo numeric forum type
 792       * @return string WordPress safe
 793       */
 794  	public function callback_sticky_status( $status = 0 ) {
 795          switch ( $status ) {
 796              case 1 :
 797                  $status = 'sticky';       // XenForo Sticky 'sticky = 1'
 798                  break;
 799  
 800              case 0  :
 801              default :
 802                  $status = 'normal';       // XenForo Normal Topic 'sticky = 0'
 803                  break;
 804          }
 805          return $status;
 806      }
 807  
 808      /**
 809       * Verify the topic reply count.
 810       *
 811       * @param int $count XenForo reply count
 812       * @return string WordPress safe
 813       */
 814  	public function callback_topic_reply_count( $count = 1 ) {
 815          $count = absint( (int) $count - 1 );
 816          return $count;
 817      }
 818  
 819      /**
 820       * This callback processes any custom parser.php attributes and custom code with preg_replace
 821       */
 822  	protected function callback_html( $field ) {
 823  
 824          // Strips Xenforo custom HTML first from $field before parsing $field to parser.php
 825          $xenforo_markup = $field;
 826          $xenforo_markup = html_entity_decode( $xenforo_markup );
 827  
 828          // Replace '[QUOTE]' with '<blockquote>'
 829          $xenforo_markup = preg_replace( '/\[QUOTE\]/', '<blockquote>', $xenforo_markup );
 830          // Replace '[/QUOTE]' with '</blockquote>'
 831          $xenforo_markup = preg_replace( '/\[\/QUOTE\]/', '</blockquote>', $xenforo_markup );
 832          // Replace '[QUOTE=User Name($1)]' with '<em>@$1 wrote:</em><blockquote>"
 833          $xenforo_markup = preg_replace( '/\[quote=\"(.*?)\,\spost\:\s(.*?)\,\s\member\:\s(.*?)\"\](.*?)\[\/quote\]/', '<em>@$1 wrote:</em><blockquote>', $xenforo_markup );
 834          // Replace '[/quote]' with '</blockquote>'
 835          $xenforo_markup = preg_replace( '/\[\/quote\]/', '</blockquote>', $xenforo_markup );
 836  
 837          // Replace '[media=youtube]$1[/media]' with '$1"
 838          $xenforo_markup = preg_replace( '/\[media\=youtube\](.*?)\[\/media\]/', 'https://youtu.be/$1', $xenforo_markup );
 839          // Replace '[media=dailymotion]$1[/media]' with '$1"
 840          $xenforo_markup = preg_replace( '/\[media\=dailymotion\](.*?)\[\/media\]/', 'https://www.dailymotion.com/video/$1', $xenforo_markup );
 841          // Replace '[media=vimeo]$1[/media]' with '$1"
 842          $xenforo_markup = preg_replace( '/\[media\=vimeo\](.*?)\[\/media\]/', 'https://vimeo.com/$1', $xenforo_markup );
 843  
 844          // Now that Xenforo custom HTML has been stripped put the cleaned HTML back in $field
 845          $field = $xenforo_markup;
 846  
 847          // Parse out any bbCodes in $field with the BBCode 'parser.php'
 848          return parent::callback_html( $field );
 849      }
 850  }


Generated: Fri Apr 26 01:01:04 2024 Cross-referenced by PHPXref 0.7.1