web/wp-content/plugins/bbpress/includes/admin/converters/bbPress1.php
changeset 196 5e8dcbe22c24
equal deleted inserted replaced
195:c7c0fbc09788 196:5e8dcbe22c24
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * bbPress 1.1 Converter
       
     5  *
       
     6  * @since bbPress (rxxxx)
       
     7  */
       
     8 class bbPress1 extends BBP_Converter_Base {
       
     9 
       
    10 	/**
       
    11 	 * Main constructor
       
    12 	 *
       
    13 	 * @uses bbPress1::setup_globals()
       
    14 	 */
       
    15 	function __construct() {
       
    16 		parent::__construct();
       
    17 		$this->setup_globals();
       
    18 	}
       
    19 
       
    20 	/**
       
    21 	 * Sets up the field mappings
       
    22 	 */
       
    23 	public function setup_globals() {
       
    24 
       
    25 		/** Forum Section *****************************************************/
       
    26 
       
    27 		// Forum id (Stored in postmeta)
       
    28 		$this->field_map[] = array(
       
    29 			'from_tablename' => 'forums',
       
    30 			'from_fieldname' => 'forum_id',
       
    31 			'to_type'        => 'forum',
       
    32 			'to_fieldname'   => '_bbp_forum_id'
       
    33 		);
       
    34 
       
    35 		// Forum parent id (If no parent, 0. Stored in postmeta)
       
    36 		$this->field_map[] = array(
       
    37 			'from_tablename' => 'forums',
       
    38 			'from_fieldname' => 'forum_parent',
       
    39 			'to_type'        => 'forum',
       
    40 			'to_fieldname'   => '_bbp_forum_parent_id'
       
    41 		);
       
    42 
       
    43 		// Forum topic count (Stored in postmeta)
       
    44 		$this->field_map[] = array(
       
    45 			'from_tablename' => 'forums',
       
    46 			'from_fieldname' => 'topics',
       
    47 			'to_type'        => 'forum',
       
    48 			'to_fieldname'   => '_bbp_topic_count'
       
    49 		);
       
    50 
       
    51 		// Forum reply count (Stored in postmeta)
       
    52 		$this->field_map[] = array(
       
    53 			'from_tablename' => 'forums',
       
    54 			'from_fieldname' => 'posts',
       
    55 			'to_type'        => 'forum',
       
    56 			'to_fieldname'   => '_bbp_reply_count'
       
    57 		);
       
    58 
       
    59 		// Forum topic count (Stored in postmeta)
       
    60 		$this->field_map[] = array(
       
    61 			'from_tablename' => 'forums',
       
    62 			'from_fieldname' => 'topics',
       
    63 			'to_type'        => 'forum',
       
    64 			'to_fieldname'   => '_bbp_total_topic_count'
       
    65 		);
       
    66 
       
    67 		// Forum reply count (Stored in postmeta)
       
    68 		$this->field_map[] = array(
       
    69 			'from_tablename' => 'forums',
       
    70 			'from_fieldname' => 'posts',
       
    71 			'to_type'        => 'forum',
       
    72 			'to_fieldname'   => '_bbp_total_reply_count'
       
    73 		);
       
    74 
       
    75 		// Forum title.
       
    76 		$this->field_map[] = array(
       
    77 			'from_tablename' => 'forums',
       
    78 			'from_fieldname' => 'forum_name',
       
    79 			'to_type'        => 'forum',
       
    80 			'to_fieldname'   => 'post_title'
       
    81 		);
       
    82 
       
    83 		// Forum slug (Clean name to avoid confilcts)
       
    84 		$this->field_map[] = array(
       
    85 			'from_tablename'   => 'forums',
       
    86 			'from_fieldname'   => 'forum_slug',
       
    87 			'to_type'          => 'forum',
       
    88 			'to_fieldname'     => 'post_name',
       
    89 			'callback_method'  => 'callback_slug'
       
    90 		);
       
    91 
       
    92 		// Forum description.
       
    93 		$this->field_map[] = array(
       
    94 			'from_tablename'   => 'forums',
       
    95 			'from_fieldname'   => 'forum_desc',
       
    96 			'to_type'          => 'forum',
       
    97 			'to_fieldname'     => 'post_content',
       
    98 			'callback_method'  => 'callback_null'
       
    99 		);
       
   100 
       
   101 		// Forum display order (Starts from 1)
       
   102 		$this->field_map[] = array(
       
   103 			'from_tablename' => 'forums',
       
   104 			'from_fieldname' => 'forum_order',
       
   105 			'to_type'        => 'forum',
       
   106 			'to_fieldname'   => 'menu_order'
       
   107 		);
       
   108 
       
   109 		// Forum dates.
       
   110 		$this->field_map[] = array(
       
   111 			'to_type'      => 'forum',
       
   112 			'to_fieldname' => 'post_date',
       
   113 			'default'      => date('Y-m-d H:i:s')
       
   114 		);
       
   115 		$this->field_map[] = array(
       
   116 			'to_type'      => 'forum',
       
   117 			'to_fieldname' => 'post_date_gmt',
       
   118 			'default'      => date('Y-m-d H:i:s')
       
   119 		);
       
   120 		$this->field_map[] = array(
       
   121 			'to_type'      => 'forum',
       
   122 			'to_fieldname' => 'post_modified',
       
   123 			'default'      => date('Y-m-d H:i:s')
       
   124 		);
       
   125 		$this->field_map[] = array(
       
   126 			'to_type'      => 'forum',
       
   127 			'to_fieldname' => 'post_modified_gmt',
       
   128 			'default'      => date('Y-m-d H:i:s')
       
   129 		);
       
   130 
       
   131 		/** Topic Section *****************************************************/
       
   132 
       
   133 		// Topic id (Stored in postmeta)
       
   134 		$this->field_map[] = array(
       
   135 			'from_tablename' => 'topics',
       
   136 			'from_fieldname' => 'topic_id',
       
   137 			'to_type'        => 'topic',
       
   138 			'to_fieldname'   => '_bbp_topic_id'
       
   139 		);
       
   140 
       
   141 		// Reply count (Stored in postmeta)
       
   142 		$this->field_map[] = array(
       
   143 			'from_tablename'  => 'topics',
       
   144 			'from_fieldname'  => 'topic_posts',
       
   145 			'to_type'         => 'topic',
       
   146 			'to_fieldname'    => '_bbp_reply_count',
       
   147 			'callback_method' => 'callback_topic_reply_count'
       
   148 		);
       
   149 
       
   150 		// Forum id (Stored in postmeta)
       
   151 		$this->field_map[] = array(
       
   152 			'from_tablename'  => 'topics',
       
   153 			'from_fieldname'  => 'forum_id',
       
   154 			'to_type'         => 'topic',
       
   155 			'to_fieldname'    => '_bbp_forum_id',
       
   156 			'callback_method' => 'callback_forumid'
       
   157 		);
       
   158 
       
   159 		// Topic author.
       
   160 		$this->field_map[] = array(
       
   161 			'from_tablename'  => 'topics',
       
   162 			'from_fieldname'  => 'topic_poster',
       
   163 			'to_type'         => 'topic',
       
   164 			'to_fieldname'    => 'post_author',
       
   165 			'callback_method' => 'callback_userid'
       
   166 		);
       
   167 
       
   168 		// Topic title.
       
   169 		$this->field_map[] = array(
       
   170 			'from_tablename' => 'topics',
       
   171 			'from_fieldname' => 'topic_title',
       
   172 			'to_type'        => 'topic',
       
   173 			'to_fieldname'   => 'post_title'
       
   174 		);
       
   175 
       
   176 		// Topic slug (Clean name to avoid conflicts)
       
   177 		$this->field_map[] = array(
       
   178 			'from_tablename'  => 'topics',
       
   179 			'from_fieldname'  => 'topic_title',
       
   180 			'to_type'         => 'topic',
       
   181 			'to_fieldname'    => 'post_name',
       
   182 			'callback_method' => 'callback_slug'
       
   183 		);
       
   184 
       
   185 		// Topic content.
       
   186 		// Note: We join the posts table because topics do not have content.
       
   187 		$this->field_map[] = array(
       
   188 			'from_tablename'  => 'posts',
       
   189 			'from_fieldname'  => 'post_text',
       
   190 			'join_tablename'  => 'topics',
       
   191 			'join_type'       => 'INNER',
       
   192 			'join_expression' => 'USING (topic_id) WHERE posts.post_position IN (0,1)',
       
   193 			'to_type'         => 'topic',
       
   194 			'to_fieldname'    => 'post_content',
       
   195 			'callback_method' => 'callback_html'
       
   196 		);
       
   197 
       
   198 		// Topic status.
       
   199 		// Note: post_status is more accurate than topic_status
       
   200 		$this->field_map[] = array(
       
   201 			'from_tablename'  => 'posts',
       
   202 			'from_fieldname'  => 'post_status',
       
   203 			'join_tablename'  => 'topics',
       
   204 			'join_type'       => 'INNER',
       
   205 			'join_expression' => 'USING (topic_id) WHERE posts.post_position IN (0,1)',
       
   206 			'to_type'         => 'topic',
       
   207 			'to_fieldname'    => 'post_status',
       
   208 			'callback_method' => 'callback_status'
       
   209 		);
       
   210 
       
   211 		// Author ip.
       
   212 		$this->field_map[] = array(
       
   213 			'from_tablename'  => 'posts',
       
   214 			'from_fieldname'  => 'poster_ip',
       
   215 			'join_tablename'  => 'topics',
       
   216 			'join_type'       => 'INNER',
       
   217 			'join_expression' => 'USING (topic_id) WHERE posts.post_position IN (0,1)',
       
   218 			'to_type'         => 'topic',
       
   219 			'to_fieldname'    => '_bbp_author_ip'
       
   220 		);
       
   221 
       
   222 		// Forum id (If no parent, 0)
       
   223 		$this->field_map[] = array(
       
   224 			'from_tablename'  => 'topics',
       
   225 			'from_fieldname'  => 'forum_id',
       
   226 			'to_type'         => 'topic',
       
   227 			'to_fieldname'    => 'post_parent',
       
   228 			'callback_method' => 'callback_forumid'
       
   229 		);
       
   230 
       
   231 		// Topic dates.
       
   232 		$this->field_map[] = array(
       
   233 			'from_tablename' => 'topics',
       
   234 			'from_fieldname' => 'topic_start_time',
       
   235 			'to_type'        => 'topic',
       
   236 			'to_fieldname'   => 'post_date'
       
   237 		);
       
   238 		$this->field_map[] = array(
       
   239 			'from_tablename' => 'topics',
       
   240 			'from_fieldname' => 'topic_start_time',
       
   241 			'to_type'        => 'topic',
       
   242 			'to_fieldname'   => 'post_date_gmt'
       
   243 		);
       
   244 		$this->field_map[] = array(
       
   245 			'from_tablename' => 'topics',
       
   246 			'from_fieldname' => 'topic_time',
       
   247 			'to_type'        => 'topic',
       
   248 			'to_fieldname'   => 'post_modified'
       
   249 		);
       
   250 		$this->field_map[] = array(
       
   251 			'from_tablename' => 'topics',
       
   252 			'from_fieldname' => 'topic_time',
       
   253 			'to_type'        => 'topic',
       
   254 			'to_fieldname'   => 'post_modified_gmt'
       
   255 		);
       
   256 		$this->field_map[] = array(
       
   257 			'from_tablename' => 'topics',
       
   258 			'from_fieldname' => 'topic_time',
       
   259 			'to_type'        => 'topic',
       
   260 			'to_fieldname'   => '_bbp_last_active_time'
       
   261 		);
       
   262 
       
   263 		/** Tags Section ******************************************************/
       
   264 
       
   265 		// Topic id.
       
   266 		$this->field_map[] = array(
       
   267 			'from_tablename'  => 'term_relationships',
       
   268 			'from_fieldname'  => 'object_id',
       
   269 			'to_type'         => 'tags',
       
   270 			'to_fieldname'    => 'objectid',
       
   271 			'callback_method' => 'callback_topicid'
       
   272 		);
       
   273 
       
   274 		// Taxonomy ID.
       
   275 		$this->field_map[] = array(
       
   276 			'from_tablename'  => 'term_taxonomy',
       
   277 			'from_fieldname'  => 'term_taxonomy_id',
       
   278 			'join_tablename'  => 'term_relationships',
       
   279 			'join_type'       => 'INNER',
       
   280 			'join_expression' => 'USING (term_taxonomy_id)',
       
   281 			'to_type'         => 'tags',
       
   282 			'to_fieldname'    => 'taxonomy'
       
   283 		);
       
   284 
       
   285 		// Term text.
       
   286 		$this->field_map[] = array(
       
   287 			'from_tablename'  => 'terms',
       
   288 			'from_fieldname'  => 'name',
       
   289 			'join_tablename'  => 'term_taxonomy',
       
   290 			'join_type'       => 'INNER',
       
   291 			'join_expression' => 'USING (term_id)',
       
   292 			'to_type'         => 'tags',
       
   293 			'to_fieldname'    => 'name'
       
   294 		);
       
   295 
       
   296 		/** Reply Section *****************************************************/
       
   297 
       
   298 		// Post id. Stores in postmeta.
       
   299 		$this->field_map[] = array(
       
   300 			'from_tablename'  => 'posts',
       
   301 			'from_fieldname'  => 'post_id',
       
   302 			'to_type'         => 'reply',
       
   303 			'to_fieldname'    => '_bbp_post_id'
       
   304 		);
       
   305 
       
   306 		// Topic id (Stores in postmeta)
       
   307 		$this->field_map[] = array(
       
   308 			'from_tablename'  => 'posts',
       
   309 			'from_fieldname'  => 'topic_id',
       
   310 			'to_type'         => 'reply',
       
   311 			'to_fieldname'    => '_bbp_topic_id',
       
   312 			'callback_method' => 'callback_topicid'
       
   313 		);
       
   314 
       
   315 		// Forum id (Stored in postmeta)
       
   316 		$this->field_map[] = array(
       
   317 			'from_tablename'  => 'posts',
       
   318 			'from_fieldname'  => 'forum_id',
       
   319 			'to_type'         => 'reply',
       
   320 			'to_fieldname'    => '_bbp_forum_id',
       
   321 			'callback_method' => 'callback_forumid'
       
   322 		);
       
   323 
       
   324 		// Topic title (for reply title).
       
   325 		$this->field_map[] = array(
       
   326 			'from_tablename'  => 'topics',
       
   327 			'from_fieldname'  => 'topic_title',
       
   328 			'join_tablename'  => 'posts',
       
   329 			'join_type'       => 'INNER',
       
   330 			'join_expression' => 'USING (topic_id) WHERE posts.post_position NOT IN (0,1)',
       
   331 			'to_type'         => 'reply',
       
   332 			'to_fieldname'    => 'post_title',
       
   333 			'callback_method' => 'callback_reply_title'
       
   334 		);
       
   335 
       
   336 		// Author ip.
       
   337 		$this->field_map[] = array(
       
   338 			'from_tablename' => 'posts',
       
   339 			'from_fieldname' => 'poster_ip',
       
   340 			'to_type'        => 'reply',
       
   341 			'to_fieldname'   => '_bbp_author_ip'
       
   342 		);
       
   343 
       
   344 		// Reply author.
       
   345 		$this->field_map[] = array(
       
   346 			'from_tablename'  => 'posts',
       
   347 			'from_fieldname'  => 'poster_id',
       
   348 			'to_type'         => 'reply',
       
   349 			'to_fieldname'    => 'post_author',
       
   350 			'callback_method' => 'callback_userid'
       
   351 		);
       
   352 
       
   353 		// Reply status
       
   354 		$this->field_map[] = array(
       
   355 			'from_tablename'  => 'posts',
       
   356 			'from_fieldname'  => 'post_status',
       
   357 			'to_type'         => 'reply',
       
   358 			'to_fieldname'    => 'post_status',
       
   359 			'callback_method' => 'callback_status'
       
   360 		);
       
   361 
       
   362 		// Reply content.
       
   363 		$this->field_map[] = array(
       
   364 			'from_tablename'  => 'posts',
       
   365 			'from_fieldname'  => 'post_text',
       
   366 			'to_type'         => 'reply',
       
   367 			'to_fieldname'    => 'post_content',
       
   368 			'callback_method' => 'callback_html'
       
   369 		);
       
   370 
       
   371 		// Reply order.
       
   372 		$this->field_map[] = array(
       
   373 			'from_tablename'  => 'posts',
       
   374 			'from_fieldname'  => 'post_position',
       
   375 			'to_type'         => 'reply',
       
   376 			'to_fieldname'    => 'menu_order'
       
   377 		);
       
   378 
       
   379 		// Topic id.  If no parent, than 0.
       
   380 		$this->field_map[] = array(
       
   381 			'from_tablename'  => 'posts',
       
   382 			'from_fieldname'  => 'topic_id',
       
   383 			'to_type'         => 'reply',
       
   384 			'to_fieldname'    => 'post_parent',
       
   385 			'callback_method' => 'callback_topicid'
       
   386 		);
       
   387 
       
   388 		// Reply dates.
       
   389 		$this->field_map[] = array(
       
   390 			'from_tablename' => 'posts',
       
   391 			'from_fieldname' => 'post_time',
       
   392 			'to_type'        => 'reply',
       
   393 			'to_fieldname'   => 'post_date'
       
   394 		);
       
   395 		$this->field_map[] = array(
       
   396 			'from_tablename' => 'posts',
       
   397 			'from_fieldname' => 'post_time',
       
   398 			'to_type'        => 'reply',
       
   399 			'to_fieldname'   => 'post_date_gmt'
       
   400 		);
       
   401 		$this->field_map[] = array(
       
   402 			'from_tablename' => 'posts',
       
   403 			'from_fieldname' => 'post_time',
       
   404 			'to_type'        => 'reply',
       
   405 			'to_fieldname'   => 'post_modified'
       
   406 		);
       
   407 		$this->field_map[] = array(
       
   408 			'from_tablename' => 'posts',
       
   409 			'from_fieldname' => 'post_time',
       
   410 			'to_type'        => 'reply',
       
   411 			'to_fieldname'   => 'post_modified_gmt'
       
   412 		);
       
   413 
       
   414 		/** User Section ******************************************************/
       
   415 
       
   416 		// Store old User id. Stores in usermeta.
       
   417 		$this->field_map[] = array(
       
   418 			'from_tablename' => 'users',
       
   419 			'from_fieldname' => 'ID',
       
   420 			'to_type'        => 'user',
       
   421 			'to_fieldname'   => '_bbp_user_id'
       
   422 		);
       
   423 
       
   424 		// Store old User password. Stores in usermeta.
       
   425 		$this->field_map[] = array(
       
   426 			'from_tablename' => 'users',
       
   427 			'from_fieldname' => 'user_pass',
       
   428 			'to_type'        => 'user',
       
   429 			'to_fieldname'   => '_bbp_password'
       
   430 		);
       
   431 
       
   432 		// User name.
       
   433 		$this->field_map[] = array(
       
   434 			'from_tablename' => 'users',
       
   435 			'from_fieldname' => 'user_login',
       
   436 			'to_type'        => 'user',
       
   437 			'to_fieldname'   => 'user_login'
       
   438 		);
       
   439 
       
   440 		// User nice name.
       
   441 		$this->field_map[] = array(
       
   442 			'from_tablename' => 'users',
       
   443 			'from_fieldname' => 'user_nicename',
       
   444 			'to_type'        => 'user',
       
   445 			'to_fieldname'   => 'user_nicename'
       
   446 		);
       
   447 
       
   448 		// User email.
       
   449 		$this->field_map[] = array(
       
   450 			'from_tablename' => 'users',
       
   451 			'from_fieldname' => 'user_email',
       
   452 			'to_type'        => 'user',
       
   453 			'to_fieldname'   => 'user_email'
       
   454 		);
       
   455 
       
   456 		// User homepage.
       
   457 		$this->field_map[] = array(
       
   458 			'from_tablename' => 'users',
       
   459 			'from_fieldname' => 'user_url',
       
   460 			'to_type'        => 'user',
       
   461 			'to_fieldname'   => 'user_url'
       
   462 		);
       
   463 
       
   464 		// User registered.
       
   465 		$this->field_map[] = array(
       
   466 			'from_tablename' => 'users',
       
   467 			'from_fieldname' => 'user_registered',
       
   468 			'to_type'        => 'user',
       
   469 			'to_fieldname'   => 'user_registered'
       
   470 		);
       
   471 
       
   472 		// User status.
       
   473 		$this->field_map[] = array(
       
   474 			'from_tablename' => 'users',
       
   475 			'from_fieldname' => 'user_status',
       
   476 			'to_type'        => 'user',
       
   477 			'to_fieldname'   => 'user_status'
       
   478 		);
       
   479 
       
   480 		// User status.
       
   481 		$this->field_map[] = array(
       
   482 			'from_tablename' => 'users',
       
   483 			'from_fieldname' => 'display_name',
       
   484 			'to_type'        => 'user',
       
   485 			'to_fieldname'   => 'display_name'
       
   486 		);
       
   487 	}
       
   488 
       
   489 	/**
       
   490 	 * This method allows us to indicates what is or is not converted for each
       
   491 	 * converter.
       
   492 	 */
       
   493 	public function info() {
       
   494 		return '';
       
   495 	}
       
   496 
       
   497 	/**
       
   498 	 * Translate the post status from bbPress 1's numeric's to WordPress's
       
   499 	 * strings.
       
   500 	 *
       
   501 	 * @param int $status bbPress 1.x numeric status
       
   502 	 * @return string WordPress safe
       
   503 	 */
       
   504 	public function callback_status( $status = 0 ) {
       
   505 		switch ( $status ) {
       
   506 			case 2 :
       
   507 				$status = 'spam';    // bbp_get_spam_status_id()
       
   508 				break;
       
   509 
       
   510 			case 1 :
       
   511 				$status = 'trash';   // bbp_get_trash_status_id()
       
   512 				break;
       
   513 
       
   514 			case 0  :
       
   515 			default :
       
   516 				$status = 'publish'; // bbp_get_public_status_id()
       
   517 				break;
       
   518 		}
       
   519 		return $status;
       
   520 	}
       
   521 
       
   522 	/**
       
   523 	 * Verify the topic reply count.
       
   524 	 *
       
   525 	 * @param int $count bbPress 1.x reply count
       
   526 	 * @return string WordPress safe
       
   527 	 */
       
   528 	public function callback_topic_reply_count( $count = 1 ) {
       
   529 		$count = absint( (int) $count - 1 );
       
   530 		return $count;
       
   531 	}
       
   532 
       
   533 	/**
       
   534 	 * Set the reply title
       
   535 	 *
       
   536 	 * @param string $title bbPress 1.x topic title of this reply
       
   537 	 * @return string Prefixed topic title, or empty string
       
   538 	 */
       
   539 	public function callback_reply_title( $title = '' ) {
       
   540 		$title = !empty( $title ) ? __( 'Re: ', 'bbpress' ) . html_entity_decode( $title ) : '';
       
   541 		return $title;
       
   542 	}
       
   543 
       
   544 	/**
       
   545 	 * This method is to save the salt and password together. That
       
   546 	 * way when we authenticate it we can get it out of the database
       
   547 	 * as one value. Array values are auto sanitized by wordpress.
       
   548 	 */
       
   549 	public function callback_savepass( $field, $row ) {
       
   550 		return false;
       
   551 	}
       
   552 
       
   553 	/**
       
   554 	 * This method is to take the pass out of the database and compare
       
   555 	 * to a pass the user has typed in.
       
   556 	 */
       
   557 	public function authenticate_pass( $password, $serialized_pass ) {
       
   558 		return false;
       
   559 	}
       
   560 }