PHPWind

Implementation of PHPWind Forum converter.

Defined (1)

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

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