Mingle

Implementation of Mingle Forums converter.

Defined (1)

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

/includes/admin/converters/Mingle.php  
  1. class Mingle extends BBP_Converter_Base { 
  2.  
  3. /** 
  4. * Main constructor 
  5. * @uses Mingle::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' => 'forum_forums',  
  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' => 'forum_forums',  
  29. 'from_fieldname' => 'parent_id',  
  30. 'to_type' => 'forum',  
  31. 'to_fieldname' => '_bbp_forum_parent_id' 
  32. ); 
  33.  
  34. // Forum title. 
  35. $this->field_map[] = array( 
  36. 'from_tablename' => 'forum_forums',  
  37. 'from_fieldname' => 'name',  
  38. 'to_type' => 'forum',  
  39. 'to_fieldname' => 'post_title' 
  40. ); 
  41.  
  42. // Forum slug (Clean name to avoid confilcts) 
  43. $this->field_map[] = array( 
  44. 'from_tablename' => 'forum_forums',  
  45. 'from_fieldname' => 'name',  
  46. 'to_type' => 'forum',  
  47. 'to_fieldname' => 'post_name',  
  48. 'callback_method' => 'callback_slug' 
  49. ); 
  50. // Forum description. 
  51. $this->field_map[] = array( 
  52. 'from_tablename' => 'forum_forums',  
  53. 'from_fieldname' => 'description',  
  54. 'to_type' => 'forum',  
  55. 'to_fieldname' => 'post_content',  
  56. 'callback_method' => 'callback_null' 
  57. ); 
  58.  
  59. // Forum display order (Starts from 1) 
  60. $this->field_map[] = array( 
  61. 'from_tablename' => 'forum_forums',  
  62. 'from_fieldname' => 'sort',  
  63. 'to_type' => 'forum',  
  64. 'to_fieldname' => 'menu_order' 
  65. ); 
  66.  
  67. // Forum dates. 
  68. $this->field_map[] = array( 
  69. 'to_type' => 'forum',  
  70. 'to_fieldname' => 'post_date',  
  71. 'default' => date('Y-m-d H:i:s') 
  72. ); 
  73. $this->field_map[] = array( 
  74. 'to_type' => 'forum',  
  75. 'to_fieldname' => 'post_date_gmt',  
  76. 'default' => date('Y-m-d H:i:s') 
  77. ); 
  78. $this->field_map[] = array( 
  79. 'to_type' => 'forum',  
  80. 'to_fieldname' => 'post_modified',  
  81. 'default' => date('Y-m-d H:i:s') 
  82. ); 
  83. $this->field_map[] = array( 
  84. 'to_type' => 'forum',  
  85. 'to_fieldname' => 'post_modified_gmt',  
  86. 'default' => date('Y-m-d H:i:s') 
  87. ); 
  88.  
  89. /** Topic Section ******************************************************/ 
  90.  
  91. // Topic id (Stored in postmeta) 
  92. $this->field_map[] = array( 
  93. 'from_tablename' => 'forum_threads',  
  94. 'from_fieldname' => 'id',  
  95. 'to_type' => 'topic',  
  96. 'to_fieldname' => '_bbp_topic_id' 
  97. ); 
  98.  
  99. // Topic parent forum id (If no parent, then 0. Stored in postmeta) 
  100. $this->field_map[] = array( 
  101. 'from_tablename' => 'forum_threads',  
  102. 'from_fieldname' => 'parent_id',  
  103. 'to_type' => 'topic',  
  104. 'to_fieldname' => '_bbp_forum_id',  
  105. 'callback_method' => 'callback_forumid' 
  106. ); 
  107.  
  108. // Topic author. 
  109. $this->field_map[] = array( 
  110. 'from_tablename' => 'forum_threads',  
  111. 'from_fieldname' => 'starter',  
  112. 'to_type' => 'topic',  
  113. 'to_fieldname' => 'post_author',  
  114. 'callback_method' => 'callback_userid' 
  115. ); 
  116.  
  117. // Topic content. 
  118. // Note: We join the forum_posts table because forum_topics do not have topic content. 
  119. $this->field_map[] = array( 
  120. 'from_tablename' => 'forum_posts',  
  121. 'from_fieldname' => 'text',  
  122. 'join_tablename' => 'forum_threads',  
  123. 'join_type' => 'INNER',  
  124. 'join_expression' => 'ON forum_posts.parent_id = forum_threads.id GROUP BY forum_threads.id',  
  125. 'to_type' => 'topic',  
  126. 'to_fieldname' => 'post_content',  
  127. 'callback_method' => 'callback_html' 
  128. ); 
  129. // Topic title. 
  130. $this->field_map[] = array( 
  131. 'from_tablename' => 'forum_threads',  
  132. 'from_fieldname' => 'subject',  
  133. 'to_type' => 'topic',  
  134. 'to_fieldname' => 'post_title' 
  135. ); 
  136.  
  137. // Topic slug (Clean name to avoid conflicts) 
  138. $this->field_map[] = array( 
  139. 'from_tablename' => 'forum_threads',  
  140. 'from_fieldname' => 'subject',  
  141. 'to_type' => 'topic',  
  142. 'to_fieldname' => 'post_name',  
  143. 'callback_method' => 'callback_slug' 
  144. ); 
  145.  
  146. // Topic parent forum id (If no parent, then 0) 
  147. $this->field_map[] = array( 
  148. 'from_tablename' => 'forum_threads',  
  149. 'from_fieldname' => 'parent_id',  
  150. 'to_type' => 'topic',  
  151. 'to_fieldname' => 'post_parent',  
  152. 'callback_method' => 'callback_forumid' 
  153. ); 
  154.  
  155. // Sticky status (Stored in postmeta)) 
  156. $this->field_map[] = array( 
  157. 'from_tablename' => 'forum_threads',  
  158. 'from_fieldname' => 'status',  
  159. 'to_type' => 'topic',  
  160. 'to_fieldname' => '_bbp_old_sticky_status',  
  161. 'callback_method' => 'callback_sticky_status' 
  162. ); 
  163.  
  164. // Topic dates. 
  165. $this->field_map[] = array( 
  166. 'from_tablename' => 'forum_threads',  
  167. 'from_fieldname' => 'date',  
  168. 'to_type' => 'topic',  
  169. 'to_fieldname' => 'post_date' 
  170. ); 
  171. $this->field_map[] = array( 
  172. 'from_tablename' => 'forum_threads',  
  173. 'from_fieldname' => 'date',  
  174. 'to_type' => 'topic',  
  175. 'to_fieldname' => 'post_date_gmt' 
  176. ); 
  177. $this->field_map[] = array( 
  178. 'from_tablename' => 'forum_threads',  
  179. 'from_fieldname' => 'last_post',  
  180. 'to_type' => 'topic',  
  181. 'to_fieldname' => 'post_modified' 
  182. ); 
  183. $this->field_map[] = array( 
  184. 'from_tablename' => 'forum_threads',  
  185. 'from_fieldname' => 'last_post',  
  186. 'to_type' => 'topic',  
  187. 'to_fieldname' => 'post_modified_gmt' 
  188. ); 
  189. $this->field_map[] = array( 
  190. 'from_tablename' => 'forum_threads',  
  191. 'from_fieldname' => 'last_post',  
  192. 'to_type' => 'topic',  
  193. 'to_fieldname' => '_bbp_last_active_time' 
  194. ); 
  195.  
  196. // Topic status (Open or Closed) 
  197. $this->field_map[] = array( 
  198. 'from_tablename' => 'forum_threads',  
  199. 'from_fieldname' => 'closed',  
  200. 'to_type' => 'topic',  
  201. 'to_fieldname' => 'post_status',  
  202. 'callback_method' => 'callback_topic_status' 
  203. ); 
  204.  
  205. /** Tags Section ******************************************************/ 
  206.  
  207. /** 
  208. * Mingle Forums do not support topic tags 
  209. */ 
  210.  
  211. /** Reply Section ******************************************************/ 
  212.  
  213. // Reply id (Stored in postmeta) 
  214. $this->field_map[] = array( 
  215. 'from_tablename' => 'forum_posts',  
  216. 'from_fieldname' => 'id',  
  217. 'to_type' => 'reply',  
  218. 'to_fieldname' => '_bbp_post_id' 
  219. ); 
  220.  
  221. // Setup reply section table joins 
  222. // We need join the 'forum_threads' table to only import replies 
  223. $this->field_map[] = array( 
  224. 'from_tablename' => 'forum_threads',  
  225. 'from_fieldname' => 'date',  
  226. 'join_tablename' => 'forum_posts',  
  227. 'join_type' => 'INNER',  
  228. 'join_expression' => 'ON forum_posts.parent_id = forum_threads.id',  
  229. 'from_expression' => 'WHERE forum_threads.subject != forum_posts.subject',  
  230. 'to_type' => 'reply',  
  231. 'to_fieldname' => '_bbp_last_active_time' 
  232. ); 
  233.  
  234. // Reply parent forum id (If no parent, then 0. Stored in postmeta) 
  235. $this->field_map[] = array( 
  236. 'from_tablename' => 'forum_posts',  
  237. 'from_fieldname' => 'parent_id',  
  238. 'to_type' => 'reply',  
  239. 'to_fieldname' => '_bbp_forum_id',  
  240. 'callback_method' => 'callback_topicid_to_forumid' 
  241. ); 
  242.  
  243. // Reply parent topic id (If no parent, then 0. Stored in postmeta) 
  244. $this->field_map[] = array( 
  245. 'from_tablename' => 'forum_posts',  
  246. 'from_fieldname' => 'parent_id',  
  247. 'to_type' => 'reply',  
  248. 'to_fieldname' => '_bbp_topic_id',  
  249. 'callback_method' => 'callback_topicid' 
  250. ); 
  251.  
  252. // Reply author. 
  253. $this->field_map[] = array( 
  254. 'from_tablename' => 'forum_posts',  
  255. 'from_fieldname' => 'author_id',  
  256. 'to_type' => 'reply',  
  257. 'to_fieldname' => 'post_author',  
  258. 'callback_method' => 'callback_userid' 
  259. ); 
  260.  
  261. // Reply title. 
  262. $this->field_map[] = array( 
  263. 'from_tablename' => 'forum_posts',  
  264. 'from_fieldname' => 'subject',  
  265. 'to_type' => 'reply',  
  266. 'to_fieldname' => 'post_title' 
  267. ); 
  268.  
  269. // Reply slug (Clean name to avoid conflicts) 
  270. $this->field_map[] = array( 
  271. 'from_tablename' => 'forum_posts',  
  272. 'from_fieldname' => 'subject',  
  273. 'to_type' => 'reply',  
  274. 'to_fieldname' => 'post_name',  
  275. 'callback_method' => 'callback_slug' 
  276. ); 
  277.  
  278. // Reply content. 
  279. $this->field_map[] = array( 
  280. 'from_tablename' => 'forum_posts',  
  281. 'from_fieldname' => 'text',  
  282. 'to_type' => 'reply',  
  283. 'to_fieldname' => 'post_content',  
  284. 'callback_method' => 'callback_html' 
  285. ); 
  286.  
  287. // Reply parent topic id (If no parent, then 0) 
  288. $this->field_map[] = array( 
  289. 'from_tablename' => 'forum_posts',  
  290. 'from_fieldname' => 'parent_id',  
  291. 'to_type' => 'reply',  
  292. 'to_fieldname' => 'post_parent',  
  293. 'callback_method' => 'callback_topicid' 
  294. ); 
  295.  
  296. // Reply dates. 
  297. $this->field_map[] = array( 
  298. 'from_tablename' => 'forum_posts',  
  299. 'from_fieldname' => 'date',  
  300. 'to_type' => 'reply',  
  301. 'to_fieldname' => 'post_date' 
  302. ); 
  303. $this->field_map[] = array( 
  304. 'from_tablename' => 'forum_posts',  
  305. 'from_fieldname' => 'date',  
  306. 'to_type' => 'reply',  
  307. 'to_fieldname' => 'post_date_gmt' 
  308. ); 
  309. $this->field_map[] = array( 
  310. 'from_tablename' => 'forum_posts',  
  311. 'from_fieldname' => 'date',  
  312. 'to_type' => 'reply',  
  313. 'to_fieldname' => 'post_modified' 
  314. ); 
  315. $this->field_map[] = array( 
  316. 'from_tablename' => 'forum_posts',  
  317. 'from_fieldname' => 'date',  
  318. 'to_type' => 'reply',  
  319. 'to_fieldname' => 'post_modified_gmt' 
  320. ); 
  321.  
  322. /** User Section ******************************************************/ 
  323.  
  324. // Store old User id (Stored in usermeta) 
  325. $this->field_map[] = array( 
  326. 'from_tablename' => 'users',  
  327. 'from_fieldname' => 'ID',  
  328. 'to_type' => 'user',  
  329. 'to_fieldname' => '_bbp_user_id' 
  330. ); 
  331.  
  332. // Store old User password (Stored in usermeta) 
  333. $this->field_map[] = array( 
  334. 'from_tablename' => 'users',  
  335. 'from_fieldname' => 'user_pass',  
  336. 'to_type' => 'user',  
  337. 'to_fieldname' => '_bbp_password' 
  338. ); 
  339.  
  340. // User name. 
  341. $this->field_map[] = array( 
  342. 'from_tablename' => 'users',  
  343. 'from_fieldname' => 'user_login',  
  344. 'to_type' => 'user',  
  345. 'to_fieldname' => 'user_login' 
  346. ); 
  347.  
  348. // User nice name. 
  349. $this->field_map[] = array( 
  350. 'from_tablename' => 'users',  
  351. 'from_fieldname' => 'user_nicename',  
  352. 'to_type' => 'user',  
  353. 'to_fieldname' => 'user_nicename' 
  354. ); 
  355.  
  356. // User email. 
  357. $this->field_map[] = array( 
  358. 'from_tablename' => 'users',  
  359. 'from_fieldname' => 'user_email',  
  360. 'to_type' => 'user',  
  361. 'to_fieldname' => 'user_email' 
  362. ); 
  363.  
  364. // User homepage. 
  365. $this->field_map[] = array( 
  366. 'from_tablename' => 'users',  
  367. 'from_fieldname' => 'user_url',  
  368. 'to_type' => 'user',  
  369. 'to_fieldname' => 'user_url' 
  370. ); 
  371.  
  372. // User registered. 
  373. $this->field_map[] = array( 
  374. 'from_tablename' => 'users',  
  375. 'from_fieldname' => 'user_registered',  
  376. 'to_type' => 'user',  
  377. 'to_fieldname' => 'user_registered' 
  378. ); 
  379.  
  380. // User status. 
  381. $this->field_map[] = array( 
  382. 'from_tablename' => 'users',  
  383. 'from_fieldname' => 'user_status',  
  384. 'to_type' => 'user',  
  385. 'to_fieldname' => 'user_status' 
  386. ); 
  387.  
  388. // User display name. 
  389. $this->field_map[] = array( 
  390. 'from_tablename' => 'users',  
  391. 'from_fieldname' => 'display_name',  
  392. 'to_type' => 'user',  
  393. 'to_fieldname' => 'display_name' 
  394. ); 
  395.  
  396. /** 
  397. * This method allows us to indicates what is or is not converted for each 
  398. * converter. 
  399. */ 
  400. public function info() { 
  401. return ''; 
  402.  
  403. /** 
  404. * This method is to save the salt and password together. That 
  405. * way when we authenticate it we can get it out of the database 
  406. * as one value. Array values are auto sanitized by WordPress. 
  407. */ 
  408. public function callback_savepass( $field, $row ) { 
  409. return false; 
  410.  
  411. /** 
  412. * This method is to take the pass out of the database and compare 
  413. * to a pass the user has typed in. 
  414. */ 
  415. public function authenticate_pass( $password, $serialized_pass ) { 
  416. return false; 
  417.  
  418. /** 
  419. * Translate the topic status from Mingle numeric's to WordPress's strings. 
  420. * @param int $status Mingle v1.x numeric topic status 
  421. * @return string WordPress safe 
  422. */ 
  423. public function callback_topic_status( $status = 0 ) { 
  424. switch ( $status ) { 
  425. case 1 : 
  426. $status = 'closed'; 
  427. break; 
  428.  
  429. case 0 : 
  430. default : 
  431. $status = 'publish'; 
  432. break; 
  433. return $status; 
  434.  
  435. /** 
  436. * Translate the topic sticky status type from Mingle numeric's to WordPress's strings. 
  437. * @param int $status Mingle numeric forum type 
  438. * @return string WordPress safe 
  439. */ 
  440. public function callback_sticky_status( $status = 0 ) { 
  441. switch ( $status ) { 
  442. case 'sticky' : 
  443. $status = 'sticky'; // Mingle Sticky 'status = sticky' 
  444. break; 
  445.  
  446. case 'open' : 
  447. default : 
  448. $status = 'normal'; // Mingle Normal Topic 'status = open' 
  449. break; 
  450. return $status; 
  451.  
  452. /** 
  453. * This callback processes any custom BBCodes with parser.php 
  454. */ 
  455. protected function callback_html( $field ) { 
  456. require_once( bbpress()->admin->admin_dir . 'parser.php' ); 
  457. $bbcode = BBCode::getInstance(); 
  458. $bbcode->enable_smileys = false; 
  459. $bbcode->smiley_regex = false; 
  460. return html_entity_decode( $bbcode->Parse( $field ) ); 
  461.