PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/bbpress/includes/admin/converters/phpBB.php

https://bitbucket.org/adatux_/uakami
PHP | 538 lines | 374 code | 67 blank | 97 comment | 17 complexity | 99ae2b013bb2f5a36ffce59602374c1d MD5 | raw file
  1. <?php
  2. /**
  3. * Implementation of phpBB converter.
  4. */
  5. class phpBB extends BBP_Converter_Base {
  6. function __construct() {
  7. parent::__construct();
  8. $this->setup_globals();
  9. }
  10. public function setup_globals() {
  11. /** Forum Section ******************************************************/
  12. // Forum id. Stored in postmeta.
  13. $this->field_map[] = array(
  14. 'from_tablename' => 'forums',
  15. 'from_fieldname' => 'forum_id',
  16. 'to_type' => 'forum',
  17. 'to_fieldname' => '_bbp_forum_id'
  18. );
  19. // Forum parent id. If no parent, than 0. Stored in postmeta.
  20. $this->field_map[] = array(
  21. 'from_tablename' => 'forums',
  22. 'from_fieldname' => 'parent_id',
  23. 'to_type' => 'forum',
  24. 'to_fieldname' => '_bbp_parent_id'
  25. );
  26. // Forum title.
  27. $this->field_map[] = array(
  28. 'from_tablename' => 'forums',
  29. 'from_fieldname' => 'forum_name',
  30. 'to_type' => 'forum',
  31. 'to_fieldname' => 'post_title'
  32. );
  33. // Forum slug. Clean name.
  34. $this->field_map[] = array(
  35. 'from_tablename' => 'forums',
  36. 'from_fieldname' => 'forum_name',
  37. 'to_type' => 'forum',
  38. 'to_fieldname' => 'post_name',
  39. 'callback_method' => 'callback_slug'
  40. );
  41. // Forum description.
  42. $this->field_map[] = array(
  43. 'from_tablename' => 'forums',
  44. 'from_fieldname' => 'forum_desc',
  45. 'to_type' => 'forum',
  46. 'to_fieldname' => 'post_content',
  47. 'callback_method' => 'callback_null'
  48. );
  49. // Forum display order. Starts from 1.
  50. $this->field_map[] = array(
  51. 'from_tablename' => 'forums',
  52. 'from_fieldname' => 'display_on_index',
  53. 'to_type' => 'forum',
  54. 'to_fieldname' => 'menu_order'
  55. );
  56. // Forum date update.
  57. $this->field_map[] = array(
  58. 'to_type' => 'forums',
  59. 'to_fieldname' => 'forum_last_post_time',
  60. 'default' => date('Y-m-d H:i:s')
  61. );
  62. $this->field_map[] = array(
  63. 'to_type' => 'forums',
  64. 'to_fieldname' => 'forum_last_post_time',
  65. 'default' => date('Y-m-d H:i:s')
  66. );
  67. $this->field_map[] = array(
  68. 'to_type' => 'forums',
  69. 'to_fieldname' => 'forum_last_post_time',
  70. 'default' => date('Y-m-d H:i:s')
  71. );
  72. $this->field_map[] = array(
  73. 'to_type' => 'forums',
  74. 'to_fieldname' => 'forum_last_post_time',
  75. 'default' => date('Y-m-d H:i:s')
  76. );
  77. /** Topic Section ******************************************************/
  78. // Topic id. Stored in postmeta.
  79. $this->field_map[] = array(
  80. 'from_tablename' => 'topics',
  81. 'from_fieldname' => 'topic_id',
  82. 'to_type' => 'topic',
  83. 'to_fieldname' => '_bbp_topic_id'
  84. );
  85. // Forum id. Stored in postmeta.
  86. $this->field_map[] = array(
  87. 'from_tablename' => 'topics',
  88. 'from_fieldname' => 'forum_id',
  89. 'to_type' => 'topic',
  90. 'to_fieldname' => '_bbp_forum_id',
  91. 'callback_method' => 'callback_forumid'
  92. );
  93. // Topic author.
  94. $this->field_map[] = array(
  95. 'from_tablename' => 'topics',
  96. 'from_fieldname' => 'topic_poster',
  97. 'to_type' => 'topic',
  98. 'to_fieldname' => 'post_author',
  99. 'callback_method' => 'callback_userid'
  100. );
  101. // Topic content.
  102. $this->field_map[] = array(
  103. 'from_tablename' => 'posts',
  104. 'from_fieldname' => 'post_text',
  105. 'join_tablename' => 'topics',
  106. 'join_type' => 'INNER',
  107. 'join_expression' => 'USING (topic_id) WHERE posts.post_id = topics.topic_first_post_id',
  108. 'to_type' => 'topic',
  109. 'to_fieldname' => 'post_content',
  110. 'callback_method' => 'callback_html'
  111. );
  112. // Topic title.
  113. $this->field_map[] = array(
  114. 'from_tablename' => 'topics',
  115. 'from_fieldname' => 'topic_title',
  116. 'to_type' => 'topic',
  117. 'to_fieldname' => 'post_title'
  118. );
  119. // Topic slug. Clean name.
  120. $this->field_map[] = array(
  121. 'from_tablename' => 'topics',
  122. 'from_fieldname' => 'topic_title',
  123. 'to_type' => 'topic',
  124. 'to_fieldname' => 'post_name',
  125. 'callback_method' => 'callback_slug'
  126. );
  127. // Forum id. If no parent, than 0.
  128. $this->field_map[] = array(
  129. 'from_tablename' => 'topics',
  130. 'from_fieldname' => 'forum_id',
  131. 'to_type' => 'topic',
  132. 'to_fieldname' => 'post_parent',
  133. 'callback_method' => 'callback_forumid'
  134. );
  135. // Topic date update.
  136. $this->field_map[] = array(
  137. 'from_tablename' => 'topics',
  138. 'from_fieldname' => 'topic_time',
  139. 'to_type' => 'topic',
  140. 'to_fieldname' => 'post_date',
  141. 'callback_method' => 'callback_datetime'
  142. );
  143. $this->field_map[] = array(
  144. 'from_tablename' => 'topics',
  145. 'from_fieldname' => 'topic_time',
  146. 'to_type' => 'topic',
  147. 'to_fieldname' => 'post_date_gmt',
  148. 'callback_method' => 'callback_datetime'
  149. );
  150. $this->field_map[] = array(
  151. 'from_tablename' => 'topics',
  152. 'from_fieldname' => 'topic_time',
  153. 'to_type' => 'topic',
  154. 'to_fieldname' => 'post_modified',
  155. 'callback_method' => 'callback_datetime'
  156. );
  157. $this->field_map[] = array(
  158. 'from_tablename' => 'topics',
  159. 'from_fieldname' => 'topic_time',
  160. 'to_type' => 'topic',
  161. 'to_fieldname' => 'post_modified_gmt',
  162. 'callback_method' => 'callback_datetime'
  163. );
  164. /** Tags Section ******************************************************/
  165. /*
  166. // Topic id.
  167. $this->field_map[] = array(
  168. 'from_tablename' => 'tagcontent',
  169. 'from_fieldname' => 'contentid',
  170. 'to_type' => 'tags',
  171. 'to_fieldname' => 'objectid',
  172. 'callback_method' => 'callback_topicid'
  173. );
  174. // Tags text.
  175. $this->field_map[] = array(
  176. 'from_tablename' => 'tag',
  177. 'from_fieldname' => 'tagtext',
  178. 'join_tablename' => 'tagcontent',
  179. 'join_type' => 'INNER',
  180. 'join_expression' => 'USING (tagid)',
  181. 'to_type' => 'tags',
  182. 'to_fieldname' => 'name'
  183. );
  184. */
  185. /** Post Section ******************************************************/
  186. // Post id. Stores in postmeta.
  187. $this->field_map[] = array(
  188. 'from_tablename' => 'posts',
  189. 'from_fieldname' => 'post_id',
  190. 'to_type' => 'reply',
  191. 'to_fieldname' => '_bbp_post_id'
  192. );
  193. // Topic content.
  194. $this->field_map[] = array(
  195. 'from_tablename' => 'topics',
  196. 'from_fieldname' => 'topic_id',
  197. 'join_tablename' => 'posts',
  198. 'join_type' => 'LEFT',
  199. 'join_expression' => 'USING (topic_id) WHERE posts.post_id != topics.topic_first_post_id',
  200. 'to_type' => 'reply'
  201. );
  202. // Forum id. Stores in postmeta.
  203. $this->field_map[] = array(
  204. 'from_tablename' => 'posts',
  205. 'from_fieldname' => 'forum_id',
  206. 'to_type' => 'reply',
  207. 'to_fieldname' => '_bbp_forum_id',
  208. 'callback_method' => 'callback_topicid_to_forumid'
  209. );
  210. // Topic id. Stores in postmeta.
  211. $this->field_map[] = array(
  212. 'from_tablename' => 'posts',
  213. 'from_fieldname' => 'topic_id',
  214. 'to_type' => 'reply',
  215. 'to_fieldname' => '_bbp_topic_id',
  216. 'callback_method' => 'callback_topicid'
  217. );
  218. // Author ip.
  219. $this->field_map[] = array(
  220. 'from_tablename' => 'posts',
  221. 'from_fieldname' => 'poster_ip',
  222. 'to_type' => 'reply',
  223. 'to_fieldname' => '_bbp_author_ip'
  224. );
  225. // Post author.
  226. $this->field_map[] = array(
  227. 'from_tablename' => 'posts',
  228. 'from_fieldname' => 'poster_id',
  229. 'to_type' => 'reply',
  230. 'to_fieldname' => 'post_author',
  231. 'callback_method' => 'callback_userid'
  232. );
  233. // Topic title.
  234. $this->field_map[] = array(
  235. 'from_tablename' => 'posts',
  236. 'from_fieldname' => 'post_subject',
  237. 'to_type' => 'reply',
  238. 'to_fieldname' => 'post_title'
  239. );
  240. // Topic slug. Clean name.
  241. $this->field_map[] = array(
  242. 'from_tablename' => 'posts',
  243. 'from_fieldname' => 'post_subject',
  244. 'to_type' => 'reply',
  245. 'to_fieldname' => 'post_name',
  246. 'callback_method' => 'callback_slug'
  247. );
  248. // Post content.
  249. $this->field_map[] = array(
  250. 'from_tablename' => 'posts',
  251. 'from_fieldname' => 'post_text',
  252. 'to_type' => 'reply',
  253. 'to_fieldname' => 'post_content',
  254. 'callback_method' => 'callback_html'
  255. );
  256. // Topic id. If no parent, than 0.
  257. $this->field_map[] = array(
  258. 'from_tablename' => 'posts',
  259. 'from_fieldname' => 'topic_id',
  260. 'to_type' => 'reply',
  261. 'to_fieldname' => 'post_parent',
  262. 'callback_method' => 'callback_topicid'
  263. );
  264. // Topic date update.
  265. $this->field_map[] = array(
  266. 'from_tablename' => 'posts',
  267. 'from_fieldname' => 'post_time',
  268. 'to_type' => 'reply',
  269. 'to_fieldname' => 'post_date',
  270. 'callback_method' => 'callback_datetime'
  271. );
  272. $this->field_map[] = array(
  273. 'from_tablename' => 'posts',
  274. 'from_fieldname' => 'post_time',
  275. 'to_type' => 'reply',
  276. 'to_fieldname' => 'post_date_gmt',
  277. 'callback_method' => 'callback_datetime'
  278. );
  279. $this->field_map[] = array(
  280. 'from_tablename' => 'posts',
  281. 'from_fieldname' => 'post_time',
  282. 'to_type' => 'reply',
  283. 'to_fieldname' => 'post_modified',
  284. 'callback_method' => 'callback_datetime'
  285. );
  286. $this->field_map[] = array(
  287. 'from_tablename' => 'posts',
  288. 'from_fieldname' => 'post_time',
  289. 'to_type' => 'reply',
  290. 'to_fieldname' => 'post_modified_gmt',
  291. 'callback_method' => 'callback_datetime'
  292. );
  293. /** User Section ******************************************************/
  294. // Store old User id. Stores in usermeta.
  295. $this->field_map[] = array(
  296. 'from_tablename' => 'users',
  297. 'from_fieldname' => 'user_id',
  298. 'to_type' => 'user',
  299. 'to_fieldname' => '_bbp_user_id'
  300. );
  301. // Store old User password. Stores in usermeta serialized with salt.
  302. $this->field_map[] = array(
  303. 'from_tablename' => 'users',
  304. 'from_fieldname' => 'user_password',
  305. 'to_type' => 'user',
  306. 'to_fieldname' => '_bbp_password',
  307. 'callback_method' => 'callback_savepass'
  308. );
  309. // Store old User Salt. This is only used for the SELECT row info for the above password save
  310. $this->field_map[] = array(
  311. 'from_tablename' => 'users',
  312. 'from_fieldname' => 'user_form_salt',
  313. 'to_type' => 'user',
  314. 'to_fieldname' => ''
  315. );
  316. // User password verify class. Stores in usermeta for verifying password.
  317. $this->field_map[] = array(
  318. 'to_type' => 'user',
  319. 'to_fieldname' => '_bbp_class',
  320. 'default' => 'phpBB'
  321. );
  322. // User name.
  323. $this->field_map[] = array(
  324. 'from_tablename' => 'users',
  325. 'from_fieldname' => 'username',
  326. 'to_type' => 'user',
  327. 'to_fieldname' => 'user_login'
  328. );
  329. // User email.
  330. $this->field_map[] = array(
  331. 'from_tablename' => 'users',
  332. 'from_fieldname' => 'user_email',
  333. 'to_type' => 'user',
  334. 'to_fieldname' => 'user_email'
  335. );
  336. // User homepage.
  337. $this->field_map[] = array(
  338. 'from_tablename' => 'users',
  339. 'from_fieldname' => 'user_website',
  340. 'to_type' => 'user',
  341. 'to_fieldname' => 'user_url'
  342. );
  343. // User registered.
  344. $this->field_map[] = array(
  345. 'from_tablename' => 'users',
  346. 'from_fieldname' => 'user_regdate',
  347. 'to_type' => 'user',
  348. 'to_fieldname' => 'user_registered',
  349. 'callback_method' => 'callback_datetime'
  350. );
  351. // User aim.
  352. $this->field_map[] = array(
  353. 'from_tablename' => 'users',
  354. 'from_fieldname' => 'user_aim',
  355. 'to_type' => 'user',
  356. 'to_fieldname' => 'aim'
  357. );
  358. // User yahoo.
  359. $this->field_map[] = array(
  360. 'from_tablename' => 'users',
  361. 'from_fieldname' => 'user_yim',
  362. 'to_type' => 'user',
  363. 'to_fieldname' => 'yim'
  364. );
  365. }
  366. /**
  367. * This method allows us to indicates what is or is not converted for each
  368. * converter.
  369. */
  370. public function info() {
  371. return '';
  372. }
  373. /**
  374. * This method is to save the salt and password together. That
  375. * way when it is authenticate it we can get it out of the database
  376. * as one value.
  377. */
  378. public function callback_savepass( $field, $row ) {
  379. $pass_array = array('hash' => $field, 'salt' => $row['salt']);
  380. return $pass_array;
  381. }
  382. /**
  383. * Check for correct password
  384. *
  385. * @param string $password The password in plain text
  386. * @param string $hash The stored password hash
  387. *
  388. * @return bool Returns true if the password is correct, false if not.
  389. */
  390. public function authenticate_pass($password, $serialized_pass) {
  391. $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  392. $pass_array = unserialize($serialized_pass);
  393. if (strlen($pass_array['hash']) == 34) {
  394. return ($this->_hash_crypt_private($password, $pass_array['hash'], $itoa64) === $pass_array['hash']) ? true : false;
  395. }
  396. return (md5($password) === $pass_array['hash']) ? true : false;
  397. }
  398. /**
  399. * The crypt function/replacement
  400. */
  401. private function _hash_crypt_private($password, $setting, &$itoa64) {
  402. $output = '*';
  403. // Check for correct hash
  404. if (substr($setting, 0, 3) != '$H$') {
  405. return $output;
  406. }
  407. $count_log2 = strpos($itoa64, $setting[3]);
  408. if ($count_log2 < 7 || $count_log2 > 30) {
  409. return $output;
  410. }
  411. $count = 1 << $count_log2;
  412. $salt = substr($setting, 4, 8);
  413. if (strlen($salt) != 8) {
  414. return $output;
  415. }
  416. /**
  417. * We're kind of forced to use MD5 here since it's the only
  418. * cryptographic primitive available in all versions of PHP
  419. * currently in use. To implement our own low-level crypto
  420. * in PHP would result in much worse performance and
  421. * consequently in lower iteration counts and hashes that are
  422. * quicker to crack (by non-PHP code).
  423. */
  424. if (floatval(phpversion()) >= 5) {
  425. $hash = md5($salt . $password, true);
  426. do
  427. {
  428. $hash = md5($hash . $password, true);
  429. }
  430. while (--$count);
  431. } else {
  432. $hash = pack('H*', md5($salt . $password));
  433. do {
  434. $hash = pack('H*', md5($hash . $password));
  435. }
  436. while (--$count);
  437. }
  438. $output = substr($setting, 0, 12);
  439. $output .= $this->_hash_encode64($hash, 16, $itoa64);
  440. return $output;
  441. }
  442. /**
  443. * Encode hash
  444. */
  445. private function _hash_encode64($input, $count, &$itoa64) {
  446. $output = '';
  447. $i = 0;
  448. do {
  449. $value = ord($input[$i++]);
  450. $output .= $itoa64[$value & 0x3f];
  451. if ($i < $count) {
  452. $value |= ord($input[$i]) << 8;
  453. }
  454. $output .= $itoa64[($value >> 6) & 0x3f];
  455. if ($i++ >= $count) {
  456. break;
  457. }
  458. if ($i < $count) {
  459. $value |= ord($input[$i]) << 16;
  460. }
  461. $output .= $itoa64[($value >> 12) & 0x3f];
  462. if ($i++ >= $count) {
  463. break;
  464. }
  465. $output .= $itoa64[($value >> 18) & 0x3f];
  466. }
  467. while ($i < $count);
  468. return $output;
  469. }
  470. }