MyBB

Implementation of MyBB Forum converter.

Defined (1)

The class is defined in the following location(s).

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