Skip to:
Content

bbPress.org

Changeset 4728


Ignore:
Timestamp:
01/28/2013 12:29:30 AM (14 years ago)
Author:
johnjamesjacoby
Message:

Improvements to the SimplePress5 converter. Props netweb. See #2182.

File:
1 edited

Legend:

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

    r4693 r4728  
    55 *
    66 * @since bbPress (r4638)
     7 * @link Codex Docs http://codex.bbpress.org/import-forums/simplepress/
    78 */
    89class SimplePress5 extends BBP_Converter_Base {
    … …  
    3334                );
    3435
    35                 // Forum parent id (If no parent, than 0, Stored in postmeta)
     36                // Forum parent id (If no parent, then 0, Stored in postmeta)
    3637                $this->field_map[] = array(
    3738                        'from_tablename' => 'sfforums',
    … …  
    3940                        'to_type'        => 'forum',
    4041                        'to_fieldname'   => '_bbp_forum_parent_id'
     42                );
     43
     44                // Forum topic count (Stored in postmeta)
     45                $this->field_map[] = array(
     46                        'from_tablename' => 'sfforums',
     47                        'from_fieldname' => 'topic_count',
     48                        'to_type'        => 'forum',
     49                        'to_fieldname'   => '_bbp_topic_count'
     50                );
     51
     52                // Forum reply count (Stored in postmeta)
     53                $this->field_map[] = array(
     54                        'from_tablename' => 'sfforums',
     55                        'from_fieldname' => 'post_count',
     56                        'to_type'        => 'forum',
     57                        'to_fieldname'   => '_bbp_reply_count'
     58                );
     59
     60                // Forum total topic count (Stored in postmeta)
     61                $this->field_map[] = array(
     62                        'from_tablename' => 'sfforums',
     63                        'from_fieldname' => 'topic_count',
     64                        'to_type'        => 'forum',
     65                        'to_fieldname'   => '_bbp_total_topic_count'
     66                );
     67
     68                // Forum total reply count (Stored in postmeta)
     69                $this->field_map[] = array(
     70                        'from_tablename' => 'sfforums',
     71                        'from_fieldname' => 'post_count',
     72                        'to_type'        => 'forum',
     73                        'to_fieldname'   => '_bbp_total_reply_count'
    4174                );
    4275
    … …  
    75108                );
    76109
    77                 // Forum date update.
     110                // Forum dates.
    78111                $this->field_map[] = array(
    79112                        'to_type'      => 'forums',
    80                         'to_fieldname' => 'forum_last_post_time',
     113                        'to_fieldname' => 'post_date',
    81114                        'default'      => date('Y-m-d H:i:s')
    82115                );
    83116                $this->field_map[] = array(
    84117                        'to_type'      => 'forums',
    85                         'to_fieldname' => 'forum_last_post_time',
     118                        'to_fieldname' => 'post_date_gmt',
    86119                        'default'      => date('Y-m-d H:i:s')
    87120                );
    88121                $this->field_map[] = array(
    89122                        'to_type'      => 'forums',
    90                         'to_fieldname' => 'forum_last_post_time',
     123                        'to_fieldname' => 'post_modified',
    91124                        'default'      => date('Y-m-d H:i:s')
    92125                );
    93126                $this->field_map[] = array(
    94127                        'to_type'      => 'forums',
    95                         'to_fieldname' => 'forum_last_post_time',
     128                        'to_fieldname' => 'post_modified_gmt',
    96129                        'default'      => date('Y-m-d H:i:s')
    97130                );
    … …  
    107140                );
    108141
    109                 // Forum id (Stored in postmeta)
     142                // Topic reply count (Stored in postmeta)
     143                $this->field_map[] = array(
     144                        'from_tablename' => 'sftopics',
     145                        'from_fieldname' => 'post_count',
     146                        'to_type'        => 'topic',
     147                        'to_fieldname'   => '_bbp_reply_count',
     148                        'callback_method' => 'callback_topic_reply_count'
     149                );
     150
     151                // Topic parent forum id (If no parent, then 0. Stored in postmeta)
    110152                $this->field_map[] = array(
    111153                        'from_tablename'  => 'sftopics',
    … …  
    155197                );
    156198
    157                 // Forum id (If no parent, than 0)
     199                // Topic parent forum id (If no parent, then 0)
    158200                $this->field_map[] = array(
    159201                        'from_tablename'  => 'sftopics',
    … …  
    164206                );
    165207
    166                 // Topic date update.
     208                // Topic dates.
    167209                $this->field_map[] = array(
    168210                        'from_tablename'  => 'sftopics',
    169211                        'from_fieldname'  => 'topic_date',
    170212                        'to_type'         => 'topic',
    171                         'to_fieldname'    => 'post_date',
    172                         'callback_method' => 'callback_datetime'
     213                        'to_fieldname'    => 'post_date'
    173214                );
    174215                $this->field_map[] = array(
    … …  
    176217                        'from_fieldname'  => 'topic_date',
    177218                        'to_type'         => 'topic',
    178                         'to_fieldname'    => 'post_date_gmt',
    179                         'callback_method' => 'callback_datetime'
     219                        'to_fieldname'    => 'post_date_gmt'
    180220                );
    181221                $this->field_map[] = array(
    … …  
    183223                        'from_fieldname'  => 'topic_date',
    184224                        'to_type'         => 'topic',
    185                         'to_fieldname'    => 'post_modified',
    186                         'callback_method' => 'callback_datetime'
     225                        'to_fieldname'    => 'post_modified'
    187226                );
    188227                $this->field_map[] = array(
    … …  
    190229                        'from_fieldname'  => 'topic_date',
    191230                        'to_type'         => 'topic',
    192                         'to_fieldname'    => 'post_modified_gmt',
    193                         'callback_method' => 'callback_datetime'
     231                        'to_fieldname'    => 'post_modified_gmt'
     232                );
     233                $this->field_map[] = array(
     234                        'from_tablename'  => 'sftopics',
     235                        'from_fieldname'  => 'topic_date',
     236                        'to_type'         => 'topic',
     237                        'to_fieldname'    => '_bbp_last_active_time'
    194238                );
    195239
    … …  
    204248
    205249                /** Tags Section ******************************************************/
    206                 /*
    207                 // Topic id.
    208                 $this->field_map[] = array(
    209                         'from_tablename'  => 'tagcontent',
    210                         'from_fieldname'  => 'contentid',
    211                         'to_type'         => 'tags',
    212                         'to_fieldname'    => 'objectid',
    213                         'callback_method' => 'callback_topicid'
    214                 );
    215 
    216                 // Tags text.
    217                 $this->field_map[] = array(
    218                         'from_tablename'  => 'tag',
    219                         'from_fieldname'  => 'tagtext',
    220                         'join_tablename'  => 'tagcontent',
    221                         'join_type'       => 'INNER',
    222                         'join_expression' => 'USING (tagid)',
    223                         'to_type'         => 'tags',
    224                         'to_fieldname'    => 'name'
    225                 );
    226                 */
     250
     251                /**
     252                 * SimplePress Forums do not support topic tags without paid extensions
     253                 */
    227254
    228255                /** Reply Section *****************************************************/
    229256
    230                 // Post id (Stored in postmeta)
     257                // Reply id (Stored in postmeta)
    231258                $this->field_map[] = array(
    232259                        'from_tablename' => 'sfposts',
    … …  
    236263                );
    237264
    238                 // Topic content.
    239                 $this->field_map[] = array(
    240                         'from_tablename'  => 'sftopics',
    241                         'from_fieldname'  => 'topic_id',
    242                         'join_tablename'  => 'sfposts',
    243                         'join_type'       => 'LEFT',
    244                         'join_expression' => 'USING (topic_id) WHERE sfposts.post_index != 1',
    245                         'to_type'         => 'reply'
    246                 );
    247 
    248                 // Forum id (Stored in postmeta)
     265                // Reply parent forum id (If no parent, then 0. Stored in postmeta)
    249266                $this->field_map[] = array(
    250267                        'from_tablename'  => 'sfposts',
    … …  
    255272                );
    256273
    257                 // Topic id (Stored in postmeta)
     274                // Reply parent topic id (If no parent, then 0. Stored in postmeta)
    258275                $this->field_map[] = array(
    259276                        'from_tablename'  => 'sfposts',
    … …  
    264281                );
    265282
    266                 // Author ip (Stored in postmeta)
     283                // Reply author ip (Stored in postmeta)
    267284                $this->field_map[] = array(
    268285                        'from_tablename' => 'sfposts',
    … …  
    272289                );
    273290
    274                 // Post author.
     291                // Reply author.
    275292                $this->field_map[] = array(
    276293                        'from_tablename'  => 'sfposts',
    … …  
    281298                );
    282299
    283                 // Topic title.
    284                 // Note: We join the sftopics table because sfposts do not have topic_name.
     300                // Reply title.
     301                // Note: We join the sftopics table because sfposts table does not include topic title.
    285302                $this->field_map[] = array(
    286303                        'from_tablename'  => 'sftopics',
    287304                        'from_fieldname'  => 'topic_name',
    288305                        'join_tablename'  => 'sfposts',
    289                         'join_type'       => 'INNER',
    290                         'join_expression' => 'USING (topic_id) WHERE sfposts.post_id = sftopics.post_id_held',
    291                         'to_type'         => 'reply',
    292                         'to_fieldname'    => 'post_title'
    293                 );
    294 
    295                 // Topic slug (Clean name to avoid conflicts)
    296                 // Note: We join the sftopics table because sfposts do not have topic_name.
    297                 $this->field_map[] = array(
    298                         'from_tablename'  => 'sftopics',
    299                         'from_fieldname'  => 'topic_name',
    300                         'join_tablename'  => 'sfposts',
    301                         'join_type'       => 'INNER',
    302                         'join_expression' => 'USING (topic_id) WHERE sfposts.post_id = sftopics.post_id_held',
    303                         'to_type'         => 'reply',
    304                         'to_fieldname'    => 'post_name',
    305                         'callback_method' => 'callback_slug'
    306                 );
    307 
    308                 // Post content.
     306                        'join_type'       => 'LEFT',
     307                        'join_expression' => 'USING (topic_id) WHERE sfposts.post_index != 1',
     308                        'to_type'         => 'reply',
     309                        'to_fieldname'    => 'post_title',
     310                        'callback_method' => 'callback_reply_title'
     311                );
     312
     313                // Reply content.
    309314                $this->field_map[] = array(
    310315                        'from_tablename'  => 'sfposts',
    … …  
    315320                );
    316321
    317                 // Topic id (If no parent, than 0)
     322                // Reply parent topic id (If no parent, then 0)
    318323                $this->field_map[] = array(
    319324                        'from_tablename'  => 'sfposts',
    … …  
    324329                );
    325330
    326                 // Topic date update.
     331                // Reply dates.
    327332                $this->field_map[] = array(
    328333                        'from_tablename'  => 'sfposts',
    329334                        'from_fieldname'  => 'post_date',
    330335                        'to_type'         => 'reply',
    331                         'to_fieldname'    => 'post_date',
    332                         'callback_method' => 'callback_datetime'
     336                        'to_fieldname'    => 'post_date'
    333337                );
    334338                $this->field_map[] = array(
    … …  
    336340                        'from_fieldname'  => 'post_date',
    337341                        'to_type'         => 'reply',
    338                         'to_fieldname'    => 'post_date_gmt',
    339                         'callback_method' => 'callback_datetime'
     342                        'to_fieldname'    => 'post_date_gmt'
    340343                );
    341344                $this->field_map[] = array(
    … …  
    343346                        'from_fieldname'  => 'post_date',
    344347                        'to_type'         => 'reply',
    345                         'to_fieldname'    => 'post_modified',
    346                         'callback_method' => 'callback_datetime'
     348                        'to_fieldname'    => 'post_modified'
    347349                );
    348350                $this->field_map[] = array(
    … …  
    350352                        'from_fieldname'  => 'post_date',
    351353                        'to_type'         => 'reply',
    352                         'to_fieldname'    => 'post_modified_gmt',
    353                         'callback_method' => 'callback_datetime'
     354                        'to_fieldname'    => 'post_modified_gmt'
    354355                );
    355356
    … …  
    455456
    456457        /**
    457          * Translate the post status from Simple:Press numeric's to WordPress's strings.
     458         * Translate the post status from Simple:Press v5.x numeric's to WordPress's strings.
    458459         *
    459460         * @param int $status Simple:Press numeric status
    … …  
    475476
    476477        /**
     478         * Verify the topic reply count.
     479         *
     480         * @param int $count Simple:Press v5.x reply count
     481         * @return string WordPress safe
     482         */
     483        public function callback_topic_reply_count( $count = 1 ) {
     484                $count = absint( (int) $count - 1 );
     485                return $count;
     486        }
     487
     488        /**
     489         * Set the reply title
     490         *
     491         * @param string $title Simple:Press v5.x topic title of this reply
     492         * @return string Prefixed topic title, or empty string
     493         */
     494        public function callback_reply_title( $title = '' ) {
     495                $title = !empty( $title ) ? __( 'Re: ', 'bbpress' ) . html_entity_decode( $title ) : '';
     496                return $title;
     497        }
     498
     499        /**
    477500         * This callback processes any custom parser.php attributes and custom HTML code with preg_replace
    478501         */
    … …  
    484507
    485508                // 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>
     509                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-confused\.gif(.*?)\" \/>/',     ':?' ,    $simplepress_markup );
     510                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-cool\.gif(.*?)\" \/>/',        ':cool:',  $simplepress_markup );
     511                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-cry\.gif(.*?)\" \/>/',         ':cry:',    $simplepress_markup );
     512                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-embarassed\.gif(.*?)\" \/>/' , ':oops:',  $simplepress_markup );
     513                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-frown\.gif(.*?)\" \/>/',       ':(',      $simplepress_markup );
     514                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-kiss\.gif(.*?)\" \/>/',        ':P',      $simplepress_markup );
     515                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-laugh\.gif(.*?)\" \/>/',       ':D',      $simplepress_markup );
     516                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-smile\.gif(.*?)\" \/>/',       ':smile:', $simplepress_markup );
     517                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-surprised\.gif(.*?)\" \/>/',   ':o',      $simplepress_markup );
     518                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-wink\.gif(.*?)\" \/>/',        ':wink:',  $simplepress_markup );
     519                $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-yell\.gif(.*?)\" \/>/',         ':x',      $simplepress_markup );
     520
     521                // Replace '<div class="sfcode">example code</div>' with '<code>*</code>'
    499522                $simplepress_markup = preg_replace( '/\<div class\=\"sfcode\"\>(.*?)\<\/div\>/' , '<code>$1</code>' , $simplepress_markup );
     523
     524                // Replace '<strong>username said </strong>' with '@username said:'
     525                $simplepress_markup = preg_replace ( '/\<strong\>(.*?)\ said\ \<\/strong\>/',     '@$1 said:',        $simplepress_markup );
    500526
    501527                // Now that SimplePress' custom HTML codes have been stripped put the cleaned HTML back in $field
Note: See TracChangeset for help on using the changeset viewer.