Drupal7

Implementation of Drupal v7.x Forum converter.

Defined (1)

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

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