Advertisement
Guest User

BBpress - phpBB 3.2.5 import script fixed

a guest
Feb 22nd, 2019
1,082
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 32.78 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * bbPress phpBB 3.x Converter
  5.  *
  6.  * @package bbPress
  7.  * @subpackage Converters
  8.  */
  9.  
  10. /**
  11.  * Implementation of phpBB v3 Converter.
  12.  *
  13.  * @since 2.3.0 bbPress (r4689)
  14.  *
  15.  * @link Codex Docs https://codex.bbpress.org/import-forums/phpbb
  16.  */
  17. class phpBB 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' => 'forums',
  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' => 'forums',
  51.             'from_fieldname' => 'parent_id',
  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' => 'forums',
  59.             'from_fieldname' => 'forum_topics_approved',
  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' => 'forums',
  67.             'from_fieldname' => 'forum_posts_approved',
  68.             'to_type'        => 'forum',
  69.             'to_fieldname'   => '_bbp_reply_count'
  70.         );
  71.  
  72.         // Forum total topic count (Includes unpublished topics, Stored in postmeta)
  73.         $this->field_map[] = array(
  74.             'from_tablename' => 'forums',
  75.             'from_fieldname' => 'forum_topics_approved',
  76.             'to_type'        => 'forum',
  77.             'to_fieldname'   => '_bbp_total_topic_count'
  78.         );
  79.  
  80.         // Forum total reply count (Includes unpublished replies, Stored in postmeta)
  81.         $this->field_map[] = array(
  82.             'from_tablename' => 'forums',
  83.             'from_fieldname' => 'forum_posts_approved',
  84.             'to_type'        => 'forum',
  85.             'to_fieldname'   => '_bbp_total_reply_count'
  86.         );
  87.  
  88.         // Forum title.
  89.         $this->field_map[] = array(
  90.             'from_tablename' => 'forums',
  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'  => 'forums',
  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'  => 'forums',
  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' => 'forums',
  117.             'from_fieldname' => 'left_id',
  118.             'to_type'        => 'forum',
  119.             'to_fieldname'   => 'menu_order'
  120.         );
  121.  
  122.         // Forum type (Category = 0 or Forum = 1, Stored in postmeta)
  123.         $this->field_map[] = array(
  124.             'from_tablename'  => 'forums',
  125.             'from_fieldname'  => 'forum_type',
  126.             'to_type'         => 'forum',
  127.             'to_fieldname'    => '_bbp_forum_type',
  128.             'callback_method' => 'callback_forum_type'
  129.         );
  130.  
  131.         // Forum status (Unlocked = 0 or Locked = 1, Stored in postmeta)
  132.         $this->field_map[] = array(
  133.             'from_tablename'  => 'forums',
  134.             'from_fieldname'  => 'forum_status',
  135.             'to_type'         => 'forum',
  136.             'to_fieldname'    => '_bbp_status',
  137.             'callback_method' => 'callback_forum_status'
  138.         );
  139.  
  140.         // Forum dates.
  141.         $this->field_map[] = array(
  142.             'to_type'      => 'forum',
  143.             'to_fieldname' => 'post_date',
  144.             'default'      => date('Y-m-d H:i:s')
  145.         );
  146.         $this->field_map[] = array(
  147.             'to_type'      => 'forum',
  148.             'to_fieldname' => 'post_date_gmt',
  149.             'default'      => date('Y-m-d H:i:s')
  150.         );
  151.         $this->field_map[] = array(
  152.             'to_type'      => 'forum',
  153.             'to_fieldname' => 'post_modified',
  154.             'default'      => date('Y-m-d H:i:s')
  155.         );
  156.         $this->field_map[] = array(
  157.             'to_type'      => 'forum',
  158.             'to_fieldname' => 'post_modified_gmt',
  159.             'default'      => date('Y-m-d H:i:s')
  160.         );
  161.  
  162.         /** Forum Subscriptions Section ***************************************/
  163.  
  164.         // Subscribed forum ID (Stored in usermeta)
  165.         $this->field_map[] = array(
  166.             'from_tablename'  => 'forums_watch',
  167.             'from_fieldname'  => 'forum_id',
  168.             'to_type'         => 'forum_subscriptions',
  169.             'to_fieldname'    => '_bbp_forum_subscriptions'
  170.         );
  171.  
  172.         // Subscribed user ID (Stored in usermeta)
  173.         $this->field_map[] = array(
  174.             'from_tablename'  => 'forums_watch',
  175.             'from_fieldname'  => 'user_id',
  176.             'to_type'         => 'forum_subscriptions',
  177.             'to_fieldname'    => 'user_id',
  178.             'callback_method' => 'callback_userid'
  179.         );
  180.  
  181.         /** Topic Section *****************************************************/
  182.  
  183.         // Old topic id (Stored in postmeta)
  184.         $this->field_map[] = array(
  185.             'from_tablename' => 'topics',
  186.             'from_fieldname' => 'topic_id',
  187.             'to_type'        => 'topic',
  188.             'to_fieldname'   => '_bbp_old_topic_id'
  189.         );
  190.  
  191.         // Topic reply count (Stored in postmeta)
  192.         $this->field_map[] = array(
  193.             'from_tablename'  => 'topics',
  194.             'from_fieldname'  => 'topic_posts_approved',
  195.             'to_type'         => 'topic',
  196.             'to_fieldname'    => '_bbp_reply_count',
  197.             'callback_method' => 'callback_topic_reply_count'
  198.         );
  199.  
  200.         // Topic total reply count (Includes unpublished replies, Stored in postmeta)
  201.         $this->field_map[] = array(
  202.             'from_tablename'  => 'topics',
  203.             'from_fieldname'  => 'topic_posts_approved',
  204.             'to_type'         => 'topic',
  205.             'to_fieldname'    => '_bbp_total_reply_count',
  206.             'callback_method' => 'callback_topic_reply_count'
  207.         );
  208.  
  209.         // Topic parent forum id (If no parent, then 0. Stored in postmeta)
  210.         $this->field_map[] = array(
  211.             'from_tablename'  => 'topics',
  212.             'from_fieldname'  => 'forum_id',
  213.             'to_type'         => 'topic',
  214.             'to_fieldname'    => '_bbp_forum_id',
  215.             'callback_method' => 'callback_forumid'
  216.         );
  217.  
  218.         // Topic author.
  219.         $this->field_map[] = array(
  220.             'from_tablename'  => 'topics',
  221.             'from_fieldname'  => 'topic_poster',
  222.             'to_type'         => 'topic',
  223.             'to_fieldname'    => 'post_author',
  224.             'callback_method' => 'callback_userid'
  225.         );
  226.  
  227.         // Topic author name (Stored in postmeta as _bbp_anonymous_name)
  228.         $this->field_map[] = array(
  229.             'from_tablename'  => 'topics',
  230.             'from_fieldname'  => 'topic_first_poster_name',
  231.             'to_type'         => 'topic',
  232.             'to_fieldname'    => '_bbp_old_topic_author_name_id'
  233.         );
  234.  
  235.         // Is the topic anonymous (Stored in postmeta)
  236.         $this->field_map[] = array(
  237.             'from_tablename'  => 'topics',
  238.             'from_fieldname'  => 'topic_poster',
  239.             'to_type'         => 'topic',
  240.             'to_fieldname'    => '_bbp_old_is_topic_anonymous_id',
  241.             'callback_method' => 'callback_check_anonymous'
  242.         );
  243.  
  244.         // Topic Author ip (Stored in postmeta)
  245.         $this->field_map[] = array(
  246.             'from_tablename'  => 'posts',
  247.             'from_fieldname'  => 'poster_ip',
  248.             'join_tablename'  => 'topics',
  249.             'join_type'       => 'INNER',
  250.             'join_expression' => 'USING (topic_id) WHERE posts.post_id = topics.topic_first_post_id',
  251.             'to_type'         => 'topic',
  252.             'to_fieldname'    => '_bbp_author_ip'
  253.         );
  254.  
  255.         // Topic content.
  256.         // Note: We join the 'posts' table because 'topics' does not include topic content.
  257.         $this->field_map[] = array(
  258.             'from_tablename'  => 'posts',
  259.             'from_fieldname'  => 'post_text',
  260.             'join_tablename'  => 'topics',
  261.             'join_type'       => 'INNER',
  262.             'join_expression' => 'USING (topic_id) WHERE posts.post_id = topics.topic_first_post_id',
  263.             'to_type'         => 'topic',
  264.             'to_fieldname'    => 'post_content',
  265.             'callback_method' => 'callback_html'
  266.         );
  267.  
  268.         // Topic title.
  269.         $this->field_map[] = array(
  270.             'from_tablename' => 'topics',
  271.             'from_fieldname' => 'topic_title',
  272.             'to_type'        => 'topic',
  273.             'to_fieldname'   => 'post_title'
  274.         );
  275.  
  276.         // Topic slug (Clean name to avoid conflicts)
  277.         $this->field_map[] = array(
  278.             'from_tablename'  => 'topics',
  279.             'from_fieldname'  => 'topic_title',
  280.             'to_type'         => 'topic',
  281.             'to_fieldname'    => 'post_name',
  282.             'callback_method' => 'callback_slug'
  283.         );
  284.  
  285.         // Topic status (Open or Closed)
  286.         $this->field_map[] = array(
  287.             'from_tablename'  => 'topics',
  288.             'from_fieldname'  => 'topic_status',
  289.             'to_type'         => 'topic',
  290.             'to_fieldname'    => '_bbp_old_closed_status_id',
  291.             'callback_method' => 'callback_topic_status'
  292.         );
  293.  
  294.         // Topic parent forum id (If no parent, then 0)
  295.         $this->field_map[] = array(
  296.             'from_tablename'  => 'topics',
  297.             'from_fieldname'  => 'forum_id',
  298.             'to_type'         => 'topic',
  299.             'to_fieldname'    => 'post_parent',
  300.             'callback_method' => 'callback_forumid'
  301.         );
  302.  
  303.         // Sticky status (Stored in postmeta)
  304.         $this->field_map[] = array(
  305.             'from_tablename'  => 'topics',
  306.             'from_fieldname'  => 'topic_type',
  307.             'to_type'         => 'topic',
  308.             'to_fieldname'    => '_bbp_old_sticky_status_id',
  309.             'callback_method' => 'callback_sticky_status'
  310.         );
  311.  
  312.         // Topic dates.
  313.         $this->field_map[] = array(
  314.             'from_tablename'  => 'topics',
  315.             'from_fieldname'  => 'topic_time',
  316.             'to_type'         => 'topic',
  317.             'to_fieldname'    => 'post_date',
  318.             'callback_method' => 'callback_datetime'
  319.         );
  320.         $this->field_map[] = array(
  321.             'from_tablename'  => 'topics',
  322.             'from_fieldname'  => 'topic_time',
  323.             'to_type'         => 'topic',
  324.             'to_fieldname'    => 'post_date_gmt',
  325.             'callback_method' => 'callback_datetime'
  326.         );
  327.         $this->field_map[] = array(
  328.             'from_tablename'  => 'topics',
  329.             'from_fieldname'  => 'topic_time',
  330.             'to_type'         => 'topic',
  331.             'to_fieldname'    => 'post_modified',
  332.             'callback_method' => 'callback_datetime'
  333.         );
  334.         $this->field_map[] = array(
  335.             'from_tablename'  => 'topics',
  336.             'from_fieldname'  => 'topic_time',
  337.             'to_type'         => 'topic',
  338.             'to_fieldname'    => 'post_modified_gmt',
  339.             'callback_method' => 'callback_datetime'
  340.         );
  341.         $this->field_map[] = array(
  342.             'from_tablename'  => 'topics',
  343.             'from_fieldname'  => 'topic_last_post_time',
  344.             'to_type'         => 'topic',
  345.             'to_fieldname'    => '_bbp_last_active_time',
  346.             'callback_method' => 'callback_datetime'
  347.         );
  348.  
  349.         /** Tags Section ******************************************************/
  350.  
  351.         /**
  352.          * phpBB Forums do not support topic tags
  353.          */
  354.  
  355.         /** Topic Subscriptions Section ***************************************/
  356.  
  357.         // Subscribed topic ID (Stored in usermeta)
  358.         $this->field_map[] = array(
  359.             'from_tablename'  => 'topics_watch',
  360.             'from_fieldname'  => 'topic_id',
  361.             'to_type'         => 'topic_subscriptions',
  362.             'to_fieldname'    => '_bbp_subscriptions'
  363.         );
  364.  
  365.         // Subscribed user ID (Stored in usermeta)
  366.         $this->field_map[] = array(
  367.             'from_tablename'  => 'topics_watch',
  368.             'from_fieldname'  => 'user_id',
  369.             'to_type'         => 'topic_subscriptions',
  370.             'to_fieldname'    => 'user_id',
  371.             'callback_method' => 'callback_userid'
  372.         );
  373.  
  374.         /** Favorites Section *************************************************/
  375.  
  376.         // Favorited topic ID (Stored in usermeta)
  377.         $this->field_map[] = array(
  378.             'from_tablename'  => 'bookmarks',
  379.             'from_fieldname'  => 'topic_id',
  380.             'to_type'         => 'favorites',
  381.             'to_fieldname'    => '_bbp_favorites'
  382.         );
  383.  
  384.         // Favorited user ID (Stored in usermeta)
  385.         $this->field_map[] = array(
  386.             'from_tablename'  => 'bookmarks',
  387.             'from_fieldname'  => 'user_id',
  388.             'to_type'         => 'favorites',
  389.             'to_fieldname'    => 'user_id',
  390.             'callback_method' => 'callback_userid'
  391.         );
  392.  
  393.         /** Reply Section *****************************************************/
  394.  
  395.         // Old reply id (Stored in postmeta)
  396.         $this->field_map[] = array(
  397.             'from_tablename' => 'posts',
  398.             'from_fieldname' => 'post_id',
  399.             'to_type'        => 'reply',
  400.             'to_fieldname'   => '_bbp_old_reply_id'
  401.         );
  402.  
  403.         // Setup reply section table joins
  404.         $this->field_map[] = array(
  405.             'from_tablename'  => 'topics',
  406.             'from_fieldname'  => 'topic_id',
  407.             'join_tablename'  => 'posts',
  408.             'join_type'       => 'LEFT',
  409.             'join_expression' => 'USING (topic_id) WHERE posts.post_id != topics.topic_first_post_id',
  410.             'to_type'         => 'reply'
  411.         );
  412.  
  413.         // Reply parent forum id (If no parent, then 0. Stored in postmeta)
  414.         $this->field_map[] = array(
  415.             'from_tablename'  => 'posts',
  416.             'from_fieldname'  => 'forum_id',
  417.             'to_type'         => 'reply',
  418.             'to_fieldname'    => '_bbp_forum_id',
  419.             'callback_method' => 'callback_forumid'
  420.         );
  421.  
  422.         // Reply parent topic id (If no parent, then 0. Stored in postmeta)
  423.         $this->field_map[] = array(
  424.             'from_tablename'  => 'posts',
  425.             'from_fieldname'  => 'topic_id',
  426.             'to_type'         => 'reply',
  427.             'to_fieldname'    => '_bbp_topic_id',
  428.             'callback_method' => 'callback_topicid'
  429.         );
  430.  
  431.         // Reply author ip (Stored in postmeta)
  432.         $this->field_map[] = array(
  433.             'from_tablename' => 'posts',
  434.             'from_fieldname' => 'poster_ip',
  435.             'to_type'        => 'reply',
  436.             'to_fieldname'   => '_bbp_author_ip'
  437.         );
  438.  
  439.         // Reply author.
  440.         $this->field_map[] = array(
  441.             'from_tablename'  => 'posts',
  442.             'from_fieldname'  => 'poster_id',
  443.             'to_type'         => 'reply',
  444.             'to_fieldname'    => 'post_author',
  445.             'callback_method' => 'callback_userid'
  446.         );
  447.  
  448.         // Reply author name (Stored in postmeta as _bbp_anonymous_name)
  449.         $this->field_map[] = array(
  450.             'from_tablename'  => 'posts',
  451.             'from_fieldname'  => 'post_username',
  452.             'to_type'         => 'reply',
  453.             'to_fieldname'    => '_bbp_old_reply_author_name_id'
  454.         );
  455.  
  456.         // Is the reply anonymous (Stored in postmeta)
  457.         $this->field_map[] = array(
  458.             'from_tablename'  => 'posts',
  459.             'from_fieldname'  => 'poster_id',
  460.             'to_type'         => 'reply',
  461.             'to_fieldname'    => '_bbp_old_is_reply_anonymous_id',
  462.             'callback_method' => 'callback_check_anonymous'
  463.         );
  464.  
  465.         // Reply content.
  466.         $this->field_map[] = array(
  467.             'from_tablename'  => 'posts',
  468.             'from_fieldname'  => 'post_text',
  469.             'to_type'         => 'reply',
  470.             'to_fieldname'    => 'post_content',
  471.             'callback_method' => 'callback_html'
  472.         );
  473.  
  474.         // Reply parent topic id (If no parent, then 0)
  475.         $this->field_map[] = array(
  476.             'from_tablename'  => 'posts',
  477.             'from_fieldname'  => 'topic_id',
  478.             'to_type'         => 'reply',
  479.             'to_fieldname'    => 'post_parent',
  480.             'callback_method' => 'callback_topicid'
  481.         );
  482.  
  483.         // Reply dates.
  484.         $this->field_map[] = array(
  485.             'from_tablename'  => 'posts',
  486.             'from_fieldname'  => 'post_time',
  487.             'to_type'         => 'reply',
  488.             'to_fieldname'    => 'post_date',
  489.             'callback_method' => 'callback_datetime'
  490.         );
  491.         $this->field_map[] = array(
  492.             'from_tablename'  => 'posts',
  493.             'from_fieldname'  => 'post_time',
  494.             'to_type'         => 'reply',
  495.             'to_fieldname'    => 'post_date_gmt',
  496.             'callback_method' => 'callback_datetime'
  497.         );
  498.         $this->field_map[] = array(
  499.             'from_tablename'  => 'posts',
  500.             'from_fieldname'  => 'post_time',
  501.             'to_type'         => 'reply',
  502.             'to_fieldname'    => 'post_modified',
  503.             'callback_method' => 'callback_datetime'
  504.         );
  505.         $this->field_map[] = array(
  506.             'from_tablename'  => 'posts',
  507.             'from_fieldname'  => 'post_time',
  508.             'to_type'         => 'reply',
  509.             'to_fieldname'    => 'post_modified_gmt',
  510.             'callback_method' => 'callback_datetime'
  511.         );
  512.  
  513.         /** User Section ******************************************************/
  514.  
  515.         // Store old user id (Stored in usermeta)
  516.         // Don't import users with id 2, these are phpBB bot/crawler accounts
  517.         $this->field_map[] = array(
  518.             'from_tablename'  => 'users',
  519.             'from_fieldname'  => 'user_id',
  520.             'to_type'         => 'user',
  521.             'to_fieldname'    => '_bbp_old_user_id'
  522.         );
  523.  
  524.         // Store old user password (Stored in usermeta serialized with salt)
  525.         $this->field_map[] = array(
  526.             'from_tablename'  => 'users',
  527.             'from_fieldname'  => 'user_password',
  528.             'to_type'         => 'user',
  529.             'to_fieldname'    => '_bbp_password',
  530.             'callback_method' => 'callback_savepass'
  531.         );
  532.  
  533.         // Store old user salt (This is only used for the SELECT row info for the above password save)
  534.         $this->field_map[] = array(
  535.             'from_tablename' => 'users',
  536.             'from_fieldname' => 'user_form_salt',
  537.             'to_type'        => 'user',
  538.             'to_fieldname'   => ''
  539.         );
  540.  
  541.         // User password verify class (Stored in usermeta for verifying password)
  542.         $this->field_map[] = array(
  543.             'to_type'      => 'user',
  544.             'to_fieldname' => '_bbp_class',
  545.             'default'      => 'phpBB'
  546.         );
  547.  
  548.         // User name.
  549.         $this->field_map[] = array(
  550.             'from_tablename' => 'users',
  551.             'from_fieldname' => 'username',
  552.             'to_type'        => 'user',
  553.             'to_fieldname'   => 'user_login'
  554.         );
  555.  
  556.         // User email.
  557.         $this->field_map[] = array(
  558.             'from_tablename' => 'users',
  559.             'from_fieldname' => 'user_email',
  560.             'to_type'        => 'user',
  561.             'to_fieldname'   => 'user_email'
  562.         );
  563.  
  564.         // User homepage.
  565.         $this->field_map[] = array(
  566.             'from_tablename'  => 'profile_fields_data',
  567.             'from_fieldname'  => 'pf_phpbb_website',
  568.             'join_tablename'  => 'users',
  569.             'join_type'       => 'LEFT',
  570.             'join_expression' => 'USING (user_id) WHERE users.user_type !=2',
  571.             'to_type'         => 'user',
  572.             'to_fieldname'    => 'user_url'
  573.         );
  574.  
  575.         // User registered.
  576.         $this->field_map[] = array(
  577.             'from_tablename'  => 'users',
  578.             'from_fieldname'  => 'user_regdate',
  579.             'to_type'         => 'user',
  580.             'to_fieldname'    => 'user_registered',
  581.             'callback_method' => 'callback_datetime'
  582.         );
  583.  
  584.         // User AOL/AIM (Stored in usermeta)
  585. /*      $this->field_map[] = array(
  586.             'from_tablename' => 'profile_fields_data',
  587.             'from_fieldname' => 'pf_phpbb_aol',
  588.             'to_type'        => 'user',
  589.             'to_fieldname'   => '_bbp_phpbb_user_aim'
  590.         );
  591.  
  592.         // User Yahoo (Stored in usermeta)
  593.         $this->field_map[] = array(
  594.             'from_tablename' => 'profile_fields_data',
  595.             'from_fieldname' => 'pf_phpbb_yahoo',
  596.             'to_type'        => 'user',
  597.             'to_fieldname'   => '_bbp_phpbb_user_yim'
  598.         );
  599.  
  600.         // Store ICQ (Stored in usermeta)
  601.         $this->field_map[] = array(
  602.             'from_tablename' => 'profile_fields_data',
  603.             'from_fieldname' => 'pf_phpbb_icq',
  604.             'to_type'        => 'user',
  605.             'to_fieldname'   => '_bbp_phpbb_user_icq'
  606.         );
  607.  
  608.         // Store MSN/WLM (Stored in usermeta)
  609.         $this->field_map[] = array(
  610.             'from_tablename' => 'profile_fields_data',
  611.             'from_fieldname' => 'pf_phpbb_wlm',
  612.             'to_type'        => 'user',
  613.             'to_fieldname'   => '_bbp_phpbb_user_msnm'
  614.         );*/
  615.  
  616.         // Store Facebook (Stored in usermeta)
  617.         $this->field_map[] = array(
  618.             'from_tablename' => 'profile_fields_data',
  619.             'from_fieldname' => 'pf_phpbb_facebook',
  620.             'to_type'        => 'user',
  621.             'to_fieldname'   => '_bbp_phpbb_user_facebook'
  622.         );
  623.  
  624.         // Store Google+ (Stored in usermeta)
  625.         $this->field_map[] = array(
  626.             'from_tablename' => 'profile_fields_data',
  627.             'from_fieldname' => 'pf_phpbb_googleplus',
  628.             'to_type'        => 'user',
  629.             'to_fieldname'   => '_bbp_phpbb_user_googleplus'
  630.         );
  631.  
  632.         // Store Skype (Stored in usermeta)
  633.         $this->field_map[] = array(
  634.             'from_tablename' => 'profile_fields_data',
  635.             'from_fieldname' => 'pf_phpbb_skype',
  636.             'to_type'        => 'user',
  637.             'to_fieldname'   => '_bbp_phpbb_user_skype'
  638.         );
  639.  
  640.         // Store Twitter (Stored in usermeta)
  641.         $this->field_map[] = array(
  642.             'from_tablename' => 'profile_fields_data',
  643.             'from_fieldname' => 'pf_phpbb_twitter',
  644.             'to_type'        => 'user',
  645.             'to_fieldname'   => '_bbp_phpbb_user_twitter'
  646.         );
  647.  
  648.         // Store Youtube (Stored in usermeta)
  649.         $this->field_map[] = array(
  650.             'from_tablename' => 'profile_fields_data',
  651.             'from_fieldname' => 'pf_phpbb_youtube',
  652.             'to_type'        => 'user',
  653.             'to_fieldname'   => '_bbp_phpbb_user_youtube'
  654.         );
  655.  
  656.         // Store Jabber
  657.     /*  $this->field_map[] = array(
  658.             'from_tablename' => 'users',
  659.             'from_fieldname' => 'user_jabber',
  660.             'to_type'        => 'user',
  661.             'to_fieldname'   => '_bbp_phpbb_user_jabber'
  662.         );*/
  663.  
  664.         // Store Occupation (Stored in usermeta)
  665.     /*  $this->field_map[] = array(
  666.             'from_tablename' => 'profile_fields_data',
  667.             'from_fieldname' => 'pf_phpbb_occupation',
  668.             'to_type'        => 'user',
  669.             'to_fieldname'   => '_bbp_phpbb_user_occ'
  670.         );*/
  671.        
  672.        
  673.         // Store Occupation (Stored in usermeta)
  674.         $this->field_map[] = array(
  675.             'from_tablename' => 'profile_fields_data',
  676.             'from_fieldname' => 'pf_phpbb_occupation',
  677.             'join_type'       => 'LEFT',
  678.             'join_expression' => 'USING (user_id) WHERE users.user_type !=2',                                  
  679.             'to_type'        => 'user',
  680.             'to_fieldname'   => '_bbp_phpbb_user_occ'
  681.         );
  682.        
  683.  
  684.         // Store Interests (Stored in usermeta)
  685.     /*  $this->field_map[] = array(
  686.             'from_tablename' => 'profile_fields_data',
  687.             'from_fieldname' => 'pf_phpbb_interests',
  688.             'to_type'        => 'user',
  689.             'to_fieldname'   => '_bbp_phpbb_user_interests'
  690.         );*/
  691.        
  692.        
  693.       $this->field_map[] = array(
  694.             'from_tablename' => 'profile_fields_data',
  695.             'from_fieldname' => 'pf_phpbb_interests',
  696.             'join_type'       => 'LEFT',
  697.             'join_expression' => 'USING (user_id) WHERE users.user_type !=2',                                  
  698.             'to_type'        => 'user',
  699.             'to_fieldname'   => '_bbp_phpbb_user_interests'
  700.         );
  701.  
  702.        
  703.  
  704.         // Store Signature (Stored in usermeta)
  705.         $this->field_map[] = array(
  706.             'from_tablename' => 'users',
  707.             'from_fieldname' => 'user_sig',
  708.             'to_type'        => 'user',
  709.             'to_fieldname'   => '_bbp_phpbb_user_sig',
  710.             'callback_method' => 'callback_html'
  711.         );
  712.  
  713.         // Store Location (Stored in usermeta)
  714.     /*  $this->field_map[] = array(
  715.             'from_tablename' => 'profile_fields_data',
  716.             'from_fieldname' => 'pf_phpbb_location',
  717.             'to_type'        => 'user',
  718.             'to_fieldname'   => '_bbp_phpbb_user_from'
  719.         );*/
  720.        
  721.             $this->field_map[] = array(
  722.             'from_tablename' => 'profile_fields_data',
  723.             'from_fieldname' => 'pf_phpbb_location',
  724.             'join_type'       => 'LEFT',
  725.             'join_expression' => 'USING (user_id) WHERE users.user_type !=2',                                              
  726.             'to_type'        => 'user',
  727.             'to_fieldname'   => '_bbp_phpbb_user_from'
  728.         );
  729.        
  730.  
  731.         // Store Avatar Filename (Stored in usermeta)
  732.         $this->field_map[] = array(
  733.             'from_tablename' => 'users',
  734.             'from_fieldname' => 'user_avatar',
  735.             'to_type'        => 'user',
  736.             'to_fieldname'   => '_bbp_phpbb_user_avatar'
  737.         );
  738.  
  739.         // Store old role (Stored in usermeta)
  740.     }
  741.  
  742.     /**
  743.      * This method allows us to indicates what is or is not converted for each
  744.      * converter.
  745.      */
  746.     public function info() {
  747.         return '';
  748.     }
  749.  
  750.     /**
  751.      * This method is to save the salt and password together.  That
  752.      * way when we authenticate it we can get it out of the database
  753.      * as one value.
  754.      */
  755.     public function callback_savepass( $field, $row ) {
  756.         return array(
  757.             'hash' => $field,
  758.             'salt' => $row['user_form_salt']
  759.         );
  760.     }
  761.  
  762.     /**
  763.      * Check for correct password
  764.      *
  765.      * @param string $password The password in plain text
  766.      * @param string $hash The stored password hash
  767.      *
  768.      * @link Original source for password functions http://openwall.com/phpass/
  769.      * @link phpass is now included in WP Core https://core.trac.wordpress.org/browser/trunk/wp-includes/class-phpass.php
  770.      *
  771.      * @return bool Returns true if the password is correct, false if not.
  772.      */
  773.     public function authenticate_pass( $password, $serialized_pass ) {
  774.         $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  775.         $pass_array = unserialize( $serialized_pass );
  776.         if ( strlen( $pass_array['hash'] ) == 34 ) {
  777.             return ( $this->_hash_crypt_private( $password, $pass_array['hash'], $itoa64 ) === $pass_array['hash'] ) ? true : false;
  778.         }
  779.  
  780.         return ( md5( $password ) === $pass_array['hash'] ) ? true : false;
  781.     }
  782.  
  783.     /**
  784.      * The crypt function/replacement
  785.      */
  786.     private function _hash_crypt_private( $password, $setting, &$itoa64 ) {
  787.         $output = '*';
  788.  
  789.         // Check for correct hash
  790.         if ( substr( $setting, 0, 3 ) != '$H$' ) {
  791.             return $output;
  792.         }
  793.  
  794.         $count_log2 = strpos( $itoa64, $setting[3] );
  795.  
  796.         if ( $count_log2 < 7 || $count_log2 > 30 ) {
  797.             return $output;
  798.         }
  799.  
  800.         $count = 1 << $count_log2;
  801.         $salt  = substr( $setting, 4, 8 );
  802.  
  803.         if ( strlen( $salt ) != 8 ) {
  804.             return $output;
  805.         }
  806.  
  807.         /**
  808.          * We're kind of forced to use MD5 here since it's the only
  809.          * cryptographic primitive available in all versions of PHP
  810.          * currently in use.  To implement our own low-level crypto
  811.          * in PHP would result in much worse performance and
  812.          * consequently in lower iteration counts and hashes that are
  813.          * quicker to crack (by non-PHP code).
  814.          */
  815.         if ( floatval( phpversion() ) >= 5 ) {
  816.             $hash = md5( $salt . $password, true );
  817.             do {
  818.                 $hash = md5( $hash . $password, true );
  819.             }
  820.             while ( --$count );
  821.         } else {
  822.             $hash = pack( 'H*', md5( $salt . $password ) );
  823.             do {
  824.                 $hash = pack( 'H*', md5( $hash . $password ) );
  825.             }
  826.             while ( --$count );
  827.         }
  828.  
  829.         $output = substr($setting, 0, 12);
  830.         $output .= $this->_hash_encode64($hash, 16, $itoa64);
  831.  
  832.         return $output;
  833.     }
  834.  
  835.     /**
  836.      * Encode hash
  837.      */
  838.     private function _hash_encode64( $input, $count, &$itoa64 ) {
  839.         $output = '';
  840.         $i = 0;
  841.  
  842.         do {
  843.             $value = ord( $input[ $i++ ] );
  844.             $output .= $itoa64[ $value & 0x3f ];
  845.  
  846.             if ($i < $count) {
  847.                 $value |= ord( $input[ $i ] ) << 8;
  848.             }
  849.  
  850.             $output .= $itoa64[( $value >> 6 ) & 0x3f];
  851.  
  852.             if ( $i++ >= $count ) {
  853.                 break;
  854.             }
  855.  
  856.             if ( $i < $count ) {
  857.                 $value |= ord( $input[ $i ] ) << 16;
  858.             }
  859.  
  860.             $output .= $itoa64[( $value >> 12 ) & 0x3f];
  861.  
  862.             if ( $i++ >= $count ) {
  863.                 break;
  864.             }
  865.  
  866.             $output .= $itoa64[($value >> 18) & 0x3f];
  867.         } while ( $i < $count );
  868.  
  869.         return $output;
  870.     }
  871.  
  872.     /**
  873.      * Translate the forum type from phpBB v3.x numerics to WordPress's strings.
  874.      *
  875.      * @param int $status phpBB v3.x numeric forum type
  876.      * @return string WordPress safe
  877.      */
  878.     public function callback_forum_type( $status = 1 ) {
  879.         switch ( $status ) {
  880.             case 0 :
  881.                 $status = 'category';
  882.                 break;
  883.  
  884.             case 1  :
  885.             default :
  886.                 $status = 'forum';
  887.                 break;
  888.         }
  889.         return $status;
  890.     }
  891.  
  892.     /**
  893.      * Translate the forum status from phpBB v3.x numerics to WordPress's strings.
  894.      *
  895.      * @param int $status phpBB v3.x numeric forum status
  896.      * @return string WordPress safe
  897.      */
  898.     public function callback_forum_status( $status = 0 ) {
  899.         switch ( $status ) {
  900.             case 1 :
  901.                 $status = 'closed';
  902.                 break;
  903.  
  904.             case 0  :
  905.             default :
  906.                 $status = 'open';
  907.                 break;
  908.         }
  909.         return $status;
  910.     }
  911.  
  912.     /**
  913.      * Translate the topic status from phpBB v3.x numerics to WordPress's strings.
  914.      *
  915.      * @param int $status phpBB v3.x numeric topic status
  916.      * @return string WordPress safe
  917.      */
  918.     public function callback_topic_status( $status = 0 ) {
  919.         switch ( $status ) {
  920.             case 1 :
  921.                 $status = 'closed';
  922.                 break;
  923.  
  924.             case 0 :
  925.             default :
  926.                 $status = 'publish';
  927.                 break;
  928.         }
  929.         return $status;
  930.     }
  931.  
  932.     /**
  933.      * Translate the topic sticky status type from phpBB 3.x numerics to WordPress's strings.
  934.      *
  935.      * @param int $status phpBB 3.x numeric forum type
  936.      * @return string WordPress safe
  937.      */
  938.     public function callback_sticky_status( $status = 0 ) {
  939.         switch ( $status ) {
  940.             case 3 :
  941.                 $status = 'super-sticky'; // phpBB Global Sticky 'topic_type = 3'
  942.                 break;
  943.  
  944.             case 2 :
  945.                 $status = 'super-sticky'; // phpBB Announcement Sticky 'topic_type = 2'
  946.                 break;
  947.  
  948.             case 1 :
  949.                 $status = 'sticky';       // phpBB Sticky 'topic_type = 1'
  950.                 break;
  951.  
  952.             case 0  :
  953.             default :
  954.                 $status = 'normal';       // phpBB normal topic 'topic_type = 0'
  955.                 break;
  956.         }
  957.         return $status;
  958.     }
  959.  
  960.     /**
  961.      * Verify the topic reply count.
  962.      *
  963.      * @param int $count phpBB v3.x reply count
  964.      * @return string WordPress safe
  965.      */
  966.     public function callback_topic_reply_count( $count = 1 ) {
  967.         $count = absint( (int) $count - 1 );
  968.         return $count;
  969.     }
  970.  
  971.     /**
  972.      * This callback processes any custom parser.php attributes and custom code with preg_replace
  973.      */
  974.     protected function callback_html( $field ) {
  975.  
  976.         // Strips custom phpBB 'magic_url' and 'bbcode_uid' first from $field before parsing $field to parser.php
  977.         $phpbb_uid = $field;
  978.         $phpbb_uid = html_entity_decode( $phpbb_uid );
  979.  
  980.         // Replace '[b:XXXXXXX]' with '<strong>'
  981.         $phpbb_uid = preg_replace( '/\[b:(.*?)\]/',   '<strong>',  $phpbb_uid );
  982.         // Replace '[/b:XXXXXXX]' with '</strong>'
  983.         $phpbb_uid = preg_replace( '/\[\/b:(.*?)\]/', '</strong>', $phpbb_uid );
  984.  
  985.         // Replace '[i:XXXXXXX]' with '<em>'
  986.         $phpbb_uid = preg_replace( '/\[i:(.*?)\]/',   '<em>',      $phpbb_uid );
  987.         // Replace '[/i:XXXXXXX]' with '</em>'
  988.         $phpbb_uid = preg_replace( '/\[\/i:(.*?)\]/', '</em>',     $phpbb_uid );
  989.  
  990.         // Replace '[u:XXXXXXX]' with '<u>'
  991.         $phpbb_uid = preg_replace( '/\[u:(.*?)\]/',   '<u>',       $phpbb_uid );
  992.         // Replace '[/u:XXXXXXX]' with '</u>'
  993.         $phpbb_uid = preg_replace( '/\[\/u:(.*?)\]/', '</u>',      $phpbb_uid );
  994.  
  995.         // Replace '[quote:XXXXXXX]' with '<blockquote>'
  996.         $phpbb_uid = preg_replace( '/\[quote:(.*?)\]/',          '<blockquote>',                   $phpbb_uid );
  997.         // Replace '[quote="$1"]' with '<em>$1 wrote:</em><blockquote>"
  998.         $phpbb_uid = preg_replace( '/\[quote="(.*?)":(.*?)\]/', '<em>@$1 wrote:</em><blockquote>', $phpbb_uid );
  999.         // Replace '[/quote:XXXXXXX]' with '</blockquote>'
  1000.         $phpbb_uid = preg_replace( '/\[\/quote:(.*?)\]/',       '</blockquote>',                   $phpbb_uid );
  1001.  
  1002.         // Replace '[img:XXXXXXX]' with '<img src="'
  1003.         $phpbb_uid = preg_replace( '/\[img:(.*?)\]/',   '<img src="', $phpbb_uid );
  1004.         // Replace '[/img:XXXXXXX]' with ' alt="">'
  1005.         $phpbb_uid = preg_replace( '/\[\/img:(.*?)\]/', '" alt="">',  $phpbb_uid );
  1006.  
  1007.         // Replace '<!-- s$1 --><img src=\"{SMILIES_PATH}$2 -->' with '$1'
  1008.         $phpbb_uid = preg_replace( '/<!-- s(.*?) --><img src=\"{SMILIES_PATH}(.*?)-->/', '$1', $phpbb_uid );
  1009.  
  1010.         // Replace '<!-- m --><a class="postlink" href="$1">$1</a><!-- m -->' with '$1'
  1011.         $phpbb_uid = preg_replace( '/\<!-- m --\>\<a class="postlink" href="([^\[]+?)"\>([^\[]+?)\<\/a\>\<!-- m --\>/', '$1', $phpbb_uid );
  1012.  
  1013.         // Replace '[url:XXXXXXX]$1[/url:XXXXXXX]' with '<a href="http://$1">$1</a>'
  1014.         $phpbb_uid = preg_replace( '/\[url:(?:[^\]]+)\]([^\[]+?)\[\/url:(?:[^\]]+)\]/',       '<a href="http://$1">$1</a>',  $phpbb_uid );
  1015.         // Replace '[url=http://$1:XXXXXXX]$3[/url:XXXXXXX]' with '<a href="http://$1">$3</a>'
  1016.         $phpbb_uid = preg_replace( '/\[url\=http\:\/\/(.*?)\:(.*?)\](.*?)\[\/url:(.*?)\]/i',  '<a href="http://$1">$3</a>',  $phpbb_uid );
  1017.         // Replace '[url=https://$1:XXXXXXX]$3[/url:XXXXXXX]' with '<a href="http://$1">$3</a>'
  1018.         $phpbb_uid = preg_replace( '/\[url\=https\:\/\/(.*?)\:(.*?)\](.*?)\[\/url:(.*?)\]/i', '<a href="https://$1">$3</a>', $phpbb_uid );
  1019.  
  1020.         // Replace '[email:XXXXXXX]' with '<a href="mailto:$2">$2</a>'
  1021.         $phpbb_uid = preg_replace( '/\[email:(.*?)\](.*?)\[\/email:(.*?)\]/', '<a href="mailto:$2">$2</a>', $phpbb_uid );
  1022.         // Replace '<!-- e -->no.one@domain.adr<!-- e -->' with '$1'
  1023.         $phpbb_uid = preg_replace( '/\<!-- e --\>(.*?)\<!-- e --\>/', '$1', $phpbb_uid );
  1024.  
  1025.         // Replace '[code:XXXXXXX]' with '<pre><code>'
  1026.         $phpbb_uid = preg_replace( '/\[code:(.*?)\]/',   '<pre><code>',   $phpbb_uid );
  1027.         // Replace '[/code:XXXXXXX]' with '</code></pre>'
  1028.         $phpbb_uid = preg_replace( '/\[\/code:(.*?)\]/', '</code></pre>', $phpbb_uid );
  1029.  
  1030.         // Replace '[color=$1:XXXXXXXX]' with '<span style="color:$1">'
  1031.         $phpbb_uid = preg_replace( '/\[color=(.*?)\:(.*?)\]/', '<span style="color: $1">', $phpbb_uid );
  1032.         // Replace '[/color:XXXXXXX]' with '</span>'
  1033.         $phpbb_uid = preg_replace( '/\[\/color:(.*?)\]/',      '</span>',                  $phpbb_uid );
  1034.  
  1035.         // Replace '[size=$1:XXXXXXXX]' with '<span style="font-size:$1%;">$3</span>'
  1036.         $phpbb_uid = preg_replace( '/\[size=(.*?):(.*?)\]/', '<span style="font-size:$1%;">', $phpbb_uid );
  1037.         // Replace '[/size:XXXXXXX]' with ''
  1038.         $phpbb_uid = preg_replace( '/\[\/size:(.*?)\]/',     '</span>',                       $phpbb_uid );
  1039.  
  1040.         // Replace '[list:XXXXXXX]' with '<ul>'
  1041.         $phpbb_uid = preg_replace( '/\[list:(.*?)\]/',     '<ul>',          $phpbb_uid );
  1042.         // Replace '[list=a:XXXXXXX]' with '<ol type="a">'
  1043.         $phpbb_uid = preg_replace( '/\[list=a:(.*?)\]/',   '<ol type="a">', $phpbb_uid );
  1044.         // Replace '[list=1:XXXXXXX]' with '<ol>'
  1045.         $phpbb_uid = preg_replace( '/\[list=1:(.*?)\]/',   '<ol>',          $phpbb_uid );
  1046.         // Replace '[*:XXXXXXX]' with '<li>'
  1047.         $phpbb_uid = preg_replace( '/\[\*:(.*?)\]/',       '<li>',          $phpbb_uid );
  1048.         // Replace '[/*:m:XXXXXXX]' with '</li>'
  1049.         $phpbb_uid = preg_replace( '/\[\/\*:m:(.*?)\]/',   '</li>',         $phpbb_uid );
  1050.         // Replace '[/list:u:XXXXXXX]' with '</ul>'
  1051.         $phpbb_uid = preg_replace( '/\[\/list:u:(.*?)\]/', '</ul>',         $phpbb_uid );
  1052.         // Replace '[/list:o:XXXXXXX]' with '</ol>'
  1053.         $phpbb_uid = preg_replace( '/\[\/list:o:(.*?)\]/', '</ol>',         $phpbb_uid );
  1054.  
  1055.         // Now that phpBB's 'magic_url' and 'bbcode_uid' have been stripped put the cleaned HTML back in $field
  1056.         $field = $phpbb_uid;
  1057.  
  1058.         // Parse out any bbCodes in $field with the BBCode 'parser.php'
  1059.         return parent::callback_html( $field );
  1060.     }
  1061. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement