SimplePress5

Implementation of SimplePress v5 converter.

Defined (1)

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

/includes/admin/converters/SimplePress5.php  
  1. class SimplePress5 extends BBP_Converter_Base { 
  2.  
  3. /** 
  4. * Main Constructor 
  5. * @uses SimplePress5::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' => 'sfforums',  
  21. 'from_fieldname' => 'forum_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' => 'sfforums',  
  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' => 'sfforums',  
  37. 'from_fieldname' => 'topic_count',  
  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' => 'sfforums',  
  45. 'from_fieldname' => 'post_count',  
  46. 'to_type' => 'forum',  
  47. 'to_fieldname' => '_bbp_reply_count' 
  48. ); 
  49.  
  50. // Forum total topic count (Stored in postmeta) 
  51. $this->field_map[] = array( 
  52. 'from_tablename' => 'sfforums',  
  53. 'from_fieldname' => 'topic_count',  
  54. 'to_type' => 'forum',  
  55. 'to_fieldname' => '_bbp_total_topic_count' 
  56. ); 
  57.  
  58. // Forum total reply count (Stored in postmeta) 
  59. $this->field_map[] = array( 
  60. 'from_tablename' => 'sfforums',  
  61. 'from_fieldname' => 'post_count',  
  62. 'to_type' => 'forum',  
  63. 'to_fieldname' => '_bbp_total_reply_count' 
  64. ); 
  65.  
  66. // Forum title. 
  67. $this->field_map[] = array( 
  68. 'from_tablename' => 'sfforums',  
  69. 'from_fieldname' => 'forum_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' => 'sfforums',  
  77. 'from_fieldname' => 'forum_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' => 'sfforums',  
  86. 'from_fieldname' => 'forum_desc',  
  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' => 'sfforums',  
  95. 'from_fieldname' => 'forum_seq',  
  96. 'to_type' => 'forum',  
  97. 'to_fieldname' => 'menu_order' 
  98. ); 
  99.  
  100. // Forum dates. 
  101. $this->field_map[] = array( 
  102. 'to_type' => 'forums',  
  103. 'to_fieldname' => 'post_date',  
  104. 'default' => date('Y-m-d H:i:s') 
  105. ); 
  106. $this->field_map[] = array( 
  107. 'to_type' => 'forums',  
  108. 'to_fieldname' => 'post_date_gmt',  
  109. 'default' => date('Y-m-d H:i:s') 
  110. ); 
  111. $this->field_map[] = array( 
  112. 'to_type' => 'forums',  
  113. 'to_fieldname' => 'post_modified',  
  114. 'default' => date('Y-m-d H:i:s') 
  115. ); 
  116. $this->field_map[] = array( 
  117. 'to_type' => 'forums',  
  118. 'to_fieldname' => 'post_modified_gmt',  
  119. 'default' => date('Y-m-d H:i:s') 
  120. ); 
  121.  
  122. /** Topic Section *****************************************************/ 
  123.  
  124. // Topic id (Stored in postmeta) 
  125. $this->field_map[] = array( 
  126. 'from_tablename' => 'sftopics',  
  127. 'from_fieldname' => 'topic_id',  
  128. 'to_type' => 'topic',  
  129. 'to_fieldname' => '_bbp_topic_id' 
  130. ); 
  131.  
  132. // Topic reply count (Stored in postmeta) 
  133. $this->field_map[] = array( 
  134. 'from_tablename' => 'sftopics',  
  135. 'from_fieldname' => 'post_count',  
  136. 'to_type' => 'topic',  
  137. 'to_fieldname' => '_bbp_reply_count',  
  138. 'callback_method' => 'callback_topic_reply_count' 
  139. ); 
  140.  
  141. // Topic parent forum id (If no parent, then 0. Stored in postmeta) 
  142. $this->field_map[] = array( 
  143. 'from_tablename' => 'sftopics',  
  144. 'from_fieldname' => 'forum_id',  
  145. 'to_type' => 'topic',  
  146. 'to_fieldname' => '_bbp_forum_id',  
  147. 'callback_method' => 'callback_forumid' 
  148. ); 
  149.  
  150. // Topic author. 
  151. $this->field_map[] = array( 
  152. 'from_tablename' => 'sftopics',  
  153. 'from_fieldname' => 'user_id',  
  154. 'to_type' => 'topic',  
  155. 'to_fieldname' => 'post_author',  
  156. 'callback_method' => 'callback_userid' 
  157. ); 
  158.  
  159. // Topic content. 
  160. // Note: We join the sfposts table because sftopics do not have content. 
  161. $this->field_map[] = array( 
  162. 'from_tablename' => 'sfposts',  
  163. 'from_fieldname' => 'post_content',  
  164. 'join_tablename' => 'sftopics',  
  165. 'join_type' => 'INNER',  
  166. 'join_expression' => 'USING (topic_id) WHERE sfposts.post_index = 1',  
  167. 'to_type' => 'topic',  
  168. 'to_fieldname' => 'post_content',  
  169. 'callback_method' => 'callback_html' 
  170. ); 
  171.  
  172. // Topic title. 
  173. $this->field_map[] = array( 
  174. 'from_tablename' => 'sftopics',  
  175. 'from_fieldname' => 'topic_name',  
  176. 'to_type' => 'topic',  
  177. 'to_fieldname' => 'post_title' 
  178. ); 
  179.  
  180. // Topic slug (Clean name to avoid conflicts) 
  181. $this->field_map[] = array( 
  182. 'from_tablename' => 'sftopics',  
  183. 'from_fieldname' => 'topic_name',  
  184. 'to_type' => 'topic',  
  185. 'to_fieldname' => 'post_name',  
  186. 'callback_method' => 'callback_slug' 
  187. ); 
  188.  
  189. // Topic parent forum id (If no parent, then 0) 
  190. $this->field_map[] = array( 
  191. 'from_tablename' => 'sftopics',  
  192. 'from_fieldname' => 'forum_id',  
  193. 'to_type' => 'topic',  
  194. 'to_fieldname' => 'post_parent',  
  195. 'callback_method' => 'callback_forumid' 
  196. ); 
  197.  
  198. // Topic status (Open or Closed) 
  199. $this->field_map[] = array( 
  200. 'from_tablename' => 'sftopics',  
  201. 'from_fieldname' => 'topic_status',  
  202. 'to_type' => 'topic',  
  203. 'to_fieldname' => 'post_status',  
  204. 'callback_method' => 'callback_status' 
  205. ); 
  206.  
  207. // Sticky status (Stored in postmeta)) 
  208. $this->field_map[] = array( 
  209. 'from_tablename' => 'sftopics',  
  210. 'from_fieldname' => 'topic_pinned',  
  211. 'to_type' => 'topic',  
  212. 'to_fieldname' => '_bbp_old_sticky_status',  
  213. 'callback_method' => 'callback_sticky_status' 
  214. ); 
  215.  
  216. // Topic dates. 
  217. $this->field_map[] = array( 
  218. 'from_tablename' => 'sftopics',  
  219. 'from_fieldname' => 'topic_date',  
  220. 'to_type' => 'topic',  
  221. 'to_fieldname' => 'post_date' 
  222. ); 
  223. $this->field_map[] = array( 
  224. 'from_tablename' => 'sftopics',  
  225. 'from_fieldname' => 'topic_date',  
  226. 'to_type' => 'topic',  
  227. 'to_fieldname' => 'post_date_gmt' 
  228. ); 
  229. $this->field_map[] = array( 
  230. 'from_tablename' => 'sftopics',  
  231. 'from_fieldname' => 'topic_date',  
  232. 'to_type' => 'topic',  
  233. 'to_fieldname' => 'post_modified' 
  234. ); 
  235. $this->field_map[] = array( 
  236. 'from_tablename' => 'sftopics',  
  237. 'from_fieldname' => 'topic_date',  
  238. 'to_type' => 'topic',  
  239. 'to_fieldname' => 'post_modified_gmt' 
  240. ); 
  241. $this->field_map[] = array( 
  242. 'from_tablename' => 'sftopics',  
  243. 'from_fieldname' => 'topic_date',  
  244. 'to_type' => 'topic',  
  245. 'to_fieldname' => '_bbp_last_active_time' 
  246. ); 
  247.  
  248. /** Tags Section ******************************************************/ 
  249.  
  250. /** 
  251. * SimplePress Forums do not support topic tags without paid extensions 
  252. */ 
  253.  
  254. /** Reply Section *****************************************************/ 
  255.  
  256. // Reply id (Stored in postmeta) 
  257. $this->field_map[] = array( 
  258. 'from_tablename' => 'sfposts',  
  259. 'from_fieldname' => 'post_id',  
  260. 'to_type' => 'reply',  
  261. 'to_fieldname' => '_bbp_post_id' 
  262. ); 
  263.  
  264. // Reply parent forum id (If no parent, then 0. Stored in postmeta) 
  265. $this->field_map[] = array( 
  266. 'from_tablename' => 'sfposts',  
  267. 'from_fieldname' => 'forum_id',  
  268. 'to_type' => 'reply',  
  269. 'to_fieldname' => '_bbp_forum_id',  
  270. 'callback_method' => 'callback_topicid_to_forumid' 
  271. ); 
  272.  
  273. // Reply parent topic id (If no parent, then 0. Stored in postmeta) 
  274. $this->field_map[] = array( 
  275. 'from_tablename' => 'sfposts',  
  276. 'from_fieldname' => 'topic_id',  
  277. 'to_type' => 'reply',  
  278. 'to_fieldname' => '_bbp_topic_id',  
  279. 'callback_method' => 'callback_topicid' 
  280. ); 
  281.  
  282. // Reply author ip (Stored in postmeta) 
  283. $this->field_map[] = array( 
  284. 'from_tablename' => 'sfposts',  
  285. 'from_fieldname' => 'poster_ip',  
  286. 'to_type' => 'reply',  
  287. 'to_fieldname' => '_bbp_author_ip' 
  288. ); 
  289.  
  290. // Reply author. 
  291. $this->field_map[] = array( 
  292. 'from_tablename' => 'sfposts',  
  293. 'from_fieldname' => 'user_id',  
  294. 'to_type' => 'reply',  
  295. 'to_fieldname' => 'post_author',  
  296. 'callback_method' => 'callback_userid' 
  297. ); 
  298.  
  299. // Reply title. 
  300. // Note: We join the sftopics table because sfposts table does not include topic title. 
  301. $this->field_map[] = array( 
  302. 'from_tablename' => 'sftopics',  
  303. 'from_fieldname' => 'topic_name',  
  304. 'join_tablename' => 'sfposts',  
  305. 'join_type' => 'LEFT',  
  306. 'join_expression' => 'USING (topic_id) WHERE sfposts.post_index != 1',  
  307. 'to_type' => 'reply',  
  308. 'to_fieldname' => 'post_title',  
  309. 'callback_method' => 'callback_reply_title' 
  310. ); 
  311.  
  312. // Reply slug (Clean name to avoid conflicts) 
  313. // Note: We join the sftopics table because sfposts table does not include topic title. 
  314. $this->field_map[] = array( 
  315. 'from_tablename' => 'sftopics',  
  316. 'from_fieldname' => 'topic_name',  
  317. 'join_tablename' => 'sfposts',  
  318. 'join_type' => 'LEFT',  
  319. 'join_expression' => 'USING (topic_id) WHERE sfposts.post_index != 1',  
  320. 'to_type' => 'reply',  
  321. 'to_fieldname' => 'post_name',  
  322. 'callback_method' => 'callback_slug' 
  323. ); 
  324.  
  325. // Reply content. 
  326. $this->field_map[] = array( 
  327. 'from_tablename' => 'sfposts',  
  328. 'from_fieldname' => 'post_content',  
  329. 'to_type' => 'reply',  
  330. 'to_fieldname' => 'post_content',  
  331. 'callback_method' => 'callback_html' 
  332. ); 
  333.  
  334. // Reply parent topic id (If no parent, then 0) 
  335. $this->field_map[] = array( 
  336. 'from_tablename' => 'sfposts',  
  337. 'from_fieldname' => 'topic_id',  
  338. 'to_type' => 'reply',  
  339. 'to_fieldname' => 'post_parent',  
  340. 'callback_method' => 'callback_topicid' 
  341. ); 
  342.  
  343. // Reply dates. 
  344. $this->field_map[] = array( 
  345. 'from_tablename' => 'sfposts',  
  346. 'from_fieldname' => 'post_date',  
  347. 'to_type' => 'reply',  
  348. 'to_fieldname' => 'post_date' 
  349. ); 
  350. $this->field_map[] = array( 
  351. 'from_tablename' => 'sfposts',  
  352. 'from_fieldname' => 'post_date',  
  353. 'to_type' => 'reply',  
  354. 'to_fieldname' => 'post_date_gmt' 
  355. ); 
  356. $this->field_map[] = array( 
  357. 'from_tablename' => 'sfposts',  
  358. 'from_fieldname' => 'post_date',  
  359. 'to_type' => 'reply',  
  360. 'to_fieldname' => 'post_modified' 
  361. ); 
  362. $this->field_map[] = array( 
  363. 'from_tablename' => 'sfposts',  
  364. 'from_fieldname' => 'post_date',  
  365. 'to_type' => 'reply',  
  366. 'to_fieldname' => 'post_modified_gmt' 
  367. ); 
  368.  
  369. /** User Section ******************************************************/ 
  370.  
  371. // Store old User id (Stored in usermeta) 
  372. $this->field_map[] = array( 
  373. 'from_tablename' => 'users',  
  374. 'from_fieldname' => 'ID',  
  375. 'to_type' => 'user',  
  376. 'to_fieldname' => '_bbp_user_id' 
  377. ); 
  378.  
  379. // Store old User password (Stored in usermeta) 
  380. $this->field_map[] = array( 
  381. 'from_tablename' => 'users',  
  382. 'from_fieldname' => 'user_pass',  
  383. 'to_type' => 'user',  
  384. 'to_fieldname' => '_bbp_password' 
  385. ); 
  386.  
  387. // User name. 
  388. $this->field_map[] = array( 
  389. 'from_tablename' => 'users',  
  390. 'from_fieldname' => 'user_login',  
  391. 'to_type' => 'user',  
  392. 'to_fieldname' => 'user_login' 
  393. ); 
  394.  
  395. // User nice name. 
  396. $this->field_map[] = array( 
  397. 'from_tablename' => 'users',  
  398. 'from_fieldname' => 'user_nicename',  
  399. 'to_type' => 'user',  
  400. 'to_fieldname' => 'user_nicename' 
  401. ); 
  402.  
  403. // User email. 
  404. $this->field_map[] = array( 
  405. 'from_tablename' => 'users',  
  406. 'from_fieldname' => 'user_email',  
  407. 'to_type' => 'user',  
  408. 'to_fieldname' => 'user_email' 
  409. ); 
  410.  
  411. // User homepage. 
  412. $this->field_map[] = array( 
  413. 'from_tablename' => 'users',  
  414. 'from_fieldname' => 'user_url',  
  415. 'to_type' => 'user',  
  416. 'to_fieldname' => 'user_url' 
  417. ); 
  418.  
  419. // User registered. 
  420. $this->field_map[] = array( 
  421. 'from_tablename' => 'users',  
  422. 'from_fieldname' => 'user_registered',  
  423. 'to_type' => 'user',  
  424. 'to_fieldname' => 'user_registered' 
  425. ); 
  426.  
  427. // User status. 
  428. $this->field_map[] = array( 
  429. 'from_tablename' => 'users',  
  430. 'from_fieldname' => 'user_status',  
  431. 'to_type' => 'user',  
  432. 'to_fieldname' => 'user_status' 
  433. ); 
  434.  
  435. // User display name. 
  436. $this->field_map[] = array( 
  437. 'from_tablename' => 'users',  
  438. 'from_fieldname' => 'display_name',  
  439. 'to_type' => 'user',  
  440. 'to_fieldname' => 'display_name' 
  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. return false; 
  457.  
  458. /** 
  459. * This method is to take the pass out of the database and compare 
  460. * to a pass the user has typed in. 
  461. */ 
  462. public function authenticate_pass( $password, $serialized_pass ) { 
  463. return false; 
  464.  
  465. /** 
  466. * Translate the post status from Simple:Press v5.x numeric's to WordPress's strings. 
  467. * @param int $status Simple:Press numeric status 
  468. * @return string WordPress safe 
  469. */ 
  470. public function callback_status( $status = 0 ) { 
  471. switch ( $status ) { 
  472. case 1 : 
  473. $status = 'closed'; 
  474. break; 
  475.  
  476. case 0 : 
  477. default : 
  478. $status = 'publish'; 
  479. break; 
  480. return $status; 
  481.  
  482. /** 
  483. * Translate the topic sticky status type from Simple:Press v5.x numeric's to WordPress's strings. 
  484. * @param int $status Simple:Press v5.x numeric forum type 
  485. * @return string WordPress safe 
  486. */ 
  487. public function callback_sticky_status( $status = 0 ) { 
  488. switch ( $status ) { 
  489. case 1 : 
  490. $status = 'sticky'; // Simple:Press Sticky 'topic_sticky = 1' 
  491. break; 
  492.  
  493. case 0 : 
  494. default : 
  495. $status = 'normal'; // Simple:Press Normal Topic 'topic_sticky = 0' 
  496. break; 
  497. return $status; 
  498.  
  499. /** 
  500. * Verify the topic reply count. 
  501. * @param int $count Simple:Press v5.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 Simple:Press v5.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 callback processes any custom parser.php attributes and custom HTML code with preg_replace 
  519. */ 
  520. protected function callback_html( $field ) { 
  521.  
  522. // Strip any custom HTML not supported by parser.php first from $field before parsing $field to parser.php 
  523. $simplepress_markup = $field; 
  524. $simplepress_markup = html_entity_decode( $simplepress_markup ); 
  525.  
  526. // Replace any SimplePress smilies from path '/sp-resources/forum-smileys/sf-smily.gif' with the equivelant WordPress Smilie 
  527. $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-confused\.gif(.*?)\" \/>/', ':?' , $simplepress_markup ); 
  528. $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-cool\.gif(.*?)\" \/>/', ':cool:', $simplepress_markup ); 
  529. $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-cry\.gif(.*?)\" \/>/', ':cry:', $simplepress_markup ); 
  530. $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-embarassed\.gif(.*?)\" \/>/' , ':oops:', $simplepress_markup ); 
  531. $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-frown\.gif(.*?)\" \/>/', ':(', $simplepress_markup ); 
  532. $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-kiss\.gif(.*?)\" \/>/', ':P', $simplepress_markup ); 
  533. $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-laugh\.gif(.*?)\" \/>/', ':D', $simplepress_markup ); 
  534. $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-smile\.gif(.*?)\" \/>/', ':smile:', $simplepress_markup ); 
  535. $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-surprised\.gif(.*?)\" \/>/', ':o', $simplepress_markup ); 
  536. $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-wink\.gif(.*?)\" \/>/', ':wink:', $simplepress_markup ); 
  537. $simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-yell\.gif(.*?)\" \/>/', ':x', $simplepress_markup ); 
  538.  
  539. // Replace '<div class="sfcode">example code</div>' with '<code>*</code>' 
  540. $simplepress_markup = preg_replace( '/\<div class\=\"sfcode\"\>(.*?)\<\/div\>/' , '<code>$1</code>' , $simplepress_markup ); 
  541.  
  542. // Replace '<strong>username said </strong>' with '@username said:' 
  543. $simplepress_markup = preg_replace ( '/\<strong\>(.*?)\ said\ \<\/strong\>/', '@$1 said:', $simplepress_markup ); 
  544.  
  545. // Replace '<p> </p>' with '<p> </p>' 
  546. $simplepress_markup = preg_replace ( '/\n( |[\s\p{Z}\xA0\x{00A0}]+)\r/', '<br>', $simplepress_markup ); 
  547.  
  548. // Now that SimplePress' custom HTML codes have been stripped put the cleaned HTML back in $field 
  549. $field = $simplepress_markup; 
  550.  
  551. // Parse out any bbCodes with the BBCode 'parser.php' 
  552. require_once( bbpress()->admin->admin_dir . 'parser.php' ); 
  553. $bbcode = BBCode::getInstance(); 
  554. $bbcode->enable_smileys = false; 
  555. $bbcode->smiley_regex = false; 
  556. return html_entity_decode( $bbcode->Parse( $field ) );