Skip to:
Content

bbPress.org

Changeset 4693


Ignore:
Timestamp:
01/22/2013 03:45:39 AM (14 years ago)
Author:
johnjamesjacoby
Message:

Improvements to SimplePress5 importer. Props netweb. Fixes #2164.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/admin/converters/SimplePress5.php

    r4639 r4693  
    22
    33/**
    4  * SimplePress 5 converter.
     4 * Implementation of SimplePress v5 converter.
    55 *
    66 * @since bbPress (r4638)
    77 */
    88class SimplePress5 extends BBP_Converter_Base {
     9
     10        /**
     11         * Main Constructor
     12         *
     13         * @uses SimplePress5::setup_globals()
     14         */
    915        function __construct() {
    1016                parent::__construct();
     
    1218        }
    1319
     20        /**
     21         * Sets up the field mappings
     22         */
    1423        public function setup_globals() {
    1524
    1625                /** Forum Section ******************************************************/
    1726
    18                 // Forum id. Stored in postmeta.
     27                // Forum id (Stored in postmeta)
    1928                $this->field_map[] = array(
    2029                        'from_tablename' => 'sfforums',
     
    2433                );
    2534
    26                 // Forum parent id.  If no parent, than 0. Stored in postmeta.
     35                // Forum parent id (If no parent, than 0, Stored in postmeta)
    2736                $this->field_map[] = array(
    2837                        'from_tablename' => 'sfforums',
     
    4049                );
    4150
    42                 // Forum slug. Clean name.
     51                // Forum slug (Clean name to avoid conflicts)
    4352                $this->field_map[] = array(
    4453                        'from_tablename'  => 'sfforums',
     
    5867                );
    5968
    60                 // Forum display order.  Starts from 1.
     69                // Forum display order (Starts from 1)
    6170                $this->field_map[] = array(
    6271                        'from_tablename' => 'sfforums',
     
    9099                /** Topic Section ******************************************************/
    91100
    92                 // Topic id. Stored in postmeta.
     101                // Topic id (Stored in postmeta)
    93102                $this->field_map[] = array(
    94103                        'from_tablename' => 'sftopics',
     
    98107                );
    99108
    100                 // Forum id. Stored in postmeta.
     109                // Forum id (Stored in postmeta)
    101110                $this->field_map[] = array(
    102111                        'from_tablename'  => 'sftopics',
     
    117126
    118127                // Topic content.
     128                // Note: We join the sfposts table because sftopics do not have content.
    119129                $this->field_map[] = array(
    120130                        'from_tablename'  => 'sfposts',
     
    136146                );
    137147
    138                 // Topic slug. Clean name.
     148                // Topic slug (Clean name to avoid conflicts)
    139149                $this->field_map[] = array(
    140150                        'from_tablename'  => 'sftopics',
     
    145155                );
    146156
    147                 // Forum id.  If no parent, than 0.
     157                // Forum id (If no parent, than 0)
    148158                $this->field_map[] = array(
    149159                        'from_tablename'  => 'sftopics',
     
    182192                        'to_fieldname'    => 'post_modified_gmt',
    183193                        'callback_method' => 'callback_datetime'
     194                );
     195
     196                // Topic status (Open or Closed)
     197                $this->field_map[] = array(
     198                        'from_tablename'  => 'sftopics',
     199                        'from_fieldname'  => 'topic_status',
     200                        'to_type'         => 'topic',
     201                        'to_fieldname'    => 'post_status',
     202                        'callback_method' => 'callback_status'
    184203                );
    185204
     
    207226                */
    208227
    209                 /** Post Section ******************************************************/
    210 
    211                 // Post id. Stores in postmeta.
     228                /** Reply Section *****************************************************/
     229
     230                // Post id (Stored in postmeta)
    212231                $this->field_map[] = array(
    213232                        'from_tablename' => 'sfposts',
     
    227246                );
    228247
    229                 // Forum id. Stores in postmeta.
     248                // Forum id (Stored in postmeta)
    230249                $this->field_map[] = array(
    231250                        'from_tablename'  => 'sfposts',
     
    236255                );
    237256
    238                 // Topic id. Stores in postmeta.
     257                // Topic id (Stored in postmeta)
    239258                $this->field_map[] = array(
    240259                        'from_tablename'  => 'sfposts',
     
    245264                );
    246265
    247                 // Author ip.
     266                // Author ip (Stored in postmeta)
    248267                $this->field_map[] = array(
    249268                        'from_tablename' => 'sfposts',
     
    274293                );
    275294
    276                 // Topic slug. Clean name.
     295                // Topic slug (Clean name to avoid conflicts)
    277296                // Note: We join the sftopics table because sfposts do not have topic_name.
    278297                $this->field_map[] = array(
     
    296315                );
    297316
    298                 // Topic id.  If no parent, than 0.
     317                // Topic id (If no parent, than 0)
    299318                $this->field_map[] = array(
    300319                        'from_tablename'  => 'sfposts',
     
    337356                /** User Section ******************************************************/
    338357
    339                 // Store old User id. Stores in usermeta.
     358                // Store old User id (Stored in usermeta)
    340359                $this->field_map[] = array(
    341360                        'from_tablename' => 'users',
     
    345364                );
    346365
    347                 // Store old User password. Stores in usermeta.
     366                // Store old User password (Stored in usermeta)
    348367                $this->field_map[] = array(
    349368                        'from_tablename' => 'users',
     
    436455
    437456        /**
    438          * This callback processes any custom parser.php attributes and custom code with preg_replace
     457         * Translate the post status from Simple:Press numeric's to WordPress's strings.
     458         *
     459         * @param int $status Simple:Press numeric status
     460         * @return string WordPress safe
     461         */
     462        public function callback_status( $status = 0 ) {
     463                switch ( $status ) {
     464                        case 1 :
     465                                $status = 'closed';
     466                                break;
     467
     468                        case 0  :
     469                        default :
     470                                $status = 'publish';
     471                                break;
     472                }
     473                return $status;
     474        }
     475
     476        /**
     477         * This callback processes any custom parser.php attributes and custom HTML code with preg_replace
    439478         */
    440479        protected function callback_html( $field ) {
    441480
    442                 // Parse out bbCodes
     481                // Strip any custom HTML not supported by parser.php first from $field before parsing $field to parser.php
     482                $simplepress_markup = $field;
     483                $simplepress_markup = html_entity_decode( $simplepress_markup );
     484
     485                // Replace any SimplePress smilies from path '/sp-resources/forum-smileys/sf-smily.gif' with the equivelant WordPress Smilie
     486                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-confused\.gif(.*?)\" \/>/'   , ':?'      , $simplepress_markup );
     487                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-cool\.gif(.*?)\" \/>/'       , ':cool:'  , $simplepress_markup );
     488                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-cry\.gif(.*?)\" \/>/'        , ':cry:'   , $simplepress_markup );
     489                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-embarassed\.gif(.*?)\" \/>/' , ':oops:'  , $simplepress_markup );
     490                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-frown\.gif(.*?)\" \/>/'      , ':('      , $simplepress_markup );
     491                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-kiss\.gif(.*?)\" \/>/'       , ':P'      , $simplepress_markup );
     492                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-laugh\.gif(.*?)\" \/>/'      , ':D'      , $simplepress_markup );
     493                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-smile\.gif(.*?)\" \/>/'      , ':smile:' , $simplepress_markup );
     494                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-surprised\.gif(.*?)\" \/>/'  , ':o'      , $simplepress_markup );
     495                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-wink\.gif(.*?)\" \/>/'       , ':wink:'  , $simplepress_markup );
     496                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-yell\.gif(.*?)\" \/>/'       , ':x'      , $simplepress_markup );
     497
     498                // Replace <div class="sfcode">example code</div> with <code>*</code>
     499                $simplepress_markup = preg_replace( '/\<div class\=\"sfcode\"\>(.*?)\<\/div\>/' , '<code>$1</code>' , $simplepress_markup );
     500
     501                // Now that SimplePress' custom HTML codes have been stripped put the cleaned HTML back in $field
     502                $field = $simplepress_markup;
     503
     504                // Parse out any bbCodes with the BBCode 'parser.php'
    443505                require_once( bbpress()->admin->admin_dir . 'parser.php' );
    444506                $bbcode = BBCode::getInstance();
    445507                $bbcode->enable_smileys = false;
    446508                $bbcode->smiley_regex   = false;
    447                 $field = html_entity_decode( $bbcode->Parse( $field ) );
    448 
    449                 // Replace SimplePress smilies with the equivelant WordPress
    450                 $field = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-confused.gif(.*?)" \/>/'   , ':?'      , $field );
    451                 $field = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-cool.gif(.*?)" \/>/'       , ':cool:'  , $field );
    452                 $field = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-cry.gif(.*?)" \/>/'        , ':cry:'   , $field );
    453                 $field = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-embarassed.gif(.*?)" \/>/' , ':oops:'  , $field );
    454                 $field = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-frown.gif(.*?)" \/>/'      , ':('      , $field );
    455                 $field = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-kiss.gif(.*?)" \/>/'       , ':P'      , $field );
    456                 $field = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-laugh.gif(.*?)" \/>/'      , ':D'      , $field );
    457                 $field = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-smile.gif(.*?)" \/>/'      , ':smile:' , $field );
    458                 $field = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-surprised.gif(.*?)" \/>/'  , ':o'      , $field );
    459                 $field = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-wink.gif(.*?)" \/>/'       , ':wink:'  , $field );
    460                 $field = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-yell.gif(.*?)" \/>/'       , ':x'      , $field );
    461 
    462                 return $field;
     509                return html_entity_decode( $bbcode->Parse( $field ) );
    463510        }
    464511}
Note: See TracChangeset for help on using the changeset viewer.