Vanilla

Implementation of Vanilla 2.0.18.1 Converter.

Defined (1)

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

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