[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * bbPress SimplePress5 Converter
   5   *
   6   * @package bbPress
   7   * @subpackage Converters
   8   */
   9  
  10  /**
  11   * Implementation of SimplePress v5 converter.
  12   *
  13   * @since 2.3.0 bbPress (r4638)
  14   *
  15   * @link Codex Docs https://codex.bbpress.org/import-forums/simplepress/
  16   */
  17  class SimplePress5 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' => 'sfforums',
  43              'from_fieldname' => 'forum_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' => 'sfforums',
  51              'from_fieldname' => 'parent',
  52              'to_type'        => 'forum',
  53              'to_fieldname'   => '_bbp_old_forum_parent_id'
  54          );
  55  
  56          // Forum topic count (Stored in postmeta)
  57          $this->field_map[] = array(
  58              'from_tablename' => 'sfforums',
  59              'from_fieldname' => 'topic_count',
  60              'to_type'        => 'forum',
  61              'to_fieldname'   => '_bbp_topic_count'
  62          );
  63  
  64          // Forum reply count (Stored in postmeta)
  65          $this->field_map[] = array(
  66              'from_tablename' => 'sfforums',
  67              'from_fieldname' => 'post_count',
  68              'to_type'        => 'forum',
  69              'to_fieldname'   => '_bbp_reply_count'
  70          );
  71  
  72          // Forum total topic count (Stored in postmeta)
  73          $this->field_map[] = array(
  74              'from_tablename' => 'sfforums',
  75              'from_fieldname' => 'topic_count',
  76              'to_type'        => 'forum',
  77              'to_fieldname'   => '_bbp_total_topic_count'
  78          );
  79  
  80          // Forum total reply count (Stored in postmeta)
  81          $this->field_map[] = array(
  82              'from_tablename' => 'sfforums',
  83              'from_fieldname' => 'post_count',
  84              'to_type'        => 'forum',
  85              'to_fieldname'   => '_bbp_total_reply_count'
  86          );
  87  
  88          // Forum title.
  89          $this->field_map[] = array(
  90              'from_tablename' => 'sfforums',
  91              'from_fieldname' => 'forum_name',
  92              'to_type'        => 'forum',
  93              'to_fieldname'   => 'post_title'
  94          );
  95  
  96          // Forum slug (Clean name to avoid conflicts)
  97          $this->field_map[] = array(
  98              'from_tablename'  => 'sfforums',
  99              'from_fieldname'  => 'forum_name',
 100              'to_type'         => 'forum',
 101              'to_fieldname'    => 'post_name',
 102              'callback_method' => 'callback_slug'
 103          );
 104  
 105          // Forum description.
 106          $this->field_map[] = array(
 107              'from_tablename'  => 'sfforums',
 108              'from_fieldname'  => 'forum_desc',
 109              'to_type'         => 'forum',
 110              'to_fieldname'    => 'post_content',
 111              'callback_method' => 'callback_null'
 112          );
 113  
 114          // Forum display order (Starts from 1)
 115          $this->field_map[] = array(
 116              'from_tablename' => 'sfforums',
 117              'from_fieldname' => 'forum_seq',
 118              'to_type'        => 'forum',
 119              'to_fieldname'   => 'menu_order'
 120          );
 121  
 122          // Forum type (Set a default value 'forum', Stored in postmeta)
 123          $this->field_map[] = array(
 124              'to_type'      => 'forum',
 125              'to_fieldname' => '_bbp_forum_type',
 126              'default'      => 'forum'
 127          );
 128  
 129          // Forum status (Set a default value 'open', Stored in postmeta)
 130          $this->field_map[] = array(
 131              'to_type'      => 'forum',
 132              'to_fieldname' => '_bbp_status',
 133              'default'      => 'open'
 134          );
 135  
 136          // Forum dates.
 137          $this->field_map[] = array(
 138              'to_type'      => 'forums',
 139              'to_fieldname' => 'post_date',
 140              'default'      => date('Y-m-d H:i:s')
 141          );
 142          $this->field_map[] = array(
 143              'to_type'      => 'forums',
 144              'to_fieldname' => 'post_date_gmt',
 145              'default'      => date('Y-m-d H:i:s')
 146          );
 147          $this->field_map[] = array(
 148              'to_type'      => 'forums',
 149              'to_fieldname' => 'post_modified',
 150              'default'      => date('Y-m-d H:i:s')
 151          );
 152          $this->field_map[] = array(
 153              'to_type'      => 'forums',
 154              'to_fieldname' => 'post_modified_gmt',
 155              'default'      => date('Y-m-d H:i:s')
 156          );
 157  
 158          /** Topic Section *****************************************************/
 159  
 160          // Old topic id (Stored in postmeta)
 161          $this->field_map[] = array(
 162              'from_tablename' => 'sftopics',
 163              'from_fieldname' => 'topic_id',
 164              'to_type'        => 'topic',
 165              'to_fieldname'   => '_bbp_old_topic_id'
 166          );
 167  
 168          // Topic reply count (Stored in postmeta)
 169          $this->field_map[] = array(
 170              'from_tablename' => 'sftopics',
 171              'from_fieldname' => 'post_count',
 172              'to_type'        => 'topic',
 173              'to_fieldname'   => '_bbp_reply_count',
 174              'callback_method' => 'callback_topic_reply_count'
 175          );
 176  
 177          // Topic parent forum id (If no parent, then 0. Stored in postmeta)
 178          $this->field_map[] = array(
 179              'from_tablename'  => 'sftopics',
 180              'from_fieldname'  => 'forum_id',
 181              'to_type'         => 'topic',
 182              'to_fieldname'    => '_bbp_forum_id',
 183              'callback_method' => 'callback_forumid'
 184          );
 185  
 186          // Topic author.
 187          $this->field_map[] = array(
 188              'from_tablename'  => 'sftopics',
 189              'from_fieldname'  => 'user_id',
 190              'to_type'         => 'topic',
 191              'to_fieldname'    => 'post_author',
 192              'callback_method' => 'callback_userid'
 193          );
 194  
 195          // Topic author ip (Stored in postmeta)
 196          $this->field_map[] = array(
 197              'from_tablename'  => 'sfposts',
 198              'from_fieldname'  => 'poster_ip',
 199              'join_tablename'  => 'sftopics',
 200              'join_type'       => 'INNER',
 201              'join_expression' => 'USING (topic_id) WHERE sfposts.post_index = 1',
 202              'to_type'         => 'topic',
 203              'to_fieldname'    => '_bbp_author_ip'
 204          );
 205  
 206          // Topic author name (Stored in postmeta as _bbp_anonymous_name)
 207          $this->field_map[] = array(
 208              'from_tablename'  => 'sfposts',
 209              'from_fieldname'  => 'guest_name',
 210              'join_tablename'  => 'sftopics',
 211              'join_type'       => 'INNER',
 212              'join_expression' => 'USING (topic_id) WHERE sfposts.post_index = 1',
 213              'to_type'         => 'topic',
 214              'to_fieldname'    => '_bbp_old_topic_author_name_id'
 215          );
 216  
 217          // Is the topic anonymous (Stored in postmeta)
 218          $this->field_map[] = array(
 219              'from_tablename'  => 'sftopics',
 220              'from_fieldname'  => 'user_id',
 221              'to_type'         => 'topic',
 222              'to_fieldname'    => '_bbp_old_is_topic_anonymous_id',
 223              'callback_method' => 'callback_check_anonymous'
 224          );
 225  
 226          // Topic content.
 227          // Note: We join the sfposts table because sftopics do not have content.
 228          $this->field_map[] = array(
 229              'from_tablename'  => 'sfposts',
 230              'from_fieldname'  => 'post_content',
 231              'join_tablename'  => 'sftopics',
 232              'join_type'       => 'INNER',
 233              'join_expression' => 'USING (topic_id) WHERE sfposts.post_index = 1',
 234              'to_type'         => 'topic',
 235              'to_fieldname'    => 'post_content',
 236              'callback_method' => 'callback_html'
 237          );
 238  
 239          // Topic title.
 240          $this->field_map[] = array(
 241              'from_tablename' => 'sftopics',
 242              'from_fieldname' => 'topic_name',
 243              'to_type'        => 'topic',
 244              'to_fieldname'   => 'post_title'
 245          );
 246  
 247          // Topic slug (Clean name to avoid conflicts)
 248          $this->field_map[] = array(
 249              'from_tablename'  => 'sftopics',
 250              'from_fieldname'  => 'topic_name',
 251              'to_type'         => 'topic',
 252              'to_fieldname'    => 'post_name',
 253              'callback_method' => 'callback_slug'
 254          );
 255  
 256          // Topic parent forum id (If no parent, then 0)
 257          $this->field_map[] = array(
 258              'from_tablename'  => 'sftopics',
 259              'from_fieldname'  => 'forum_id',
 260              'to_type'         => 'topic',
 261              'to_fieldname'    => 'post_parent',
 262              'callback_method' => 'callback_forumid'
 263          );
 264  
 265          // Topic status (Open or Closed)
 266          $this->field_map[] = array(
 267              'from_tablename'  => 'sftopics',
 268              'from_fieldname'  => 'topic_status',
 269              'to_type'         => 'topic',
 270              'to_fieldname'    => '_bbp_old_closed_status_id',
 271              'callback_method' => 'callback_status'
 272          );
 273  
 274          // Sticky status (Stored in postmeta)
 275          $this->field_map[] = array(
 276              'from_tablename'  => 'sftopics',
 277              'from_fieldname'  => 'topic_pinned',
 278              'to_type'         => 'topic',
 279              'to_fieldname'    => '_bbp_old_sticky_status_id',
 280              'callback_method' => 'callback_sticky_status'
 281          );
 282  
 283          // Topic dates.
 284          $this->field_map[] = array(
 285              'from_tablename'  => 'sftopics',
 286              'from_fieldname'  => 'topic_date',
 287              'to_type'         => 'topic',
 288              'to_fieldname'    => 'post_date'
 289          );
 290          $this->field_map[] = array(
 291              'from_tablename'  => 'sftopics',
 292              'from_fieldname'  => 'topic_date',
 293              'to_type'         => 'topic',
 294              'to_fieldname'    => 'post_date_gmt'
 295          );
 296          $this->field_map[] = array(
 297              'from_tablename'  => 'sftopics',
 298              'from_fieldname'  => 'topic_date',
 299              'to_type'         => 'topic',
 300              'to_fieldname'    => 'post_modified'
 301          );
 302          $this->field_map[] = array(
 303              'from_tablename'  => 'sftopics',
 304              'from_fieldname'  => 'topic_date',
 305              'to_type'         => 'topic',
 306              'to_fieldname'    => 'post_modified_gmt'
 307          );
 308          $this->field_map[] = array(
 309              'from_tablename'  => 'sftopics',
 310              'from_fieldname'  => 'topic_date',
 311              'to_type'         => 'topic',
 312              'to_fieldname'    => '_bbp_last_active_time'
 313          );
 314  
 315          /** Tags Section ******************************************************/
 316  
 317          /**
 318           * SimplePress Forums do not support topic tags without paid extensions
 319           */
 320  
 321          /** Reply Section *****************************************************/
 322  
 323          // Old reply id (Stored in postmeta)
 324          $this->field_map[] = array(
 325              'from_tablename' => 'sfposts',
 326              'from_fieldname' => 'post_id',
 327              'to_type'        => 'reply',
 328              'to_fieldname'   => '_bbp_old_reply_id'
 329          );
 330  
 331          // Reply parent forum id (If no parent, then 0. Stored in postmeta)
 332          $this->field_map[] = array(
 333              'from_tablename'  => 'sfposts',
 334              'from_fieldname'  => 'forum_id',
 335              'from_expression' => 'WHERE post_index != 1',
 336              'to_type'         => 'reply',
 337              'to_fieldname'    => '_bbp_forum_id',
 338              'callback_method' => 'callback_forumid'
 339          );
 340  
 341          // Reply parent topic id (If no parent, then 0. Stored in postmeta)
 342          $this->field_map[] = array(
 343              'from_tablename'  => 'sfposts',
 344              'from_fieldname'  => 'topic_id',
 345              'to_type'         => 'reply',
 346              'to_fieldname'    => '_bbp_topic_id',
 347              'callback_method' => 'callback_topicid'
 348          );
 349  
 350          // Reply author ip (Stored in postmeta)
 351          $this->field_map[] = array(
 352              'from_tablename' => 'sfposts',
 353              'from_fieldname' => 'poster_ip',
 354              'to_type'        => 'reply',
 355              'to_fieldname'   => '_bbp_author_ip'
 356          );
 357  
 358          // Reply author.
 359          $this->field_map[] = array(
 360              'from_tablename'  => 'sfposts',
 361              'from_fieldname'  => 'user_id',
 362              'to_type'         => 'reply',
 363              'to_fieldname'    => 'post_author',
 364              'callback_method' => 'callback_userid'
 365          );
 366  
 367          // Reply author name (Stored in postmeta as _bbp_anonymous_name)
 368          $this->field_map[] = array(
 369              'from_tablename'  => 'sfposts',
 370              'from_fieldname'  => 'guest_name',
 371              'to_type'         => 'reply',
 372              'to_fieldname'    => '_bbp_old_reply_author_name_id'
 373          );
 374  
 375          // Is the reply anonymous (Stored in postmeta)
 376          $this->field_map[] = array(
 377              'from_tablename'  => 'sfposts',
 378              'from_fieldname'  => 'user_id',
 379              'to_type'         => 'reply',
 380              'to_fieldname'    => '_bbp_old_is_reply_anonymous_id',
 381              'callback_method' => 'callback_check_anonymous'
 382          );
 383  
 384          // Reply content.
 385          $this->field_map[] = array(
 386              'from_tablename'  => 'sfposts',
 387              'from_fieldname'  => 'post_content',
 388              'to_type'         => 'reply',
 389              'to_fieldname'    => 'post_content',
 390              'callback_method' => 'callback_html'
 391          );
 392  
 393          // Reply parent topic id (If no parent, then 0)
 394          $this->field_map[] = array(
 395              'from_tablename'  => 'sfposts',
 396              'from_fieldname'  => 'topic_id',
 397              'to_type'         => 'reply',
 398              'to_fieldname'    => 'post_parent',
 399              'callback_method' => 'callback_topicid'
 400          );
 401  
 402          // Reply dates.
 403          $this->field_map[] = array(
 404              'from_tablename'  => 'sfposts',
 405              'from_fieldname'  => 'post_date',
 406              'to_type'         => 'reply',
 407              'to_fieldname'    => 'post_date'
 408          );
 409          $this->field_map[] = array(
 410              'from_tablename'  => 'sfposts',
 411              'from_fieldname'  => 'post_date',
 412              'to_type'         => 'reply',
 413              'to_fieldname'    => 'post_date_gmt'
 414          );
 415          $this->field_map[] = array(
 416              'from_tablename'  => 'sfposts',
 417              'from_fieldname'  => 'post_date',
 418              'to_type'         => 'reply',
 419              'to_fieldname'    => 'post_modified'
 420          );
 421          $this->field_map[] = array(
 422              'from_tablename'  => 'sfposts',
 423              'from_fieldname'  => 'post_date',
 424              'to_type'         => 'reply',
 425              'to_fieldname'    => 'post_modified_gmt'
 426          );
 427  
 428          /** User Section ******************************************************/
 429  
 430          // Store old user id (Stored in usermeta)
 431          $this->field_map[] = array(
 432              'from_tablename' => 'users',
 433              'from_fieldname' => 'ID',
 434              'to_type'        => 'user',
 435              'to_fieldname'   => '_bbp_old_user_id'
 436          );
 437  
 438          // Store old user password (Stored in usermeta)
 439          $this->field_map[] = array(
 440              'from_tablename' => 'users',
 441              'from_fieldname' => 'user_pass',
 442              'to_type'        => 'user',
 443              'to_fieldname'   => '_bbp_password'
 444          );
 445  
 446          // User name.
 447          $this->field_map[] = array(
 448              'from_tablename' => 'users',
 449              'from_fieldname' => 'user_login',
 450              'to_type'        => 'user',
 451              'to_fieldname'   => 'user_login'
 452          );
 453  
 454          // User nice name.
 455          $this->field_map[] = array(
 456              'from_tablename' => 'users',
 457              'from_fieldname' => 'user_nicename',
 458              'to_type'        => 'user',
 459              'to_fieldname'   => 'user_nicename'
 460          );
 461  
 462          // User email.
 463          $this->field_map[] = array(
 464              'from_tablename' => 'users',
 465              'from_fieldname' => 'user_email',
 466              'to_type'        => 'user',
 467              'to_fieldname'   => 'user_email'
 468          );
 469  
 470          // User homepage.
 471          $this->field_map[] = array(
 472              'from_tablename' => 'users',
 473              'from_fieldname' => 'user_url',
 474              'to_type'        => 'user',
 475              'to_fieldname'   => 'user_url'
 476          );
 477  
 478          // User registered.
 479          $this->field_map[] = array(
 480              'from_tablename' => 'users',
 481              'from_fieldname' => 'user_registered',
 482              'to_type'        => 'user',
 483              'to_fieldname'   => 'user_registered'
 484          );
 485  
 486          // User status.
 487          $this->field_map[] = array(
 488              'from_tablename' => 'users',
 489              'from_fieldname' => 'user_status',
 490              'to_type'        => 'user',
 491              'to_fieldname'   => 'user_status'
 492          );
 493  
 494          // User display name.
 495          $this->field_map[] = array(
 496              'from_tablename' => 'users',
 497              'from_fieldname' => 'display_name',
 498              'to_type'        => 'user',
 499              'to_fieldname'   => 'display_name'
 500          );
 501      }
 502  
 503      /**
 504       * This method allows us to indicates what is or is not converted for each
 505       * converter.
 506       */
 507  	public function info() {
 508          return '';
 509      }
 510  
 511      /**
 512       * This method is to save the salt and password together. That
 513       * way when we authenticate it we can get it out of the database
 514       * as one value. Array values are auto sanitized by WordPress.
 515       */
 516  	public function callback_savepass( $field, $row ) {
 517          return false;
 518      }
 519  
 520      /**
 521       * This method is to take the pass out of the database and compare
 522       * to a pass the user has typed in.
 523       */
 524  	public function authenticate_pass( $password, $serialized_pass ) {
 525          return false;
 526      }
 527  
 528      /**
 529       * Translate the post status from Simple:Press v5.x numerics to WordPress's strings.
 530       *
 531       * @param int $status Simple:Press numeric status
 532       * @return string WordPress safe
 533       */
 534  	public function callback_status( $status = 0 ) {
 535          switch ( $status ) {
 536              case 1 :
 537                  $status = 'closed';
 538                  break;
 539  
 540              case 0  :
 541              default :
 542                  $status = 'publish';
 543                  break;
 544          }
 545          return $status;
 546      }
 547  
 548      /**
 549       * Translate the topic sticky status type from Simple:Press v5.x numerics to WordPress's strings.
 550       *
 551       * @param int $status Simple:Press v5.x numeric forum type
 552       * @return string WordPress safe
 553       */
 554  	public function callback_sticky_status( $status = 0 ) {
 555          switch ( $status ) {
 556              case 1 :
 557                  $status = 'sticky';       // Simple:Press Sticky 'topic_sticky = 1'
 558                  break;
 559  
 560              case 0  :
 561              default :
 562                  $status = 'normal';       // Simple:Press Normal Topic 'topic_sticky = 0'
 563                  break;
 564          }
 565          return $status;
 566      }
 567  
 568      /**
 569       * Verify the topic reply count.
 570       *
 571       * @param int $count Simple:Press v5.x reply count
 572       * @return string WordPress safe
 573       */
 574  	public function callback_topic_reply_count( $count = 1 ) {
 575          $count = absint( (int) $count - 1 );
 576          return $count;
 577      }
 578  
 579      /**
 580       * This callback processes any custom parser.php attributes and custom HTML code with preg_replace
 581       */
 582  	protected function callback_html( $field ) {
 583  
 584          // Strip any custom HTML not supported by parser.php first from $field before parsing $field to parser.php
 585          $simplepress_markup = $field;
 586          $simplepress_markup = html_entity_decode( $simplepress_markup );
 587  
 588          // Replace any SimplePress smilies from path '/sp-resources/forum-smileys/sf-smily.gif' with the equivelant WordPress Smilie
 589          $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-confused\.gif(.*?)\" \/>/',     ':?',      $simplepress_markup );
 590          $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-cool\.gif(.*?)\" \/>/',        ':cool:',   $simplepress_markup );
 591          $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-cry\.gif(.*?)\" \/>/',         ':cry:',    $simplepress_markup );
 592          $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-embarassed\.gif(.*?)\" \/>/',  ':oops:',   $simplepress_markup );
 593          $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-frown\.gif(.*?)\" \/>/',       ':(',       $simplepress_markup );
 594          $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-kiss\.gif(.*?)\" \/>/',        ':P',       $simplepress_markup );
 595          $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-laugh\.gif(.*?)\" \/>/',       ':D',       $simplepress_markup );
 596          $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-smile\.gif(.*?)\" \/>/',       ':smile:',  $simplepress_markup );
 597          $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-surprised\.gif(.*?)\" \/>/',   ':o',       $simplepress_markup );
 598          $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-wink\.gif(.*?)\" \/>/',        ':wink:',   $simplepress_markup );
 599          $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-yell\.gif(.*?)\" \/>/',         ':x',      $simplepress_markup );
 600  
 601          // Replace '<div class="sfcode">example code</div>' with '<code>*</code>'
 602          $simplepress_markup = preg_replace( '/\<div class\=\"sfcode\"\>(.*?)\<\/div\>/', '<code>$1</code>', $simplepress_markup );
 603  
 604          // Replace '<strong>username said </strong>' with '@username said:'
 605          $simplepress_markup = preg_replace( '/\<strong\>(.*?)\ said\ \<\/strong\>/',     '@$1 said:',        $simplepress_markup );
 606  
 607          // Replace '<p>&nbsp;</p>' with '<p>&nbsp;</p>'
 608          $simplepress_markup = preg_replace( '/\n(&nbsp;|[\s\p{Z}\xA0\x{00A0}]+)\r/', '<br>', $simplepress_markup );
 609  
 610          // Now that SimplePress' custom HTML codes have been stripped put the cleaned HTML back in $field
 611          $field = $simplepress_markup;
 612  
 613          // Parse out any bbCodes in $field with the BBCode 'parser.php'
 614          return parent::callback_html( $field );
 615      }
 616  }


Generated: Thu Mar 28 01:00:51 2024 Cross-referenced by PHPXref 0.7.1