Skip to:
Content

bbPress.org

Ticket #1884: 1884.4.diff

File 1884.4.diff, 24.7 KB (added by netweb, 10 years ago)

(All previous diffs are included in this latest iteration 1884.4.diff)

  • includes/admin/converters/phpBB.php

    diff --git a/includes/admin/converters/phpBB.php b/includes/admin/converters/phpBB.php
    index 8f3a03c..70e1d0e 100644
    a b  
    11<?php
    22
    33/**
    4  * Implementation of phpBB converter.
     4 * Implementation of phpBB v3 Converter.
     5 *
     6 * @since bbPress (r4689)
    57 */
    68class phpBB extends BBP_Converter_Base {
     9
     10        /**
     11         * Main Constructor
     12         *
     13         * @uses phpBB::setup_globals()
     14         */
    715        function __construct() {
    816                parent::__construct();
    917                $this->setup_globals();
    1018        }
    1119
     20        /**
     21         * Sets up the field mappings
     22         */
     23
    1224        public function setup_globals() {
    1325
    1426                /** Forum Section ******************************************************/
    1527
    16                 // Forum id. Stored in postmeta.
     28                // Forum id (Stored in postmeta)
    1729                $this->field_map[] = array(
    1830                        'from_tablename' => 'forums',
    1931                        'from_fieldname' => 'forum_id',
    class phpBB extends BBP_Converter_Base { 
    2133                        'to_fieldname'   => '_bbp_forum_id'
    2234                );
    2335               
    24                 // Forum parent id.  If no parent, than 0. Stored in postmeta.
     36                // Forum parent id (If no parent, than 0, Stored in postmeta)
    2537                $this->field_map[] = array(
    2638                        'from_tablename' => 'forums',
    2739                        'from_fieldname' => 'parent_id',
    2840                        'to_type'        => 'forum',
    29                         'to_fieldname'   => '_bbp_parent_id'
     41                        'to_fieldname'   => '_bbp_forum_parent_id'
    3042                );
    31                
     43
     44                // Forum topic count (Stored in postmeta)
     45                $this->field_map[] = array(
     46                        'from_tablename' => 'forums',
     47                        'from_fieldname' => 'forum_topics',
     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' => 'forums',
     55                        'from_fieldname' => 'forum_posts',
     56                        'to_type'        => 'forum',
     57                        'to_fieldname'   => '_bbp_reply_count'
     58                );
     59
     60                // Forum total topic count (Includes unpublished topics, Stored in postmeta)
     61                $this->field_map[] = array(
     62                        'from_tablename' => 'forums',
     63                        'from_fieldname' => 'forum_topics_real',
     64                        'to_type'        => 'forum',
     65                        'to_fieldname'   => '_bbp_total_topic_count'
     66                );
     67
    3268                // Forum title.
    3369                $this->field_map[] = array(
    3470                        'from_tablename' => 'forums',
    class phpBB extends BBP_Converter_Base { 
    3773                        'to_fieldname'   => 'post_title'
    3874                );
    3975               
    40                 // Forum slug. Clean name.
     76                // Forum slug (Clean name to avoid conflicts)
    4177                $this->field_map[] = array(
    4278                        'from_tablename'  => 'forums',
    4379                        'from_fieldname'  => 'forum_name',
    class phpBB extends BBP_Converter_Base { 
    5591                        'callback_method' => 'callback_null'
    5692                );
    5793               
    58                 // Forum display order.  Starts from 1.
     94                // Forum display order (Starts from 1)
    5995                $this->field_map[] = array(
    6096                        'from_tablename' => 'forums',
    6197                        'from_fieldname' => 'display_on_index',
    6298                        'to_type'        => 'forum',
    6399                        'to_fieldname'   => 'menu_order'
    64100                );
    65                
    66                 // Forum date update.
     101
     102                // Forum status (Locked =1 Unlocked =0, Stored in postmeta)
    67103                $this->field_map[] = array(
    68                         'to_type'      => 'forums',
    69                         'to_fieldname' => 'forum_last_post_time',
     104                        'from_tablename' => 'forums',
     105                        'from_fieldname' => 'forum_status',
     106                        'to_type'        => 'forum',
     107                        'to_fieldname'   => '_bbp_status'
     108                );
     109
     110                // Forum dates.
     111                $this->field_map[] = array(
     112                        'to_type'      => 'forum',
     113                        'to_fieldname' => 'post_date',
    70114                        'default'      => date('Y-m-d H:i:s')
    71115                );
    72116                $this->field_map[] = array(
    73                         'to_type'      => 'forums',
    74                         'to_fieldname' => 'forum_last_post_time',
     117                        'to_type'      => 'forum',
     118                        'to_fieldname' => 'post_date_gmt',
    75119                        'default'      => date('Y-m-d H:i:s')
    76120                );
    77121                $this->field_map[] = array(
    78                         'to_type'      => 'forums',
    79                         'to_fieldname' => 'forum_last_post_time',
     122                        'to_type'      => 'forum',
     123                        'to_fieldname' => 'post_modified',
    80124                        'default'      => date('Y-m-d H:i:s')
    81125                );
    82126                $this->field_map[] = array(
    83                         'to_type'      => 'forums',
    84                         'to_fieldname' => 'forum_last_post_time',
     127                        'to_type'      => 'forum',
     128                        'to_fieldname' => 'post_modified_gmt',
    85129                        'default'      => date('Y-m-d H:i:s')
    86130                );
    87131
    88132                /** Topic Section ******************************************************/
    89133
    90                 // Topic id. Stored in postmeta.
     134                // Topic id (Stored in postmeta)
    91135                $this->field_map[] = array(
    92136                        'from_tablename' => 'topics',
    93137                        'from_fieldname' => 'topic_id',
    94138                        'to_type'        => 'topic',
    95139                        'to_fieldname'   => '_bbp_topic_id'
    96140                );
    97                
    98                 // Forum id. Stored in postmeta.
     141
     142                // Topic reply count (Stored in postmeta)
     143                $this->field_map[] = array(
     144                        'from_tablename'  => 'topics',
     145                        'from_fieldname'  => 'topic_replies',
     146                        'to_type'         => 'topic',
     147                        'to_fieldname'    => '_bbp_reply_count',
     148                        'callback_method' => 'callback_topic_reply_count'
     149                );
     150
     151                // Topic total reply count (Includes unpublished replies, Stored in postmeta)
     152                $this->field_map[] = array(
     153                        'from_tablename'  => 'topics',
     154                        'from_fieldname'  => 'topic_replies_real',
     155                        'to_type'         => 'topic',
     156                        'to_fieldname'    => '_bbp_total_reply_count',
     157                        'callback_method' => 'callback_topic_reply_count'
     158                );
     159
     160                // Topic forum id (Stored in postmeta)
    99161                $this->field_map[] = array(
    100162                        'from_tablename'  => 'topics',
    101163                        'from_fieldname'  => 'forum_id',
    class phpBB extends BBP_Converter_Base { 
    103165                        'to_fieldname'    => '_bbp_forum_id',
    104166                        'callback_method' => 'callback_forumid'
    105167                );
    106                                
     168
    107169                // Topic author.
    108170                $this->field_map[] = array(
    109171                        'from_tablename'  => 'topics',
    class phpBB extends BBP_Converter_Base { 
    114176                );
    115177
    116178                // Topic content.
     179                // Note: We join the posts table because topics do not have content.
    117180                $this->field_map[] = array(
    118181                        'from_tablename'  => 'posts',
    119182                        'from_fieldname'  => 'post_text',
    class phpBB extends BBP_Converter_Base { 
    123186                        'to_type'         => 'topic',
    124187                        'to_fieldname'    => 'post_content',
    125188                        'callback_method' => 'callback_html'
    126                 );     
     189                );
    127190
    128191                // Topic title.
    129192                $this->field_map[] = array(
    class phpBB extends BBP_Converter_Base { 
    132195                        'to_type'        => 'topic',
    133196                        'to_fieldname'   => 'post_title'
    134197                );
    135                
    136                 // Topic slug. Clean name.
     198
     199                // Topic slug (Clean name to avoid conflicts)
    137200                $this->field_map[] = array(
    138201                        'from_tablename'  => 'topics',
    139202                        'from_fieldname'  => 'topic_title',
    class phpBB extends BBP_Converter_Base { 
    141204                        'to_fieldname'    => 'post_name',
    142205                        'callback_method' => 'callback_slug'
    143206                );
    144                
    145                 // Forum id.  If no parent, than 0.
     207
     208                // Topic forum id (If no parent, than 0)
    146209                $this->field_map[] = array(
    147210                        'from_tablename'  => 'topics',
    148211                        'from_fieldname'  => 'forum_id',
    class phpBB extends BBP_Converter_Base { 
    180243                        'to_fieldname'    => 'post_modified_gmt',
    181244                        'callback_method' => 'callback_datetime'
    182245                );
     246                $this->field_map[] = array(
     247                        'from_tablename' => 'topics',
     248                        'from_fieldname' => 'topic_last_post_time',
     249                        'to_type'        => 'topic',
     250                        'to_fieldname'   => '_bbp_last_active_time',
     251                        'callback_method' => 'callback_datetime'
     252                );
    183253
    184254                // Topic status (Open or Closed)
    185255                $this->field_map[] = array(
    class phpBB extends BBP_Converter_Base { 
    190260                        'callback_method' => 'callback_topic_status'
    191261                );
    192262
     263                // Topic Author ip (Stored in postmeta)
     264                $this->field_map[] = array(
     265                        'from_tablename'  => 'posts',
     266                        'from_fieldname'  => 'poster_ip',
     267                        'join_tablename'  => 'topics',
     268                        'join_type'       => 'INNER',
     269                        'join_expression' => 'USING (topic_id) WHERE posts.post_id = topics.topic_first_post_id',
     270                        'to_type'         => 'topic',
     271                        'to_fieldname'    => '_bbp_author_ip'
     272                );
     273
     274                // Sticky Status
     275
    193276                /** Tags Section ******************************************************/
    194277                /*
    195278                // Topic id.
    class phpBB extends BBP_Converter_Base { 
    213296                );             
    214297                */
    215298               
    216                 /** Post Section ******************************************************/
     299                /** Reply Section *****************************************************/
    217300
    218                 // Post id. Stored in postmeta.
     301                // Post id (Stored in postmeta)
    219302                $this->field_map[] = array(
    220303                        'from_tablename' => 'posts',
    221304                        'from_fieldname' => 'post_id',
    222305                        'to_type'        => 'reply',
    223306                        'to_fieldname'   => '_bbp_post_id'
    224307                );
    225                
     308
    226309                // Topic content.
    227310                $this->field_map[] = array(
    228311                        'from_tablename'  => 'topics',
    class phpBB extends BBP_Converter_Base { 
    231314                        'join_type'       => 'LEFT',
    232315                        'join_expression' => 'USING (topic_id) WHERE posts.post_id != topics.topic_first_post_id',
    233316                        'to_type'         => 'reply'
    234                 );     
    235                
    236                 // Forum id. Stored in postmeta.
     317                );
     318
     319                // Forum id (Stored in postmeta)
    237320                $this->field_map[] = array(
    238321                        'from_tablename'  => 'posts',
    239322                        'from_fieldname'  => 'forum_id',
    class phpBB extends BBP_Converter_Base { 
    241324                        'to_fieldname'    => '_bbp_forum_id',
    242325                        'callback_method' => 'callback_topicid_to_forumid'
    243326                );
    244                
    245                 // Topic id. Stored in postmeta.
     327
     328                // Topic id (Stored in postmeta)
    246329                $this->field_map[] = array(
    247330                        'from_tablename'  => 'posts',
    248331                        'from_fieldname'  => 'topic_id',
    class phpBB extends BBP_Converter_Base { 
    250333                        'to_fieldname'    => '_bbp_topic_id',
    251334                        'callback_method' => 'callback_topicid'
    252335                );
    253                
    254                 // Author ip. Stored in postmeta.
     336
     337                // Reply author ip (Stored in postmeta)
    255338                $this->field_map[] = array(
    256339                        'from_tablename' => 'posts',
    257340                        'from_fieldname' => 'poster_ip',
    258341                        'to_type'        => 'reply',
    259342                        'to_fieldname'   => '_bbp_author_ip'
    260                 );     
    261                        
    262                 // Post author.
     343                );
     344
     345                // Reply author.
    263346                $this->field_map[] = array(
    264347                        'from_tablename'  => 'posts',
    265348                        'from_fieldname'  => 'poster_id',
    class phpBB extends BBP_Converter_Base { 
    267350                        'to_fieldname'    => 'post_author',
    268351                        'callback_method' => 'callback_userid'
    269352                );
    270                
    271                 // Topic title.
     353
     354                // Topic title (for reply title).
    272355                $this->field_map[] = array(
    273356                        'from_tablename' => 'posts',
    274357                        'from_fieldname' => 'post_subject',
    275358                        'to_type'        => 'reply',
    276359                        'to_fieldname'   => 'post_title'
    277360                );
    278                
    279                 // Topic slug. Clean name.
     361
     362                // Reply slug (Clean name to avoid conflicts)
    280363                $this->field_map[] = array(
    281364                        'from_tablename'  => 'posts',
    282365                        'from_fieldname'  => 'post_subject',
    class phpBB extends BBP_Converter_Base { 
    284367                        'to_fieldname'    => 'post_name',
    285368                        'callback_method' => 'callback_slug'
    286369                );
    287                
     370
    288371                // Post content.
    289372                $this->field_map[] = array(
    290373                        'from_tablename'  => 'posts',
    class phpBB extends BBP_Converter_Base { 
    293376                        'to_fieldname'    => 'post_content',
    294377                        'callback_method' => 'callback_html'
    295378                );
    296                
    297                 // Topic id.  If no parent, than 0.
     379
     380                // Parent topic id (If no parent, than 0)
    298381                $this->field_map[] = array(
    299382                        'from_tablename'  => 'posts',
    300383                        'from_fieldname'  => 'topic_id',
    class phpBB extends BBP_Converter_Base { 
    303386                        'callback_method' => 'callback_topicid'
    304387                );
    305388
    306                 // Topic date update.
     389                // Reply dates.
    307390                $this->field_map[] = array(
    308391                        'from_tablename'  => 'posts',
    309392                        'from_fieldname'  => 'post_time',
    class phpBB extends BBP_Converter_Base { 
    335418
    336419                /** User Section ******************************************************/
    337420
    338                 // Store old User id. Stored in usermeta.
     421                // Store old User id (Stored in usermeta)
    339422                $this->field_map[] = array(
    340423                        'from_tablename' => 'users',
    341424                        'from_fieldname' => 'user_id',
    342425                        'to_type'        => 'user',
    343426                        'to_fieldname'   => '_bbp_user_id'
    344427                );
    345                
    346                 // Store old User password. Stored in usermeta serialized with salt.
     428
     429                // Store old User password (Stored in usermeta serialized with salt)
    347430                $this->field_map[] = array(
    348431                        'from_tablename'  => 'users',
    349432                        'from_fieldname'  => 'user_password',
    class phpBB extends BBP_Converter_Base { 
    352435                        'callback_method' => 'callback_savepass'
    353436                );
    354437
    355                 // Store old User Salt. This is only used for the SELECT row info for the above password save
     438                // Store old User Salt (This is only used for the SELECT row info for the above password save)
    356439                $this->field_map[] = array(
    357440                        'from_tablename' => 'users',
    358441                        'from_fieldname' => 'user_form_salt',
    359442                        'to_type'        => 'user',
    360443                        'to_fieldname'   => ''
    361444                );
    362                                
    363                 // User password verify class. Stored in usermeta for verifying password.
     445
     446                // User password verify class (Stored in usermeta for verifying password)
    364447                $this->field_map[] = array(
    365448                        'to_type'      => 'user',
    366449                        'to_fieldname' => '_bbp_class',
    367450                        'default'      => 'phpBB'
    368451                );
    369                                
     452
    370453                // User name.
    371454                $this->field_map[] = array(
    372455                        'from_tablename' => 'users',
    class phpBB extends BBP_Converter_Base { 
    374457                        'to_type'        => 'user',
    375458                        'to_fieldname'   => 'user_login'
    376459                );
    377                                
     460
    378461                // User email.
    379462                $this->field_map[] = array(
    380463                        'from_tablename' => 'users',
    class phpBB extends BBP_Converter_Base { 
    382465                        'to_type'        => 'user',
    383466                        'to_fieldname'   => 'user_email'
    384467                );
    385                
     468
    386469                // User homepage.
    387470                $this->field_map[] = array(
    388471                        'from_tablename' => 'users',
    class phpBB extends BBP_Converter_Base { 
    390473                        'to_type'        => 'user',
    391474                        'to_fieldname'   => 'user_url'
    392475                );
    393                
     476
    394477                // User registered.
    395478                $this->field_map[] = array(
    396479                        'from_tablename'  => 'users',
    class phpBB extends BBP_Converter_Base { 
    399482                        'to_fieldname'    => 'user_registered',
    400483                        'callback_method' => 'callback_datetime'
    401484                );
    402                
    403                 // User aim.
     485
     486                // User AIM (Stored in usermeta)
    404487                $this->field_map[] = array(
    405488                        'from_tablename' => 'users',
    406489                        'from_fieldname' => 'user_aim',
    407490                        'to_type'        => 'user',
    408491                        'to_fieldname'   => 'aim'
    409492                );
    410                
    411                 // User yahoo.
     493
     494                // User Yahoo (Stored in usermeta)
    412495                $this->field_map[] = array(
    413496                        'from_tablename' => 'users',
    414497                        'from_fieldname' => 'user_yim',
    415498                        'to_type'        => 'user',
    416499                        'to_fieldname'   => 'yim'
    417                 );     
     500                );
     501
     502                // Store ICQ (Stored in usermeta)
     503                $this->field_map[] = array(
     504                        'from_tablename' => 'users',
     505                        'from_fieldname' => 'user_icq',
     506                        'to_type'        => 'user',
     507                        'to_fieldname'   => '_bbp_phpbb_user_icq'
     508                );
     509
     510                // Store MSN (Stored in usermeta)
     511                $this->field_map[] = array(
     512                        'from_tablename' => 'users',
     513                        'from_fieldname' => 'user_msnm',
     514                        'to_type'        => 'user',
     515                        'to_fieldname'   => '_bbp_phpbb_user_msnm'
     516                );
     517
     518                // Store Jabber
     519                $this->field_map[] = array(
     520                        'from_tablename' => 'users',
     521                        'from_fieldname' => 'user_jabber',
     522                        'to_type'        => 'user',
     523                        'to_fieldname'   => 'jabber'
     524                );
     525
     526                // Store Occupation (Stored in usermeta)
     527                $this->field_map[] = array(
     528                        'from_tablename' => 'users',
     529                        'from_fieldname' => 'user_occ',
     530                        'to_type'        => 'user',
     531                        'to_fieldname'   => '_bbp_phpbb_user_occ'
     532                );
     533
     534                // Store Interests (Stored in usermeta)
     535                $this->field_map[] = array(
     536                        'from_tablename' => 'users',
     537                        'from_fieldname' => 'user_interests',
     538                        'to_type'        => 'user',
     539                        'to_fieldname'   => '_bbp_phpbb_user_interests'
     540                );
     541
     542                // Store Signature (Stored in usermeta)
     543                $this->field_map[] = array(
     544                        'from_tablename' => 'users',
     545                        'from_fieldname' => 'user_sig',
     546                        'to_type'        => 'user',
     547                        'to_fieldname'   => '_bbp_phpbb_user_sig',
     548                        'callback_method' => 'callback_html'
     549                );
     550
     551                // Store Location (Stored in usermeta)
     552                $this->field_map[] = array(
     553                        'from_tablename' => 'users',
     554                        'from_fieldname' => 'user_from',
     555                        'to_type'        => 'user',
     556                        'to_fieldname'   => '_bbp_phpbb_user_from'
     557                );
     558
     559                // Store Avatar Filename (Stored in usermeta)
     560                $this->field_map[] = array(
     561                        'from_tablename' => 'users',
     562                        'from_fieldname' => 'user_avatar',
     563                        'to_type'        => 'user',
     564                        'to_fieldname'   => '_bbp_phpbb_user_avatar'
     565                );
     566
     567                // Store old role (Stored in usermeta)
     568
    418569        }
    419570
    420571        /**
    class phpBB extends BBP_Converter_Base { 
    441592         * @param string $password The password in plain text
    442593         * @param string $hash The stored password hash
    443594         *
     595         * @link Original source for password functions http://openwall.com/phpass/
     596         * @link phpass is now included in WP Core http://core.trac.wordpress.org/browser/trunk/wp-includes/class-phpass.php
     597         *
    444598         * @return bool Returns true if the password is correct, false if not.
    445599         */
    446600        public function authenticate_pass($password, $serialized_pass) {
    447601                $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    448602                $pass_array = unserialize($serialized_pass);
    449                 if (strlen($pass_array['hash']) == 34) {                               
     603                if (strlen($pass_array['hash']) == 34) {
    450604                        return ($this->_hash_crypt_private($password, $pass_array['hash'], $itoa64) === $pass_array['hash']) ? true : false;
    451605                }
    452        
     606
    453607                return (md5($password) === $pass_array['hash']) ? true : false;
    454608        }
    455609       
    class phpBB extends BBP_Converter_Base { 
    458612         */
    459613        private function _hash_crypt_private($password, $setting, &$itoa64) {
    460614                $output = '*';
    461        
     615
    462616                // Check for correct hash
    463617                if (substr($setting, 0, 3) != '$H$') {
    464618                        return $output;
    465619                }
    466        
     620
    467621                $count_log2 = strpos($itoa64, $setting[3]);
    468        
     622
    469623                if ($count_log2 < 7 || $count_log2 > 30) {
    470624                        return $output;
    471625                }
    472        
     626
    473627                $count = 1 << $count_log2;
    474628                $salt = substr($setting, 4, 8);
    475        
     629
    476630                if (strlen($salt) != 8) {
    477631                        return $output;
    478632                }
    479        
     633
    480634                /**
    481635                 * We're kind of forced to use MD5 here since it's the only
    482636                 * cryptographic primitive available in all versions of PHP
    class phpBB extends BBP_Converter_Base { 
    502656
    503657                $output = substr($setting, 0, 12);
    504658                $output .= $this->_hash_encode64($hash, 16, $itoa64);
    505        
     659
    506660                return $output;
    507661        }
    508                
     662
    509663        /**
    510664         * Encode hash
    511665         */
    512666        private function _hash_encode64($input, $count, &$itoa64) {
    513667                $output = '';
    514668                $i = 0;
    515        
     669
    516670                do {
    517671                        $value = ord($input[$i++]);
    518672                        $output .= $itoa64[$value & 0x3f];
    519        
     673
    520674                        if ($i < $count) {
    521675                                $value |= ord($input[$i]) << 8;
    522676                        }
    523        
     677
    524678                        $output .= $itoa64[($value >> 6) & 0x3f];
    525        
     679
    526680                        if ($i++ >= $count) {
    527681                                break;
    528682                        }
    529        
     683
    530684                        if ($i < $count) {
    531685                                $value |= ord($input[$i]) << 16;
    532686                        }
    533        
     687
    534688                        $output .= $itoa64[($value >> 12) & 0x3f];
    535        
     689
    536690                        if ($i++ >= $count) {
    537691                                break;
    538692                        }
    539        
     693
    540694                        $output .= $itoa64[($value >> 18) & 0x3f];
    541695                }
    542696                while ($i < $count);
    543        
     697
    544698                return $output;
    545699        }
    546700
    547701        /**
    548702         * Translate the post status from phpBB numeric's to WordPress's strings.
    549703         *
    550          * @param int $status phpBB 3.x numeric topic status
     704         * @param int $status phpBB v3.x numeric topic status
    551705         * @return string WordPress safe
    552706         */
    553707        public function callback_topic_status( $status = 0 ) {
    class phpBB extends BBP_Converter_Base { 
    563717                }
    564718                return $status;
    565719        }
    566 }
     720
     721        /**
     722         * Verify the topic reply count.
     723         *
     724         * @param int $count phpBB v3.x reply count
     725         * @return string WordPress safe
     726         */
     727        public function callback_topic_reply_count( $count = 1 ) {
     728                $count = absint( (int) $count - 1 );
     729                return $count;
     730        }
     731
     732        /**
     733         * This callback processes any custom parser.php attributes and custom code with preg_replace
     734         */
     735        protected function callback_html( $field ) {
     736
     737                // Strips custom phpBB 'magic_url' and 'bbcode_uid' first from $field before parsing $field to parser.php
     738                $phpbb_uid = $field;
     739                $phpbb_uid = html_entity_decode ( $phpbb_uid );
     740
     741                // Replace '[b:XXXXXXX]' with '<strong>'
     742                $phpbb_uid = preg_replace ( '/\[b:(.*?)\]/'   , '<strong>'  , $phpbb_uid );
     743                // Replace '[/b:XXXXXXX]' with '</strong>'
     744                $phpbb_uid = preg_replace ( '/\[\/b:(.*?)\]/' , '</strong>' , $phpbb_uid );
     745
     746                // Replace '[i:XXXXXXX]' with '<em>'
     747                $phpbb_uid = preg_replace ( '/\[i:(.*?)\]/'   , '<em>'      , $phpbb_uid );
     748                // Replace '[/i:XXXXXXX]' with '</em>'
     749                $phpbb_uid = preg_replace ( '/\[\/i:(.*?)\]/' , '</em>'     , $phpbb_uid );
     750
     751                // Replace '[u:XXXXXXX]' with '<u>'
     752                $phpbb_uid = preg_replace ( '/\[u:(.*?)\]/'   , '<u>'       , $phpbb_uid );
     753                // Replace '[/u:XXXXXXX]' with '</u>'
     754                $phpbb_uid = preg_replace ( '/\[\/u:(.*?)\]/' , '</u>'      , $phpbb_uid );
     755
     756                // Replace '[quote:XXXXXXX]' with '<blockquote>'
     757                $phpbb_uid = preg_replace ( '/\[quote:(.*?)\]/'         , '<blockquote>'                   , $phpbb_uid );
     758                // Replace '[quote="$1"]' with '<em>$1 wrote:</em><blockquote>"
     759                $phpbb_uid = preg_replace ( '/\[quote="(.*?)":(.*?)\]/' , '<em>@$1 wrote:</em><blockquote>' , $phpbb_uid );
     760                // Replace '[/quote:XXXXXXX]' with '</blockquote>'
     761                $phpbb_uid = preg_replace ( '/\[\/quote:(.*?)\]/'       , '</blockquote>'                  , $phpbb_uid );
     762
     763                // Replace '[img:XXXXXXX]' with '<img src="'
     764                $phpbb_uid = preg_replace ( '/\[img:(.*?)\]/'   , '<img src="' , $phpbb_uid );
     765                // Replace '[/img:XXXXXXX]' with ' alt="">'
     766                $phpbb_uid = preg_replace ( '/\[\/img:(.*?)\]/' , '" alt="">'  , $phpbb_uid );
     767
     768                // Replace '<!-- s$1 --><img src=\"{SMILIES_PATH}$2 -->' with '$1'
     769                $phpbb_uid = preg_replace ( '/<!-- s(.*?) --><img src=\"{SMILIES_PATH}(.*?)-->/' , '$1' , $phpbb_uid );
     770
     771                // Replace '<!-- m --><a class="postlink" href="$1">$1</a><!-- m -->' with '$1'
     772                $phpbb_uid = preg_replace ( '/\<!-- m --\>\<a class="postlink" href="([^\[]+?)"\>([^\[]+?)\<\/a\>\<!-- m --\>/' , '$1' , $phpbb_uid );
     773
     774                // Replace '[url:XXXXXXX]$1[/url:XXXXXXX]' with '<a href="http://$1">$1</a>'
     775                $phpbb_uid = preg_replace ( '/\[url:(?:[^\]]+)\]([^\[]+?)\[\/url:(?:[^\]]+)\]/'       , '<a href="http://$1">$1</a>'  , $phpbb_uid );
     776                // Replace '[url=http://$1:XXXXXXX]$3[/url:XXXXXXX]' with '<a href="http://$1">$3</a>'
     777                $phpbb_uid = preg_replace ( '/\[url\=http\:\/\/(.*?)\:(.*?)\](.*?)\[\/url:(.*?)\]/i'  , '<a href="http://$1">$3</a>'  , $phpbb_uid );
     778                // Replace '[url=https://$1:XXXXXXX]$3[/url:XXXXXXX]' with '<a href="http://$1">$3</a>'
     779                $phpbb_uid = preg_replace ( '/\[url\=https\:\/\/(.*?)\:(.*?)\](.*?)\[\/url:(.*?)\]/i' , '<a href="https://$1">$3</a>' , $phpbb_uid );
     780
     781                // Replace '[email:XXXXXXX]' with '<a href="mailto:$2">$2</a>'
     782                $phpbb_uid = preg_replace ( '/\[email:(.*?)\](.*?)\[\/email:(.*?)\]/' , '<a href="mailto:$2">$2</a>' , $phpbb_uid );
     783                // Replace '<!-- e -->no.one@domain.adr<!-- e -->' with '$1'
     784                $phpbb_uid = preg_replace ( '/\<!-- e --\>(.*?)\<!-- e --\>/' , '$1' , $phpbb_uid );
     785
     786                // Replace '[code:XXXXXXX]' with '<pre><code>'
     787                $phpbb_uid = preg_replace ( '/\[code:(.*?)\]/'   , '<pre><code>'   , $phpbb_uid );
     788                // Replace '[/code:XXXXXXX]' with '</code></pre>'
     789                $phpbb_uid = preg_replace ( '/\[\/code:(.*?)\]/' , '</code></pre>' , $phpbb_uid );
     790
     791                // Replace '[color=$1:XXXXXXXX]' with '<span style="color:$1">'
     792                $phpbb_uid = preg_replace ( '/\[color=(.*?)\:(.*?)\]/' , '<span style="color: $1">' , $phpbb_uid );
     793                // Replace '[/color:XXXXXXX]' with '</span>'
     794                $phpbb_uid = preg_replace ( '/\[\/color:(.*?)\]/'     , '</span>'                 , $phpbb_uid );
     795
     796                // Replace '[size=$1:XXXXXXXX]' with '<span style="font-size:$1%;">$3</span>'
     797                $phpbb_uid = preg_replace ( '/\[size=(.*?):(.*?)\]/' , '<span style="font-size:$1%;">' , $phpbb_uid );
     798                // Replace '[/size:XXXXXXX]' with ''
     799                $phpbb_uid = preg_replace ( '/\[\/size:(.*?)\]/'     , '</span>'                       , $phpbb_uid );
     800
     801                // Replace '[list:XXXXXXX]' with '<ul>'
     802                $phpbb_uid = preg_replace ( '/\[list:(.*?)\]/'     , '<ul>'          , $phpbb_uid );
     803                // Replace '[list=a:XXXXXXX]' with '<ol type="a">'
     804                $phpbb_uid = preg_replace ( '/\[list=a:(.*?)\]/'   , '<ol type="a">' , $phpbb_uid );
     805                // Replace '[list=1:XXXXXXX]' with '<ol>'
     806                $phpbb_uid = preg_replace ( '/\[list=1:(.*?)\]/'   , '<ol>'          , $phpbb_uid );
     807                // Replace '[*:XXXXXXX]' with '<li>'
     808                $phpbb_uid = preg_replace ( '/\[\*:(.*?)\]/'       , '<li>'          , $phpbb_uid );
     809                // Replace '[/*:m:XXXXXXX]' with '</li>'
     810                $phpbb_uid = preg_replace ( '/\[\/\*:m:(.*?)\]/'   , '</li>'         , $phpbb_uid );
     811                // Replace '[/list:u:XXXXXXX]' with '</ul>'
     812                $phpbb_uid = preg_replace ( '/\[\/list:u:(.*?)\]/' , '</ul>'         , $phpbb_uid );
     813                // Replace '[/list:o:XXXXXXX]' with '</ol>'
     814                $phpbb_uid = preg_replace ( '/\[\/list:o:(.*?)\]/' , '</ol>'         , $phpbb_uid );
     815
     816                // Now that phpBB's 'magic_url' and 'bbcode_uid' have been stripped put the cleaned HTML back in $field
     817                $field = $phpbb_uid;
     818
     819                // Parse out any bbCodes in $field with the BBCode 'parser.php'
     820                require_once( bbpress()->admin->admin_dir . 'parser.php' );
     821                $bbcode = BBCode::getInstance();
     822                $bbcode->enable_smileys = false;
     823                $bbcode->smiley_regex   = false;
     824                return html_entity_decode( $bbcode->Parse( $field ) );
     825
     826        }
     827}
     828 No newline at end of file