web/wp-content/plugins/bbpress/includes/admin/converters/vBulletin.php
changeset 196 5e8dcbe22c24
equal deleted inserted replaced
195:c7c0fbc09788 196:5e8dcbe22c24
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * vBulletin Converter
       
     5  *
       
     6  * @since bbPress (r)
       
     7  */
       
     8 class vBulletin extends BBP_Converter_Base {
       
     9 
       
    10 	/**
       
    11 	 * Main constructor
       
    12 	 *
       
    13 	 * @uses vBulletin::setup_globals()
       
    14 	 */
       
    15 	function __construct() {
       
    16 		parent::__construct();
       
    17 		$this->setup_globals();
       
    18 	}
       
    19 
       
    20 	/**
       
    21 	 * Sets up the field mappings
       
    22 	 */
       
    23 	private function setup_globals() {
       
    24 
       
    25 		/** Forum Section *****************************************************/
       
    26 
       
    27 		// Forum id (Stored in postmeta)
       
    28 		$this->field_map[] = array(
       
    29 			'from_tablename' => 'forum',
       
    30 			'from_fieldname' => 'forumid',
       
    31 			'to_type'        => 'forum',
       
    32 			'to_fieldname'   => '_bbp_forum_id'
       
    33 		);
       
    34 
       
    35 		// Forum parent id (If no parent, than 0. Stored in postmeta)
       
    36 		$this->field_map[] = array(
       
    37 			'from_tablename' => 'forum',
       
    38 			'from_fieldname' => 'parentid',
       
    39 			'to_type'        => 'forum',
       
    40 			'to_fieldname'   => '_bbp_forum_parent_id'
       
    41 		);
       
    42 
       
    43 		// Forum title.
       
    44 		$this->field_map[] = array(
       
    45 			'from_tablename' => 'forum',
       
    46 			'from_fieldname' => 'title',
       
    47 			'to_type'        => 'forum',
       
    48 			'to_fieldname'   => 'post_title'
       
    49 		);
       
    50 
       
    51 		// Forum slug (Clean name to avoid confilcts)
       
    52 		$this->field_map[] = array(
       
    53 			'from_tablename'  => 'forum',
       
    54 			'from_fieldname'  => 'title_clean',
       
    55 			'to_type'         => 'forum',
       
    56 			'to_fieldname'    => 'post_name',
       
    57 			'callback_method' => 'callback_slug'
       
    58 		);
       
    59 
       
    60 		// Forum description.
       
    61 		$this->field_map[] = array(
       
    62 			'from_tablename'  => 'forum',
       
    63 			'from_fieldname'  => 'description',
       
    64 			'to_type'         => 'forum',
       
    65 			'to_fieldname'    => 'post_content',
       
    66 			'callback_method' => 'callback_null'
       
    67 		);
       
    68 
       
    69 		// Forum display order (Starts from 1)
       
    70 		$this->field_map[] = array(
       
    71 			'from_tablename' => 'forum',
       
    72 			'from_fieldname' => 'displayorder',
       
    73 			'to_type'        => 'forum',
       
    74 			'to_fieldname'   => 'menu_order'
       
    75 		);
       
    76 
       
    77 		// Forum date update.
       
    78 		$this->field_map[] = array(
       
    79 			'to_type'      => 'forum',
       
    80 			'to_fieldname' => 'post_date',
       
    81 			'default'      => date( 'Y-m-d H:i:s' )
       
    82 		);
       
    83 		$this->field_map[]	 = array(
       
    84 			'to_type'      => 'forum',
       
    85 			'to_fieldname' => 'post_date_gmt',
       
    86 			'default'      => date( 'Y-m-d H:i:s' )
       
    87 		);
       
    88 		$this->field_map[]	 = array(
       
    89 			'to_type'      => 'forum',
       
    90 			'to_fieldname' => 'post_modified',
       
    91 			'default'      => date( 'Y-m-d H:i:s' )
       
    92 		);
       
    93 		$this->field_map[]	 = array(
       
    94 			'to_type'      => 'forum',
       
    95 			'to_fieldname' => 'post_modified_gmt',
       
    96 			'default'      => date( 'Y-m-d H:i:s' )
       
    97 		);
       
    98 
       
    99 		/** Topic Section *****************************************************/
       
   100 
       
   101 		// Topic id (Stored in postmeta)
       
   102 		$this->field_map[] = array(
       
   103 			'from_tablename' => 'thread',
       
   104 			'from_fieldname' => 'threadid',
       
   105 			'to_type'        => 'topic',
       
   106 			'to_fieldname'   => '_bbp_topic_id'
       
   107 		);
       
   108 
       
   109 		// Forum id (Stored in postmeta)
       
   110 		$this->field_map[] = array(
       
   111 			'from_tablename'  => 'thread',
       
   112 			'from_fieldname'  => 'forumid',
       
   113 			'to_type'         => 'topic',
       
   114 			'to_fieldname'    => '_bbp_forum_id',
       
   115 			'callback_method' => 'callback_forumid'
       
   116 		);
       
   117 
       
   118 		// Topic author.
       
   119 		$this->field_map[] = array(
       
   120 			'from_tablename'  => 'thread',
       
   121 			'from_fieldname'  => 'postuserid',
       
   122 			'to_type'         => 'topic',
       
   123 			'to_fieldname'    => 'post_author',
       
   124 			'callback_method' => 'callback_userid'
       
   125 		);
       
   126 
       
   127 		// Topic title.
       
   128 		$this->field_map[] = array(
       
   129 			'from_tablename' => 'thread',
       
   130 			'from_fieldname' => 'title',
       
   131 			'to_type'        => 'topic',
       
   132 			'to_fieldname'   => 'post_title'
       
   133 		);
       
   134 
       
   135 		// Topic slug (Clean name to avoid conflicts)
       
   136 		$this->field_map[] = array(
       
   137 			'from_tablename'  => 'thread',
       
   138 			'from_fieldname'  => 'title',
       
   139 			'to_type'         => 'topic',
       
   140 			'to_fieldname'    => 'post_name',
       
   141 			'callback_method' => 'callback_slug'
       
   142 		);
       
   143 
       
   144 		// Forum id (If no parent, than 0)
       
   145 		$this->field_map[] = array(
       
   146 			'from_tablename'  => 'thread',
       
   147 			'from_fieldname'  => 'forumid',
       
   148 			'to_type'         => 'topic',
       
   149 			'to_fieldname'    => 'post_parent',
       
   150 			'callback_method' => 'callback_forumid'
       
   151 		);
       
   152 
       
   153 		// Topic content.
       
   154 		// Note: We join the posts table because topics do not have content.
       
   155 		$this->field_map[] = array(
       
   156 			'from_tablename'  => 'post',
       
   157 			'from_fieldname'  => 'pagetext',
       
   158 			'join_tablename'  => 'thread',
       
   159 			'join_type'       => 'INNER',
       
   160 			'join_expression' => 'USING (threadid) WHERE post.parentid = 0',
       
   161 			'to_type'         => 'topic',
       
   162 			'to_fieldname'    => 'post_content',
       
   163 			'callback_method' => 'callback_html'
       
   164 		);
       
   165 
       
   166 		// Topic date update.
       
   167 		$this->field_map[] = array(
       
   168 			'from_tablename'  => 'thread',
       
   169 			'from_fieldname'  => 'dateline',
       
   170 			'to_type'         => 'topic',
       
   171 			'to_fieldname'    => 'post_date',
       
   172 			'callback_method' => 'callback_datetime'
       
   173 		);
       
   174 		$this->field_map[] = array(
       
   175 			'from_tablename'  => 'thread',
       
   176 			'from_fieldname'  => 'dateline',
       
   177 			'to_type'         => 'topic',
       
   178 			'to_fieldname'    => 'post_date_gmt',
       
   179 			'callback_method' => 'callback_datetime'
       
   180 		);
       
   181 		$this->field_map[] = array(
       
   182 			'from_tablename'  => 'thread',
       
   183 			'from_fieldname'  => 'dateline',
       
   184 			'to_type'         => 'topic',
       
   185 			'to_fieldname'    => 'post_modified',
       
   186 			'callback_method' => 'callback_datetime'
       
   187 		);
       
   188 		$this->field_map[] = array(
       
   189 			'from_tablename'  => 'thread',
       
   190 			'from_fieldname'  => 'dateline',
       
   191 			'to_type'         => 'topic',
       
   192 			'to_fieldname'    => 'post_modified_gmt',
       
   193 			'callback_method' => 'callback_datetime'
       
   194 		);
       
   195 
       
   196 		/** Tags Section ******************************************************/
       
   197 
       
   198 		// Topic id.
       
   199 		$this->field_map[] = array(
       
   200 			'from_tablename'  => 'tagcontent',
       
   201 			'from_fieldname'  => 'contentid',
       
   202 			'to_type'         => 'tags',
       
   203 			'to_fieldname'    => 'objectid',
       
   204 			'callback_method' => 'callback_topicid'
       
   205 		);
       
   206 
       
   207 		// Tags text.
       
   208 		$this->field_map[] = array(
       
   209 			'from_tablename'  => 'tag',
       
   210 			'from_fieldname'  => 'tagtext',
       
   211 			'join_tablename'  => 'tagcontent',
       
   212 			'join_type'       => 'INNER',
       
   213 			'join_expression' => 'USING (tagid)',
       
   214 			'to_type'         => 'tags',
       
   215 			'to_fieldname'    => 'name'
       
   216 		);
       
   217 
       
   218 		/** Post Section ******************************************************/
       
   219 
       
   220 		// Post id (Stores in postmeta)
       
   221 		$this->field_map[] = array(
       
   222 			'from_tablename'  => 'post',
       
   223 			'from_fieldname'  => 'postid',
       
   224 			'from_expression' => 'WHERE post.parentid != 0',
       
   225 			'to_type'         => 'reply',
       
   226 			'to_fieldname'    => '_bbp_post_id'
       
   227 		);
       
   228 
       
   229 		// Forum id (Stores in postmeta)
       
   230 		$this->field_map[] = array(
       
   231 			'from_tablename'  => 'post',
       
   232 			'from_fieldname'  => 'threadid',
       
   233 			'to_type'         => 'reply',
       
   234 			'to_fieldname'    => '_bbp_forum_id',
       
   235 			'callback_method' => 'callback_topicid_to_forumid'
       
   236 		);
       
   237 
       
   238 		// Topic id (Stores in postmeta)
       
   239 		$this->field_map[] = array(
       
   240 			'from_tablename'  => 'post',
       
   241 			'from_fieldname'  => 'threadid',
       
   242 			'to_type'         => 'reply',
       
   243 			'to_fieldname'    => '_bbp_topic_id',
       
   244 			'callback_method' => 'callback_topicid'
       
   245 		);
       
   246 
       
   247 		// Author ip.
       
   248 		$this->field_map[] = array(
       
   249 			'from_tablename' => 'post',
       
   250 			'from_fieldname' => 'ipaddress',
       
   251 			'to_type'        => 'reply',
       
   252 			'to_fieldname'   => '_bbp_author_ip'
       
   253 		);
       
   254 
       
   255 		// Post author.
       
   256 		$this->field_map[] = array(
       
   257 			'from_tablename'  => 'post',
       
   258 			'from_fieldname'  => 'userid',
       
   259 			'to_type'         => 'reply',
       
   260 			'to_fieldname'    => 'post_author',
       
   261 			'callback_method' => 'callback_userid'
       
   262 		);
       
   263 
       
   264 		// Topic title.
       
   265 		$this->field_map[] = array(
       
   266 			'from_tablename' => 'post',
       
   267 			'from_fieldname' => 'title',
       
   268 			'to_type'        => 'reply',
       
   269 			'to_fieldname'   => 'post_title'
       
   270 		);
       
   271 
       
   272 		// Topic slug (Clean name)
       
   273 		$this->field_map[] = array(
       
   274 			'from_tablename'  => 'post',
       
   275 			'from_fieldname'  => 'title',
       
   276 			'to_type'         => 'reply',
       
   277 			'to_fieldname'    => 'post_name',
       
   278 			'callback_method' => 'callback_slug'
       
   279 		);
       
   280 
       
   281 		// Post content.
       
   282 		$this->field_map[] = array(
       
   283 			'from_tablename'  => 'post',
       
   284 			'from_fieldname'  => 'pagetext',
       
   285 			'to_type'         => 'reply',
       
   286 			'to_fieldname'    => 'post_content',
       
   287 			'callback_method' => 'callback_html'
       
   288 		);
       
   289 
       
   290 		// Topic id (If no parent, than 0)
       
   291 		$this->field_map[] = array(
       
   292 			'from_tablename'  => 'post',
       
   293 			'from_fieldname'  => 'threadid',
       
   294 			'to_type'         => 'reply',
       
   295 			'to_fieldname'    => 'post_parent',
       
   296 			'callback_method' => 'callback_topicid'
       
   297 		);
       
   298 
       
   299 		// Topic date update.
       
   300 		$this->field_map[] = array(
       
   301 			'from_tablename'  => 'post',
       
   302 			'from_fieldname'  => 'dateline',
       
   303 			'to_type'         => 'reply',
       
   304 			'to_fieldname'    => 'post_date',
       
   305 			'callback_method' => 'callback_datetime'
       
   306 		);
       
   307 		$this->field_map[] = array(
       
   308 			'from_tablename'  => 'post',
       
   309 			'from_fieldname'  => 'dateline',
       
   310 			'to_type'         => 'reply',
       
   311 			'to_fieldname'    => 'post_date_gmt',
       
   312 			'callback_method' => 'callback_datetime'
       
   313 		);
       
   314 		$this->field_map[] = array(
       
   315 			'from_tablename'  => 'post',
       
   316 			'from_fieldname'  => 'dateline',
       
   317 			'to_type'         => 'reply',
       
   318 			'to_fieldname'    => 'post_modified',
       
   319 			'callback_method' => 'callback_datetime'
       
   320 		);
       
   321 		$this->field_map[]	 = array(
       
   322 			'from_tablename'  => 'post',
       
   323 			'from_fieldname'  => 'dateline',
       
   324 			'to_type'         => 'reply',
       
   325 			'to_fieldname'    => 'post_modified_gmt',
       
   326 			'callback_method' => 'callback_datetime'
       
   327 		);
       
   328 
       
   329 		/** User Section ******************************************************/
       
   330 
       
   331 		// Store old User id (Stores in usermeta)
       
   332 		$this->field_map[] = array(
       
   333 			'from_tablename' => 'user',
       
   334 			'from_fieldname' => 'userid',
       
   335 			'to_type'        => 'user',
       
   336 			'to_fieldname'   => '_bbp_user_id'
       
   337 		);
       
   338 
       
   339 		// Store old User password (Stores in usermeta serialized with salt)
       
   340 		$this->field_map[] = array(
       
   341 			'from_tablename'  => 'user',
       
   342 			'from_fieldname'  => 'password',
       
   343 			'to_type'         => 'user',
       
   344 			'to_fieldname'    => '_bbp_password',
       
   345 			'callback_method' => 'callback_savepass'
       
   346 		);
       
   347 
       
   348 		// Store old User Salt (This is only used for the SELECT row info for
       
   349 		// the above password save)
       
   350 		$this->field_map[] = array(
       
   351 			'from_tablename' => 'user',
       
   352 			'from_fieldname' => 'salt',
       
   353 			'to_type'        => 'user',
       
   354 			'to_fieldname'   => ''
       
   355 		);
       
   356 
       
   357 		// User password verify class (Stores in usermeta for verifying password)
       
   358 		$this->field_map[] = array(
       
   359 			'to_type'      => 'user',
       
   360 			'to_fieldname' => '_bbp_class',
       
   361 			'default'      => 'vBulletin'
       
   362 		);
       
   363 
       
   364 		// User name.
       
   365 		$this->field_map[] = array(
       
   366 			'from_tablename' => 'user',
       
   367 			'from_fieldname' => 'username',
       
   368 			'to_type'        => 'user',
       
   369 			'to_fieldname'   => 'user_login'
       
   370 		);
       
   371 
       
   372 		// User nice name.
       
   373 		$this->field_map[] = array(
       
   374 			'from_tablename' => 'user',
       
   375 			'from_fieldname' => 'user_nicename',
       
   376 			'to_type'        => 'user',
       
   377 			'to_fieldname'   => 'user_nicename'
       
   378 		);
       
   379 
       
   380 		// User email.
       
   381 		$this->field_map[] = array(
       
   382 			'from_tablename' => 'user',
       
   383 			'from_fieldname' => 'email',
       
   384 			'to_type'        => 'user',
       
   385 			'to_fieldname'   => 'user_email'
       
   386 		);
       
   387 
       
   388 		// User homepage.
       
   389 		$this->field_map[] = array(
       
   390 			'from_tablename' => 'user',
       
   391 			'from_fieldname' => 'homepage',
       
   392 			'to_type'        => 'user',
       
   393 			'to_fieldname'   => 'user_url'
       
   394 		);
       
   395 
       
   396 		// User registered.
       
   397 		$this->field_map[] = array(
       
   398 			'from_tablename'  => 'user',
       
   399 			'from_fieldname'  => 'joindate',
       
   400 			'to_type'         => 'user',
       
   401 			'to_fieldname'    => 'user_registered',
       
   402 			'callback_method' => 'callback_datetime'
       
   403 		);
       
   404 
       
   405 		// User aim.
       
   406 		$this->field_map[] = array(
       
   407 			'from_tablename' => 'user',
       
   408 			'from_fieldname' => 'aim',
       
   409 			'to_type'        => 'user',
       
   410 			'to_fieldname'   => 'aim'
       
   411 		);
       
   412 
       
   413 		// User yahoo.
       
   414 		$this->field_map[] = array(
       
   415 			'from_tablename' => 'user',
       
   416 			'from_fieldname' => 'yahoo',
       
   417 			'to_type'        => 'user',
       
   418 			'to_fieldname'   => 'yim'
       
   419 		);
       
   420 	}
       
   421 
       
   422 	/**
       
   423 	 * This method allows us to indicates what is or is not converted for each
       
   424 	 * converter.
       
   425 	 */
       
   426 	public function info() {
       
   427 		return '';
       
   428 	}
       
   429 
       
   430 	/**
       
   431 	 * This method is to save the salt and password together.  That
       
   432 	 * way when we authenticate it we can get it out of the database
       
   433 	 * as one value. Array values are auto sanitized by wordpress.
       
   434 	 */
       
   435 	public function callback_savepass( $field, $row ) {
       
   436 		$pass_array = array( 'hash'	 => $field, 'salt'	 => $row['salt'] );
       
   437 		return $pass_array;
       
   438 	}
       
   439 
       
   440 	/**
       
   441 	 * This method is to take the pass out of the database and compare
       
   442 	 * to a pass the user has typed in.
       
   443 	 */
       
   444 	public function authenticate_pass( $password, $serialized_pass ) {
       
   445 		$pass_array = unserialize( $serialized_pass );
       
   446 		return ( $pass_array['hash'] == md5( md5( $password ) . $pass_array['salt'] ) );
       
   447 	}
       
   448 }