Kunena1

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

Defined (1)

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

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