Phorum

Implementation of Phorum Forum converter.

Defined (1)

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

/includes/admin/converters/Phorum.php  
  1. class Phorum extends BBP_Converter_Base { 
  2.  
  3. /** 
  4. * Main Constructor 
  5. * @uses Phorum::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' => 'forum_id',  
  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' => 'parent_id',  
  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' => 'thread_count',  
  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' => 'message_count',  
  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' => 'display_order',  
  80. 'to_type' => 'forum',  
  81. 'to_fieldname' => 'menu_order' 
  82. ); 
  83.  
  84. // Forum type (Category = 1 or Forum = 0, Stored in postmeta) 
  85. $this->field_map[] = array( 
  86. 'from_tablename' => 'forums',  
  87. 'from_fieldname' => 'folder_flag',  
  88. 'to_type' => 'forum',  
  89. 'to_fieldname' => '_bbp_forum_type',  
  90. 'callback_method' => 'callback_forum_type' 
  91. ); 
  92.  
  93. // Forum dates. 
  94. $this->field_map[] = array( 
  95. 'to_type' => 'forum',  
  96. 'to_fieldname' => 'post_date',  
  97. 'default' => date('Y-m-d H:i:s') 
  98. ); 
  99. $this->field_map[] = array( 
  100. 'to_type' => 'forum',  
  101. 'to_fieldname' => 'post_date_gmt',  
  102. 'default' => date('Y-m-d H:i:s') 
  103. ); 
  104. $this->field_map[] = array( 
  105. 'to_type' => 'forum',  
  106. 'to_fieldname' => 'post_modified',  
  107. 'default' => date('Y-m-d H:i:s') 
  108. ); 
  109. $this->field_map[] = array( 
  110. 'to_type' => 'forum',  
  111. 'to_fieldname' => 'post_modified_gmt',  
  112. 'default' => date('Y-m-d H:i:s') 
  113. ); 
  114.  
  115. /** Topic Section *****************************************************/ 
  116.  
  117. // Topic id (Stored in postmeta) 
  118. $this->field_map[] = array( 
  119. 'from_tablename' => 'messages',  
  120. 'from_fieldname' => 'thread',  
  121. 'from_expression' => 'WHERE parent_id = 0',  
  122. 'to_type' => 'topic',  
  123. 'to_fieldname' => '_bbp_topic_id' 
  124. ); 
  125.  
  126. // Topic reply count (Stored in postmeta) 
  127. $this->field_map[] = array( 
  128. 'from_tablename' => 'messages',  
  129. 'from_fieldname' => 'thread_count',  
  130. 'to_type' => 'topic',  
  131. 'to_fieldname' => '_bbp_reply_count',  
  132. 'callback_method' => 'callback_topic_reply_count' 
  133. ); 
  134.  
  135. // Topic total reply count (Includes unpublished replies, Stored in postmeta) 
  136. $this->field_map[] = array( 
  137. 'from_tablename' => 'messages',  
  138. 'from_fieldname' => 'thread_count',  
  139. 'to_type' => 'topic',  
  140. 'to_fieldname' => '_bbp_total_reply_count',  
  141. 'callback_method' => 'callback_topic_reply_count' 
  142. ); 
  143.  
  144. // Topic parent forum id (If no parent, then 0, Stored in postmeta) 
  145. $this->field_map[] = array( 
  146. 'from_tablename' => 'messages',  
  147. 'from_fieldname' => 'forum_id',  
  148. 'to_type' => 'topic',  
  149. 'to_fieldname' => '_bbp_forum_id',  
  150. 'callback_method' => 'callback_forumid' 
  151. ); 
  152.  
  153. // Topic author. 
  154. $this->field_map[] = array( 
  155. 'from_tablename' => 'messages',  
  156. 'from_fieldname' => 'user_id',  
  157. 'to_type' => 'topic',  
  158. 'to_fieldname' => 'post_author',  
  159. 'callback_method' => 'callback_userid' 
  160. ); 
  161.  
  162. // Topic Author ip (Stored in postmeta) 
  163. $this->field_map[] = array( 
  164. 'from_tablename' => 'messages',  
  165. 'from_fieldname' => 'ip',  
  166. 'to_type' => 'topic',  
  167. 'to_fieldname' => '_bbp_author_ip' 
  168. ); 
  169.  
  170. // Topic content. 
  171. $this->field_map[] = array( 
  172. 'from_tablename' => 'messages',  
  173. 'from_fieldname' => 'body',  
  174. 'to_type' => 'topic',  
  175. 'to_fieldname' => 'post_content',  
  176. 'callback_method' => 'callback_html' 
  177. ); 
  178.  
  179. // Topic title. 
  180. $this->field_map[] = array( 
  181. 'from_tablename' => 'messages',  
  182. 'from_fieldname' => 'subject',  
  183. 'to_type' => 'topic',  
  184. 'to_fieldname' => 'post_title' 
  185. ); 
  186.  
  187. // Topic slug (Clean name to avoid conflicts) 
  188. $this->field_map[] = array( 
  189. 'from_tablename' => 'messages',  
  190. 'from_fieldname' => 'subject',  
  191. 'to_type' => 'topic',  
  192. 'to_fieldname' => 'post_name',  
  193. 'callback_method' => 'callback_slug' 
  194. ); 
  195.  
  196. // Topic parent forum id (If no parent, then 0) 
  197. $this->field_map[] = array( 
  198. 'from_tablename' => 'messages',  
  199. 'from_fieldname' => 'forum_id',  
  200. 'to_type' => 'topic',  
  201. 'to_fieldname' => 'post_parent',  
  202. 'callback_method' => 'callback_forumid' 
  203. ); 
  204.  
  205. // Topic dates. 
  206. $this->field_map[] = array( 
  207. 'from_tablename' => 'messages',  
  208. 'from_fieldname' => 'datestamp',  
  209. 'to_type' => 'topic',  
  210. 'to_fieldname' => 'post_date',  
  211. 'callback_method' => 'callback_datetime' 
  212. ); 
  213. $this->field_map[] = array( 
  214. 'from_tablename' => 'messages',  
  215. 'from_fieldname' => 'datestamp',  
  216. 'to_type' => 'topic',  
  217. 'to_fieldname' => 'post_date_gmt',  
  218. 'callback_method' => 'callback_datetime' 
  219. ); 
  220. $this->field_map[] = array( 
  221. 'from_tablename' => 'messages',  
  222. 'from_fieldname' => 'datestamp',  
  223. 'to_type' => 'topic',  
  224. 'to_fieldname' => 'post_modified',  
  225. 'callback_method' => 'callback_datetime' 
  226. ); 
  227. $this->field_map[] = array( 
  228. 'from_tablename' => 'messages',  
  229. 'from_fieldname' => 'datestamp',  
  230. 'to_type' => 'topic',  
  231. 'to_fieldname' => 'post_modified_gmt',  
  232. 'callback_method' => 'callback_datetime' 
  233. ); 
  234. $this->field_map[] = array( 
  235. 'from_tablename' => 'messages',  
  236. 'from_fieldname' => 'datestamp',  
  237. 'to_type' => 'topic',  
  238. 'to_fieldname' => '_bbp_last_active_time',  
  239. 'callback_method' => 'callback_datetime' 
  240. ); 
  241.  
  242. // Topic status (Open = 0 or Closed = 1) 
  243. $this->field_map[] = array( 
  244. 'from_tablename' => 'messages',  
  245. 'from_fieldname' => 'closed',  
  246. 'to_type' => 'topic',  
  247. 'to_fieldname' => 'post_status',  
  248. 'callback_method' => 'callback_topic_status' 
  249. ); 
  250.  
  251. /** Tags Section ******************************************************/ 
  252.  
  253. /** 
  254. * Phorum v5.2.19 Forums do not support topic tags out of the box 
  255. */ 
  256.  
  257. /** Reply Section *****************************************************/ 
  258.  
  259. // Reply id (Stored in postmeta) 
  260. $this->field_map[] = array( 
  261. 'from_tablename' => 'messages',  
  262. 'from_fieldname' => 'message_id',  
  263. 'from_expression' => 'WHERE parent_id != 0',  
  264. 'to_type' => 'reply',  
  265. 'to_fieldname' => '_bbp_post_id' 
  266. ); 
  267.  
  268. // Reply parent forum id (If no parent, then 0. Stored in postmeta) 
  269. $this->field_map[] = array( 
  270. 'from_tablename' => 'messages',  
  271. 'from_fieldname' => 'forum_id',  
  272. 'to_type' => 'reply',  
  273. 'to_fieldname' => '_bbp_forum_id',  
  274. 'callback_method' => 'callback_topicid_to_forumid' 
  275. ); 
  276.  
  277. // Reply parent topic id (If no parent, then 0. Stored in postmeta) 
  278. $this->field_map[] = array( 
  279. 'from_tablename' => 'messages',  
  280. 'from_fieldname' => 'thread',  
  281. 'to_type' => 'reply',  
  282. 'to_fieldname' => '_bbp_topic_id',  
  283. 'callback_method' => 'callback_topicid' 
  284. ); 
  285.  
  286. // Reply author ip (Stored in postmeta) 
  287. $this->field_map[] = array( 
  288. 'from_tablename' => 'messages',  
  289. 'from_fieldname' => 'ip',  
  290. 'to_type' => 'reply',  
  291. 'to_fieldname' => '_bbp_author_ip' 
  292. ); 
  293.  
  294. // Reply author. 
  295. $this->field_map[] = array( 
  296. 'from_tablename' => 'messages',  
  297. 'from_fieldname' => 'user_id',  
  298. 'to_type' => 'reply',  
  299. 'to_fieldname' => 'post_author',  
  300. 'callback_method' => 'callback_userid' 
  301. ); 
  302.  
  303. // Reply title. 
  304. $this->field_map[] = array( 
  305. 'from_tablename' => 'messages',  
  306. 'from_fieldname' => 'subject',  
  307. 'to_type' => 'reply',  
  308. 'to_fieldname' => 'post_title' 
  309. ); 
  310.  
  311. // Reply slug (Clean name to avoid conflicts) 
  312. $this->field_map[] = array( 
  313. 'from_tablename' => 'messages',  
  314. 'from_fieldname' => 'subject',  
  315. 'to_type' => 'reply',  
  316. 'to_fieldname' => 'post_name',  
  317. 'callback_method' => 'callback_slug' 
  318. ); 
  319.  
  320. // Reply content. 
  321. $this->field_map[] = array( 
  322. 'from_tablename' => 'messages',  
  323. 'from_fieldname' => 'body',  
  324. 'to_type' => 'reply',  
  325. 'to_fieldname' => 'post_content',  
  326. 'callback_method' => 'callback_html' 
  327. ); 
  328.  
  329. // Reply parent topic id (If no parent, then 0) 
  330. $this->field_map[] = array( 
  331. 'from_tablename' => 'messages',  
  332. 'from_fieldname' => 'thread',  
  333. 'to_type' => 'reply',  
  334. 'to_fieldname' => 'post_parent',  
  335. 'callback_method' => 'callback_topicid' 
  336. ); 
  337.  
  338. // Reply dates. 
  339. $this->field_map[] = array( 
  340. 'from_tablename' => 'messages',  
  341. 'from_fieldname' => 'datestamp',  
  342. 'to_type' => 'reply',  
  343. 'to_fieldname' => 'post_date',  
  344. 'callback_method' => 'callback_datetime' 
  345. ); 
  346. $this->field_map[] = array( 
  347. 'from_tablename' => 'messages',  
  348. 'from_fieldname' => 'datestamp',  
  349. 'to_type' => 'reply',  
  350. 'to_fieldname' => 'post_date_gmt',  
  351. 'callback_method' => 'callback_datetime' 
  352. ); 
  353. $this->field_map[] = array( 
  354. 'from_tablename' => 'messages',  
  355. 'from_fieldname' => 'datestamp',  
  356. 'to_type' => 'reply',  
  357. 'to_fieldname' => 'post_modified',  
  358. 'callback_method' => 'callback_datetime' 
  359. ); 
  360. $this->field_map[] = array( 
  361. 'from_tablename' => 'messages',  
  362. 'from_fieldname' => 'datestamp',  
  363. 'to_type' => 'reply',  
  364. 'to_fieldname' => 'post_modified_gmt',  
  365. 'callback_method' => 'callback_datetime' 
  366. ); 
  367.  
  368. /** User Section ******************************************************/ 
  369.  
  370. // Store old User id (Stored in usermeta) 
  371. $this->field_map[] = array( 
  372. 'from_tablename' => 'users',  
  373. 'from_fieldname' => 'user_id',  
  374. 'to_type' => 'user',  
  375. 'to_fieldname' => '_bbp_user_id' 
  376. ); 
  377.  
  378. // Store old User password (Stored in usermeta serialized with salt) 
  379. $this->field_map[] = array( 
  380. 'from_tablename' => 'users',  
  381. 'from_fieldname' => 'password',  
  382. 'to_type' => 'user',  
  383. 'to_fieldname' => '_bbp_password',  
  384. 'callback_method' => 'callback_savepass' 
  385. ); 
  386.  
  387. // Store old User Salt (This is only used for the SELECT row info for the above password save) 
  388. // $this->field_map[] = array( 
  389. // 'from_tablename' => 'users',  
  390. // 'from_fieldname' => 'salt',  
  391. // 'to_type' => 'user',  
  392. // 'to_fieldname' => '' 
  393. // ); 
  394.  
  395. // User password verify class (Stored in usermeta for verifying password) 
  396. $this->field_map[] = array( 
  397. 'to_type' => 'users',  
  398. 'to_fieldname' => '_bbp_class',  
  399. 'default' => 'Phorum' 
  400. ); 
  401.  
  402. // User name. 
  403. $this->field_map[] = array( 
  404. 'from_tablename' => 'users',  
  405. 'from_fieldname' => 'username',  
  406. 'to_type' => 'user',  
  407. 'to_fieldname' => 'user_login' 
  408. ); 
  409.  
  410. // User nice name. 
  411. $this->field_map[] = array( 
  412. 'from_tablename' => 'users',  
  413. 'from_fieldname' => 'display_name',  
  414. 'to_type' => 'user',  
  415. 'to_fieldname' => 'user_nicename' 
  416. ); 
  417.  
  418. // User email. 
  419. $this->field_map[] = array( 
  420. 'from_tablename' => 'users',  
  421. 'from_fieldname' => 'email',  
  422. 'to_type' => 'user',  
  423. 'to_fieldname' => 'user_email' 
  424. ); 
  425.  
  426. // User registered. 
  427. $this->field_map[] = array( 
  428. 'from_tablename' => 'users',  
  429. 'from_fieldname' => 'date_added',  
  430. 'to_type' => 'user',  
  431. 'to_fieldname' => 'user_registered',  
  432. 'callback_method' => 'callback_datetime' 
  433. ); 
  434.  
  435. // User display name. 
  436. $this->field_map[] = array( 
  437. 'from_tablename' => 'users',  
  438. 'from_fieldname' => 'real_name',  
  439. 'to_type' => 'user',  
  440. 'to_fieldname' => 'display_name' 
  441. ); 
  442.  
  443. // Store Signature (Stored in usermeta) 
  444. $this->field_map[] = array( 
  445. 'from_tablename' => 'users',  
  446. 'from_fieldname' => 'signature',  
  447. 'to_type' => 'user',  
  448. 'to_fieldname' => '_bbp_phorum_user_sig',  
  449. 'callback_method' => 'callback_html' 
  450. ); 
  451.  
  452.  
  453. /** 
  454. * This method allows us to indicates what is or is not converted for each 
  455. * converter. 
  456. */ 
  457. public function info() 
  458. return ''; 
  459.  
  460. /** 
  461. * This method is to save the salt and password together. That 
  462. * way when we authenticate it we can get it out of the database 
  463. * as one value. Array values are auto sanitized by WordPress. 
  464. */ 
  465. public function callback_savepass( $field, $row ) 
  466. $pass_array = array( 'hash' => $field, 'salt' => $row['salt'] ); 
  467. return $pass_array; 
  468.  
  469. /** 
  470. * This method is to take the pass out of the database and compare 
  471. * to a pass the user has typed in. 
  472. */ 
  473. public function authenticate_pass( $password, $serialized_pass ) 
  474. $pass_array = unserialize( $serialized_pass ); 
  475. return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) ); 
  476.  
  477. /** 
  478. * Translate the forum type from Phorum v5.2.19 numeric's to WordPress's strings. 
  479. * @param int $status Phorum v5.2.19 numeric forum type 
  480. * @return string WordPress safe 
  481. */ 
  482. public function callback_forum_type( $status = 0 ) { 
  483. switch ( $status ) { 
  484. case 1 : 
  485. $status = 'category'; 
  486. break; 
  487.  
  488. case 0 : 
  489. default : 
  490. $status = 'forum'; 
  491. break; 
  492. return $status; 
  493.  
  494. /** 
  495. * Translate the post status from Phorum v5.2.19 numeric's to WordPress's strings. 
  496. * @param int $status Phorum v5.2.19 numeric topic status 
  497. * @return string WordPress safe 
  498. */ 
  499. public function callback_topic_status( $status = 0 ) { 
  500. switch ( $status ) { 
  501. case 1 : 
  502. $status = 'closed'; 
  503. break; 
  504.  
  505. case 0 : 
  506. default : 
  507. $status = 'publish'; 
  508. break; 
  509. return $status; 
  510.  
  511. /** 
  512. * Verify the topic/reply count. 
  513. * @param int $count Phorum v5.2.19 topic/reply counts 
  514. * @return string WordPress safe 
  515. */ 
  516. public function callback_topic_reply_count( $count = 1 ) { 
  517. $count = absint( (int) $count - 1 ); 
  518. return $count; 
  519.