Kunena2

Implementation of Kunena v2.x Forums for Joomla Forum converter.

Defined (1)

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

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