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