/[drupal]/contributions/modules/phpbb2drupal/phpbb2drupal.module
ViewVC logotype

Contents of /contributions/modules/phpbb2drupal/phpbb2drupal.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.107 - (show annotations) (download) (as text)
Sat Oct 3 18:02:13 2009 UTC (7 weeks, 5 days ago) by nbz
Branch: MAIN
CVS Tags: DRUPAL-6--2-1, HEAD
Changes since 1.106: +12 -8 lines
File MIME type: text/x-php
#594876 - Various bugs reported and solutions provided by Phliplip (http://drupal.org/user/566088) : Allow for support for signatures for forums module and also fix bugs in the attachments code.
1 <?php
2 // ; $Id: phpbb2drupal.module,v 1.106 2009/10/03 17:35:02 nbz Exp $
3
4 /**
5 * Implementation of hook_menu()
6 */
7 function phpbb2drupal_menu() {
8 $items = array();
9
10 $items['admin/phpbb2drupal'] = array(
11 'title' => 'phpBB to Drupal',
12 'access callback' => 'user_access',
13 'access arguments' => array('migrate phpBB'),
14 'page callback' => 'phpbb2drupal_main',
15 'file' => 'phpbb2drupal.pages.inc',
16 'type' => MENU_NORMAL_ITEM,
17 );
18 $items['admin/phpbb2drupal/postconfiguration'] = array(
19 'title' => 'Post Migration Configuration',
20 'access callback' => 'user_access',
21 'access arguments' => array('migrate phpBB'),
22 'page callback' => 'phpbb2drupal_postconfiguration',
23 'file' => 'phpbb2drupal.pages.inc',
24 'type' => MENU_NORMAL_ITEM,
25 );
26 $items['admin/phpbb2drupal/cleanup'] = array(
27 'title' => 'Cleanup',
28 'access callback' => 'user_access',
29 'access arguments' => array('migrate phpBB'),
30 'page callback' => 'phpbb2drupal_cleanup',
31 'type' => MENU_CALLBACK,
32 );
33 $items['admin/phpbb2drupal/migrate'] = array(
34 'title' => 'Execute Migration',
35 'access callback' => 'user_access',
36 'access arguments' => array('migrate phpBB'),
37 'page callback' => 'phpbb2drupal_migrate',
38 'type' => MENU_CALLBACK,
39 );
40 $items['admin/phpbb2drupal/reset'] = array(
41 'title' => 'Reset phpBB2 database URL',
42 'access callback' => 'user_access',
43 'access arguments' => array('migrate phpBB'),
44 'page callback' => 'phpbb2drupal_reset',
45 'type' => MENU_CALLBACK,
46 );
47 $items['admin/settings/phpbb2drupal'] = array(
48 'title' => 'phpBB2Drupal Settings',
49 'access callback' => 'user_access',
50 'access arguments' => array('migrate phpBB'),
51 'page callback' => 'drupal_get_form',
52 'page arguments' => array('phpbb2drupal_admin_settings'),
53 'file' => 'phpbb2drupal.pages.inc',
54 );
55 return $items;
56 }
57
58 /**
59 * Implementation of hook_perm()
60 */
61 function phpbb2drupal_perm() {
62 return array('migrate phpBB');
63 }
64
65 /**
66 * Callback admin/phpbb2drupal/reset
67 */
68 function phpbb2drupal_reset() {
69 global $db_url;
70 variable_set('phpbb2drupal_db_url', $db_url);
71 variable_set('phpbb2drupal_ready', 0);
72 return '<p>'. t('The phpBB2 database URL has been reset. You may now <a href="@configlink">go back to the configuration page</a>.',
73 array('@configlink' => url('admin/settings/phpbb2drupal'))) .'</p>';
74 }
75
76 /**
77 * Callback admin/phpbb2drupal/cleanup
78 */
79 function phpbb2drupal_cleanup() {
80 return phpbb2drupal_import_cleanup() .'<p>'. t('Drupal database cleaned.') .'</p>';
81 }
82
83 /**
84 * Set database connection for phpBB
85 *
86 * @return
87 * 1 if can connect to phpbb database.
88 *
89 * BEWARE: if you test using db_connect and the connection
90 * fails, the process will die() which is a bit too much since we only
91 * want to test. Therefore, the test part of the code is not used, now.
92 */
93 function _phpbb2drupal_db_connect($test= 0) {
94 global $db_url;
95 $same = variable_get('phpbb2drupal_same_db', 1);
96 if (!$same) {
97 $db_url2['phpbb'] = variable_get('phpbb2drupal_db_url', $db_url);
98 $db_url2['default'] = $db_url;
99 $GLOBALS['db_url'] =& $db_url2;
100 if ($test) {
101 if (!db_connect($db_url2['phpbb'])) {
102 return 0;
103 }
104 }
105 }
106 return 1;
107
108 }
109
110 /**
111 * Check if the module is enabled.
112 *
113 * @return array
114 * $out['html'] = formatted html.
115 * $out['result'] = boolean.
116 */
117 function _phpbb2drupal_check_module($module) {
118 $out['html'] = '<ul>';
119 $result = module_exists($module);
120 $out['result'] = $result;
121 if ($result == 1) {
122 $out['html'] .= '<li>'. t('Module %module is enabled. OK!', array('%module' => $module)) .'</li>';
123 }
124 else {
125 $out['html'] .= '<li><span class="marker">'. t('Module %module is disabled.', array('%module' => $module)) .'</span></li>';
126 }
127 $out['html'] .= '</ul>';
128 return $out;
129 }
130
131 /**
132 * Check if the sql tables are installed.
133 *
134 * @return array
135 * $out['html'] = formatted html.
136 * $out['result'] = boolean.
137 */
138 function _phpbb2drupal_check_tables( $tables = array(), $db = 'default' , $prefix = 1) {
139 _phpbb2drupal_db_connect();
140
141 $out['html'] = '<ul>';
142 $out['result']= 1;
143 foreach ($tables as $table) {
144 if ($prefix) {
145 $table = db_prefix_tables('{'. $table .'}');
146 }
147
148 db_set_active($db);
149 if ($GLOBALS['db_type'] == 'pgsql') {
150 // adapt from db_table_exists in database.pgsql.inc
151 $result = (bool) db_result(db_query("SELECT COUNT(*) FROM pg_class WHERE relname = '%s'", $table));
152 }
153 else {
154 // adapt from db_table_exists in database.mysql.inc
155 $result = (bool) db_fetch_object(db_query("SHOW TABLES LIKE '%s'", $table));
156 }
157 db_set_active('default');
158 if ($result) {
159 $out['html'] .= '<li>'. t('Table %table: OK!', array('%table' => $table)) .'</li>';
160 }
161 else {
162 $out['html'] .= '<li><span class="marker">'. t('Table <strong>%table</strong> does not exist!', array('%table' => $table)) .'</span></li>';
163 $out['result']= 0;
164 }
165 }
166 $out['html'] .= '</ul>';
167 return $out;
168 }
169
170
171
172 function phpbb2drupal_migrate() {
173 if (!variable_get('phpbb2drupal_ready', 0)) {
174 return '<p>'. t('You cannot migrate the data now. Please <a href="@settings">complete the setup first</a>', array('@settings' => url('admin/settings/phpbb2drupal'))) .'</p>';
175 }
176
177 $output = 'Phpbb 2 Drupal Migration Form';
178 $output .= drupal_get_form('phpbb2drupal_migrate_form');
179 return $output;
180 }
181
182 function phpbb2drupal_migrate_form() {
183 _phpbb2drupal_db_connect() ;
184 // Causes problems with form api redirect
185 //ini_set('display_errors', TRUE);
186
187 // Adjust how long you want the script to run...
188 if (!ini_get('safe_mode')) {
189 set_time_limit(variable_get('phpbb2drupal_time_limit', 0));
190 }
191
192 $PHPBB2DRUPAL_FUNCTIONS = array(
193 'users' => t('Import Users'),
194 'categories' => t('Import Categories'),
195 'topics' => t('Import Topics'),
196 'posts' => t('Import Posts'),
197 'url' => t('Transform URLs'),
198 );
199
200 $form['import'] = array(
201 '#type' => 'select',
202 '#title' => t('Next import to perform'),
203 '#default_value' => $_SESSION['phpbb2drupal_selected'],
204 '#options' => $PHPBB2DRUPAL_FUNCTIONS,
205 );
206 $form[] = array(
207 '#type' => 'submit',
208 '#value' => t('Import'),
209 );
210 return $form;
211 }
212
213 function phpbb2drupal_migrate_form_submit($form, $form_state) {
214
215 switch ($form_state['values']['import']) {
216 case 'users':
217 phpbb2drupal_import_users();
218 if (!variable_get('phpbb2drupal_import_user_successful', 0)) {
219 $_SESSION['phpbb2drupal_selected'] = 'users';
220 }
221 else {
222 $_SESSION['phpbb2drupal_selected'] = 'categories';
223 }
224 break;
225
226 case 'categories':
227 phpbb2drupal_import_categories();
228 if (!variable_get('phpbb2drupal_import_category_successful', 0)) {
229 $_SESSION['phpbb2drupal_selected'] = 'categories';
230 }
231 else {
232 $_SESSION['phpbb2drupal_selected'] = 'topics';
233 }
234 break;
235
236 case 'topics':
237 phpbb2drupal_import_topics();
238 if (!variable_get('phpbb2drupal_import_topic_successful', 0)) {
239 $_SESSION['phpbb2drupal_selected'] = 'topics';
240 }
241 else {
242 $_SESSION['phpbb2drupal_selected'] = 'posts';
243 }
244 break;
245
246 case 'posts':
247 phpbb2drupal_import_posts();
248 if (!variable_get('phpbb2drupal_import_post_successful', 0)) {
249 $_SESSION['phpbb2drupal_selected'] = 'posts';
250 }
251 else {
252 $_SESSION['phpbb2drupal_selected'] = 'url';
253 }
254 break;
255
256 case 'url':
257 phpbb2drupal_replace_url();
258 if (!variable_get('phpbb2drupal_replace_url_successful', 0)) {
259 $_SESSION['phpbb2drupal_selected'] = 'url';
260 }
261 else {
262 drupal_set_message('Congratulations. Import Finished');
263 drupal_set_message('Please visit the '. l('Post migration configuration', 'admin/phpbb2drupal/postconfiguration') .' page');
264 unset($_SESSION['phpbb2drupal_selected']);
265 }
266 break;
267 default:
268 $_SESSION['phpbb2drupal_selected'] = 'users';
269 break;
270 }
271 }
272
273 /**
274 * User Import Functions
275 */
276 function phpbb2drupal_import_users() {
277 $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
278 // check if the user database has been successfully imported
279 db_set_active('default');
280 if (variable_get('phpbb2drupal_import_user_successful', 0)) {
281 drupal_set_message(t('Users already imported successfully'));
282 return;
283 }
284
285 if (variable_get('phpbb2drupal_import_user_started', 0) == 0) {
286 // create temporary tables
287 db_set_active('default');
288
289 // create profile fields for icq, aim, msn...etc
290 $querybase = 'INSERT INTO {profile_fields} (title, name, explanation, category, page, type, weight, required, register, visibility, options) VALUES ';
291
292 $query = $querybase ."('YIM', 'user_yim', '', 'Contact', '', 'textfield', 0, 0, 1, 2, '')";
293 db_query($query);
294
295 $query = $querybase ."('AIM', 'user_aim', '', 'Contact', '', 'textfield', 0, 0, 1, 2, '')";
296 db_query($query);
297
298 $query = $querybase ."('icq', 'user_icq', '', 'Contact', '', 'textfield', 0, 0, 1, 2, '')";
299 db_query($query);
300
301 $query = $querybase ."('Website', 'user_website', '', 'Contact', '', 'url', 0, 0, 1, 2, '')";
302 db_query($query);
303
304 $query = $querybase ."('Location', 'user_from', '', 'Personal', '', 'textfield', 0, 0, 1, 2, '')";
305 db_query($query);
306
307 $query = $querybase ."('Occupation', 'user_occ', '', 'Personal', '', 'textfield', 0, 0, 1, 2, '')";
308 db_query($query);
309
310 $query = $querybase ."('Interests', 'user_interests', '', 'Personal', '', 'textfield', 0, 0, 1, 2, '')";
311 db_query($query);
312
313 variable_set('phpbb2drupal_import_user_started', 1);
314 }
315
316 db_set_active('default');
317 $drupal_admin = user_load(array('name' => variable_get('phpbb2drupal_admin_user', '')));
318 db_query('INSERT INTO {phpbb2drupal_temp_user} (user_id, uid) VALUES (2 , %d)', $drupal_admin->uid);
319
320 $files_path = variable_get('file_directory_path', 'files');
321 $pictures_path = variable_get('user_picture_path', 'pictures');
322
323 // Insert the users into drupal
324 db_set_active('phpbb');
325 $user_ids = db_query('SELECT user_id FROM %susers WHERE ( user_id > 2 AND user_type <> 2) ORDER BY user_id', $pre);
326
327 $user_count = db_result(db_query('SELECT COUNT(*) FROM %susers WHERE user_id > 2', $pre));
328
329 if (!$user_count) {
330 drupal_set_message(t('There were no users found: Aborting script'), 'error');
331 return t('There were no users found: Aborting script.');
332 }
333
334 drupal_set_message(t('Found %user_count users: Beginning Import', array('%user_count' => $user_count + 1)));
335
336 $import_spammers = variable_get('phpbb2drupal_import_spammers', 1);
337
338 while ($result = db_fetch_object($user_ids)) {
339
340 db_set_active('phpbb');
341 $user = db_fetch_object(db_query('SELECT * FROM %susers WHERE user_id = %d', $pre, $result->user_id));
342
343 // If we don't want to import users who have never posted, break this while loop here.
344 if ($import_spammers == 1 || $user->user_posts != 0 ) {
345
346 // Make sure the user is has not already been imported
347 db_set_active('default');
348 $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $user->user_id));
349 if ($count > 0) {
350 $user->user_active = 0;
351 }
352
353 $user->user_aim = strtr($user->user_aim, array('+' => ' ')); # PHPBB stores spaces as +, replace with ' '
354 $user->user_yim = strtr($user->user_yim, array('+' => ' '));
355 $user->user_timezone = $user->user_timezone * 60 * 60; # Drupal stores timezones in seconds
356
357 // if the $user->user_avatar_type is not their own image, delete it
358 // drupal doesn't have pre-defined avatars. if we were to import it
359 // then multiple people would share the same avatar image and if one user
360 // were to changes their avatar then it would change it for everybody else.
361 if ($user->user_avatar_type > 1) {
362 $user->user_avatar = '';
363 }
364
365 $user->user_avatar = ($user->user_avatar) ? "$files_path/$pictures_path/$user->user_avatar" : '';
366
367 // remove the :bbcode_uid from signature
368 if(!empty($user->user_sig_bbcode_uid)) {
369 $user->user_sig = preg_replace("/:$user->user_sig_bbcode_uid/", '', $user->user_sig);
370 }
371 $signature = _phpbb2drupal_strip_bbcode($user->user_sig);
372 $signature = _phpbb2drupal_text_sanitise($signature);
373
374 // Signatures for Forums module supports longer values than default 255 chars
375 // http://drupal.org/project/signature_forum0
376 if(!module_exists('signature_forum')) {
377 $signature = substr($signature, 0, 255);
378 }
379
380 if (variable_get('phpbb2drupal_regdate_us_english', 0)) {
381 $user_regdate = strtotime($user->user_regdate);
382 $user_lastvisit = strtotime($user->user_lastvisit);
383 $user_session_time = strtotime($user->user_session_time);
384 }
385 else {
386 $user_regdate = $user->user_regdate;
387 $user_lastvisit = $user->user_lastvisit;
388 $user_session_time = $user->user_session_time;
389 }
390
391 //phpbb3 stores user status in user_type instead of user_active as phpbb2 did. inactive users get an id of 1. there are other status too, no idea what they mean.
392 //KISS - user_type of 1 = inactive. The rest mean active.
393 //further complication - duplicate check sets $user->user_active to 0 if the user is a duplicate.
394 //Assume the only time the $user->user_active is set before now is in duplicate check and nothing is taken from database - so php isset() should work.
395 if ($user->user_type <> 1 && !(isset($user->user_active))) {
396 $user->user_active = 1;
397 }
398
399 $data = array(
400 'name' => substr($user->username, 0, 60),
401 'pass' => $user->user_password,
402 'mail' => substr($user->user_email, 0, 64),
403 'signature' => $signature,
404 'created' => $user_regdate,
405 //'access' => $user_session_time,
406 // It seems that last login time is more accurate for the last access data...
407 'access' => $user_lastvisit,
408 'login' => $user_lastvisit,
409 'status' => $user->user_active,
410 'timezone' => $user->user_timezone,
411 'picture' => $user->user_avatar,
412 'init' => substr($user->user_email, 0, 64),
413 'roles' => array(0 => 2), # Authenticated User
414 'user_website' => $user->user_website,
415 'user_from' => $user->user_from,
416 'user_icq' => $user->user_icq,
417 'user_aim' => $user->user_aim,
418 'user_yim' => $user->user_yim,
419 'user_msnm' => $user->user_msnm,
420 'user_occ' => $user->user_occ,
421 'user_interests' => $user->user_interest
422 );
423 if (variable_get('phpbb2drupal_import_pm', 0)) {
424 $data['privatemsg_allow'] = 1;
425 }
426
427 $data['interests'] = _phpbb2drupal_text_sanitise($data['interests']);
428
429 db_set_active('default');
430 $drupal_user = phpbb2drupal_user_save($data, array('account', 'Personal', 'Contact'));
431
432 // populate the temporary user table
433 db_set_active('default');
434 db_query('INSERT INTO {phpbb2drupal_temp_user} (user_id, uid) VALUES ( %d, %d )', $user->user_id , $drupal_user->uid);
435
436 db_set_active('phpbb');
437 }
438 }
439
440 // set the user import successful flag in the variable table
441 db_set_active('default');
442 variable_set('phpbb2drupal_import_user_successful', '1');
443
444 $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_user}'));
445 drupal_set_message(t('Successfully Imported %count Users', array('%count' => $count)));
446 }
447
448 /**
449 * Create Forum Containers and Forums
450 */
451 function phpbb2drupal_import_categories() {
452 $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
453
454 // check if the forum database has been successfully imported
455 db_set_active('default');
456 if (variable_get('phpbb2drupal_import_category_successful', 0)) {
457 drupal_set_message(t('Categories already imported successfully'));
458 return;
459 }
460
461 // Retrieve the vocabulary vid named "Forum".
462 $forum_vid = variable_get('forum_nav_vocabulary', 0);
463
464 drupal_set_message(t('Forum vid: %forum_vid', array('%forum_vid' => $forum_vid)));
465
466 // Get Categories/Forums from PHPBB
467 db_set_active('phpbb');
468
469 $results = db_query('SELECT * FROM %sforums WHERE forum_type <> 2 ORDER BY parent_id', $pre);
470 while ($result = db_fetch_object($results)) {
471 db_set_active('default');
472 if (!db_result(db_query('SELECT forum_id FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $result->forum_id))) {
473 if ($result->parent_id > 0) {
474 $result->parent_id = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $result->parent_id));
475 }
476 $forum = array(
477 'name' => $result->forum_name,
478 'vid' => $forum_vid,
479 'description' => $result->forum_desc,
480 'parent' => $result->parent_id,
481 );
482 $forum['name'] = _phpbb2drupal_text_sanitise($forum['name']);
483 $forum['description'] = _phpbb2drupal_text_sanitise($forum['description']);
484
485 taxonomy_save_term($forum);
486
487 // serialize the forum containers
488 if ($result->forum_type == 0) {
489 //This is a category
490 $containers = variable_get('forum_containers', array());
491 $containers[] = $forum['tid'];
492 variable_set('forum_containers', $containers);
493 }
494 //save the container to the forum table - yes this is hackish.
495 db_query('INSERT INTO {phpbb2drupal_temp_forum} (forum_id, tid) VALUES (%d, %d)', $result->forum_id, $forum['tid']);
496 }
497 db_set_active('phpbb');
498 }
499 db_set_active('default');
500 // set the forums import successful flag in the variable table
501 variable_set('phpbb2drupal_import_category_successful', '1');
502
503 $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_forum}'));
504 drupal_set_message(t('Successfully Imported %count forums and containers.', array('%count' => $count)));
505 }
506
507 /**
508 * Imports PHPBB topics to Drupal equivalent forum nodes
509 */
510 function phpbb2drupal_import_topics() {
511 $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
512 $PHPBB2DRUPAL_IMPORT_ATTACHMENTS = variable_get('phpbb2drupal_import_attachments', 0);
513 $input_format = variable_get('phpbb2drupal_input_format', 0);
514
515 // check if the post database has been successfully imported
516 db_set_active('default');
517 if (variable_get('phpbb2drupal_import_topic_successful', 0)) {
518 drupal_set_message(t('Topics already imported successfully'));
519 return;
520 }
521
522 // Get All topics from PHPBB
523 db_set_active('phpbb');
524 // topic_status == 2, Moved topics are duplicates don't import
525 $topic_ids = db_query('SELECT topic_id FROM %stopics ORDER BY topic_id', $pre);
526 $topic_count = db_result(db_query('SELECT COUNT(*) FROM %stopics', $pre));
527 drupal_set_message(t('Found %topic_count topics: Beginning Import', array('%topic_count' => $topic_count)));
528
529 // Import the topics into drupal
530 $counter = 0;
531 db_set_active('phpbb');
532 while ($result = db_fetch_object($topic_ids)) {
533
534 // check if this topic has been imported already just to be sure
535 db_set_active('default');
536 $count = db_result(db_query('SELECT count(*) FROM {phpbb2drupal_temp_topic} WHERE topic_id = %d', $result->topic_id));
537 if ($count > 0) {
538 db_set_active('phpbb');
539 continue;
540 }
541
542 db_set_active('phpbb');
543
544 $query = db_query('SELECT *
545 FROM %stopics t
546 INNER JOIN %sposts p ON t.topic_id = p.topic_id WHERE p.post_id = t.topic_first_post_id
547 AND t.topic_id = %d',$pre, $pre, $result->topic_id);
548
549 $querycount = db_query('SELECT COUNT(*)
550 FROM %stopics t
551 INNER JOIN %sposts p ON t.topic_id = p.topic_id WHERE p.post_id = t.topic_first_post_id
552 AND t.topic_id = %d',$pre, $pre, $result->topic_id);
553
554
555 // check if the topic is a valid topic. if not, continue on
556 if (db_result($querycount)) {
557 $topic = db_fetch_object($query);
558 }
559 else {
560 drupal_set_message(t('Could not find post details of topic: %topic_id', array('%topic_id' => $result->topic_id)));
561 continue;
562 }
563
564 db_set_active('default');
565 $uid = db_result(db_query('SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $topic->topic_poster));
566 $tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $topic->forum_id));
567
568 if ($topic->topic_poster == 2) { // is the admin
569 $user = user_load(array('name' => variable_get('phpbb2drupal_admin_user', '')));
570 $uid = $user->uid;
571 }
572 else if ($topic->topic_poster == -1) {
573 $uid = 0;
574 }
575
576 if ($topic->topic_type == 1) {
577 $sticky = 1; // sticky
578 $promote = 0;
579 }
580 else if ($topic->topic_type == 2) {
581 $sticky = 1;
582 $promote = 0; // display on the front page, i.e. promote
583 }
584 else {
585 $sticky = 0;
586 $promote = 0;
587 }
588
589 if ($topic->topic_status == 1) { // LOCKED
590 $comment = 1; // read-only
591 }
592 else { // UNLOCKED & WATCH NOTIFIED
593 $comment = 2; // read-write
594 }
595
596 // remove the bbcode_uid from post_text
597 if(!empty($topic->bbcode_uid)) {
598 $topic->post_text = preg_replace("/:$topic->bbcode_uid/", '', $topic->post_text);
599 }
600 $topic->post_text = _phpbb2drupal_strip_bbcode($topic->post_text);
601 $topic->post_text = _phpbb2drupal_text_sanitise($topic->post_text);
602
603 $teaser = node_teaser($topic->post_text);
604
605 if ($topic->post_edit_time < $topic->topic_time) {
606 $topic->post_edit_time = $topic->topic_time;
607 }
608
609 //construct the node
610 $node = array(
611 'type' => 'forum',
612 'title' => $topic->topic_title,
613 'uid' => $uid,
614 'status' => 1, // published or not - always publish
615 'promote' => $promote,
616 'created' => $topic->topic_time,
617 'changed' => $topic->post_edit_time,
618 'comment' => $comment,
619 'moderate' => 0,
620 'body' => $topic->post_text,
621 'sticky' => $sticky,
622 'format' => $input_format,
623 'teaser' => $teaser,
624 );
625 $node['title'] = _phpbb2drupal_text_sanitise($node['title']);
626
627 if ($topic->topic_status == 2) {
628 db_set_active('phpbb');
629 $forum_id = db_result(db_query('SELECT forum_id FROM %stopics WHERE topic_id = %d', $pre, $topic->topic_moved_id));
630 db_set_active('default');
631 $moved_tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $forum_id));
632
633 $node['tid'] = $moved_tid; // which forum it used to be part of
634 }
635 else {
636 $node['tid'] = $tid;
637 }
638
639 $node = (object)$node; // node_save requires an object form
640
641 db_set_active('default');
642 node_save($node);
643 taxonomy_node_save($node, array($tid));
644
645 if (!$node->nid) {
646 drupal_set_message(t('Failed importing %topic_id', array('%topic_id' => $topic->topic_id)));
647 }
648
649 // Handle attachments
650 if ($PHPBB2DRUPAL_IMPORT_ATTACHMENTS) {
651 if ($topic->topic_attachment == 1) {
652
653 db_set_active('default');
654 $file_path = variable_get('file_directory_path', 'files');
655
656 db_set_active('phpbb');
657 $files = db_query('SELECT * FROM %sattachments a WHERE a.post_msg_id = %d',
658 $pre, $topic->topic_first_post_id);
659
660 while ($file = db_fetch_object($files)) {
661 db_set_active('default');
662 db_query("INSERT INTO {files} (uid, filename, filepath, filemime, filesize, status, timestamp) VALUES (%d, '%s', '%s', '%s', %d, %d, %d)", $uid, substr($file->real_filename, 0, 255), substr("$file_path/$file->physical_filename", 0, 255), substr($file->mimetype, 0, 255), $file->filesize, 1, $file->filetime);
663 $fid = db_last_insert_id('files', 'fid');
664 db_query("INSERT INTO {upload} (fid, nid, vid, description, list, weight) VALUES (%d, %d, %d, '%s', %d, %d)", $fid, $node->nid, $node->nid, substr($file->real_filename, 0, 255), 1, $file->attach_id);
665 db_set_active('phpbb');
666 }
667 }
668 }
669
670 db_set_active('default');
671 db_query('INSERT INTO {phpbb2drupal_temp_topic} (topic_id, post_id, nid) VALUES (%d, %d, %d)', $topic->topic_id, $topic->post_id, $node->nid);
672
673 //hack to keep the topics in correct order
674 db_query('UPDATE {node_comment_statistics} SET last_comment_timestamp = %d WHERE nid = %d', $node->created, $node->nid);
675
676 db_set_active('phpbb');
677 }
678
679 db_set_active('default');
680 // set the topic import successful flag in the variable table
681 variable_set('phpbb2drupal_import_topic_successful', '1');
682
683 $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_topic}'));
684 drupal_set_message(t('Successfully Imported %count topics', array('%count' => $count)));
685 }
686
687 /**
688 * PHPBB Posts --> Drupal Comments
689 */
690 function phpbb2drupal_import_posts() {
691 $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
692 $PHPBB2DRUPAL_IMPORT_ATTACHMENTS = variable_get('phpbb2drupal_import_attachments', 0);
693 $input_format = variable_get('phpbb2drupal_input_format', 0);
694
695 db_set_active('default');
696 // check if the post database has been successfully imported
697 if (variable_get('phpbb2drupal_import_post_successful', 0)) {
698 drupal_set_message(t('Posts already imported successfully'));
699 return;
700 }
701
702 if (!variable_get('phpbb2drupal_import_post_started', 0)) {
703 db_set_active('default');
704 variable_set('phpbb2drupal_import_post_started', 1);
705 }
706
707 db_set_active('phpbb');
708
709 $topic_ids = db_query('SELECT topic_id, topic_first_post_id, topic_last_post_id
710 FROM %stopics
711 WHERE topic_replies > 0
712 ORDER BY topic_id', $pre);
713
714 $topic_count = db_result(db_query("SELECT COUNT(topic_id) FROM %stopics WHERE topic_replies > 0", $pre));
715 drupal_set_message(t('Found %post_count posts: Beginning Import', array('%post_count' => $topic_count)));
716
717 $errors = 0;
718 $loops = 0;
719 // Import the posts into drupal
720 while ($obj = db_fetch_object($topic_ids)) {
721 $loops++;
722
723 // skip first post if the post is not a poll
724 // stupid phpbb... make the way you store topics consistent for crying out loud
725 db_set_active('phpbb');
726 $post_ids = db_query('SELECT post_id FROM %sposts WHERE topic_id = %d AND post_id <> %d ORDER BY post_id',
727 $pre, $obj->topic_id, $obj->topic_first_post_id);
728
729 unset($obj);
730
731 while ($result = db_fetch_object($post_ids)) {
732 $loops++;
733
734 db_set_active('phpbb');
735 $query = db_query('SELECT * FROM %sposts WHERE post_id = %d', $pre, $result->post_id);
736 $querycount = db_query('SELECT COUNT(*) FROM %sposts WHERE post_id = %d', $pre, $result->post_id);
737
738 // make sure the post is valid
739 if (db_result($querycount)) {
740 $post = db_fetch_object($query);
741 }
742 else {
743 $errors++;
744 drupal_set_message(t("Couldn't find post text for %post_id", array('%post_id' => $result->post_id)));
745 continue;
746 }
747
748 // skip if the post has already been imported
749 db_set_active('default');
750 $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_post} WHERE post_id = %d', $post->post_id));
751 if ($count > 0) {
752 $errors++;
753 drupal_set_message(t('Post %post_id was already inserted', array('%post_id' => $post->post_id)));
754 db_set_active('phpbb');
755 continue;
756 }
757
758 db_set_active('default');
759 $uid = db_result(db_query('SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $post->poster_id));
760 $pid = db_result(db_query('SELECT MAX(pid) FROM {comments} WHERE nid = %d', $nid));
761 // get the node ID. The title may be useful further down if the comment doesn't have its own title.
762 $node = (db_fetch_object(db_query('SELECT n.nid, n.title FROM {phpbb2drupal_temp_topic} ptt LEFT JOIN {node_revisions} AS n ON ptt.nid = n.nid WHERE topic_id = %d', $post->topic_id)));
763 $nid = $node->nid;
764
765 $pid = (is_null($pid)) ? 0 : $pid;
766
767 if ($post->poster_id == 2) { // is the admin
768 $user = user_load(array('name' => variable_get('phpbb2drupal_admin_user', '')));
769 $uid = $user->uid;
770 }
771 else if ($post->poster_id == -1) { // anonymous
772 $uid = 0;
773 }
774
775 $hostname = phpbb2drupal_decode_ip($post->poster_ip);
776
777 // remove the :bbcode_uid from post_text
778 if(!empty($post->bbcode_uid)) {
779 $post->post_text = preg_replace("/:$post->bbcode_uid/", '', $post->post_text);
780 }
781 $post->post_text = _phpbb2drupal_strip_bbcode($post->post_text);
782 $post->post_text = _phpbb2drupal_text_sanitise($post->post_text);
783 $post->post_subject = _phpbb2drupal_text_sanitise($post->post_subject);
784
785 //construct the comment.
786 $comment = array(
787 'pid' => $pid,
788 'nid' => $nid,
789 'uid' => $uid,
790 'subject' => $post->post_subject,
791 'comment' => $post->post_text,
792 'hostname' => $hostname,
793 'timestamp' => $post->post_time,
794 'format' => $input_format
795 );
796
797 // if the title field is empty, use the node title as default.
798 if (empty($comment['subject'])) {
799 $comment['subject'] = $node->title;
800 }
801
802 db_set_active('default');
803 $cid = phpbb2drupal_comment_save($comment);
804
805 if (!$cid) {
806 $errors++;
807 drupal_set_message(t('Failed importing %post_id', array('%post_id' => $post->post_id)));
808 }
809
810 // Handle attachments
811 if ($PHPBB2DRUPAL_IMPORT_ATTACHMENTS) {
812 if ($post->post_attachment == 1) {
813 db_set_active('default');
814 $file_path = variable_get('file_directory_path', 'files');
815
816 db_set_active('phpbb');
817 $files = db_query('SELECT * FROM %sattachments a WHERE a.post_msg_id = %d',
818 $pre, $post->post_id);
819
820 while ($file = db_fetch_object($files)) {
821 db_set_active('default');
822 db_query("INSERT INTO {files} (uid, filename, filepath, filemime, filesize, status, timestamp) VALUES (%d, '%s', '%s', '%s', %d, %d, %d)", $uid, substr($file->real_filename, 0, 255), substr("$file_path/$file->physical_filename", 0, 255), substr($file->mimetype, 0, 255), $file->filesize, 1, $file->filetime);
823 $fid = db_last_insert_id('files', 'fid');
824 db_query("INSERT INTO {comment_upload} (fid, nid, cid, description, list, weight) VALUES (%d, %d, %d, '%s', %d, %d)", $fid, $nid, $cid, substr($file->real_filename, 0, 255), 1, $file->attach_id);
825 db_set_active('phpbb');
826 }
827 }
828 }
829
830 db_set_active('default');
831 db_query('INSERT INTO {phpbb2drupal_temp_post} (post_id, cid) VALUES (%d, %d)', $post->post_id, $cid);
832
833 db_set_active('phpbb');
834 }
835 }
836
837 // set the post import successful flag in the variable table
838 db_set_active('default');
839 variable_set('phpbb2drupal_import_post_successful', '1');
840 drupal_set_message(t('Successfully Imported %imported posts', array('%imported' => $imported)));
841 drupal_set_message(t('The were %loops loops executed', array('%loops' => $loops)));
842 drupal_set_message(t('There %errors errors while importing posts', array('%errors' => $errors)));
843 }
844
845 /**
846 * Clean UP
847 */
848 function phpbb2drupal_import_cleanup() {
849 $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
850
851 #
852 # Update Drupal sequence
853 #
854 db_set_active('default');
855 $term_data_tid = db_result(db_query('SELECT MAX(tid) FROM {term_data}'));
856 $comments_cid = db_result(db_query('SELECT MAX(cid) FROM {comments}'));
857 $node_nid = db_result(db_query('SELECT MAX(nid) FROM {node}'));
858 $users_uid = db_result(db_query('SELECT MAX(uid) FROM {users}'));
859
860 db_query("DELETE FROM {sequences} WHERE name='term_data_tid'");
861 db_query("DELETE FROM {sequences} WHERE name='comments_cid'");
862 db_query("DELETE FROM {sequences} WHERE name='node_nid'");
863 db_query("DELETE FROM {sequences} WHERE name='users_uid'");
864
865 db_query("INSERT INTO {sequences} (name,id) VALUES ('term_data_tid', '%s')", $term_data_tid);
866 db_query("INSERT INTO {sequences} (name,id) VALUES ('comments_cid', '%s')", $comments_cid);
867 db_query("INSERT INTO {sequences} (name,id) VALUES ('node_nid', '%s')", $node_nid);
868 db_query("INSERT INTO {sequences} (name,id) VALUES ('users_uid', '%s')", $users_uid);
869
870 if (variable_get('phpbb2drupal_import_attachments', 0)) {
871 $files_fid = db_result(db_query('SELECT MAX(fid) FROM {files}'));
872 if (!$files_fid) { //may be NULL
873 $files_fid = 0;
874 }
875 db_query("DELETE FROM {sequences} WHERE name='files_fid'");
876 db_query("INSERT INTO {sequences} (name,id) VALUES ('files_fid', '%s')", $files_fid);
877 }
878
879 variable_del('phpbb2drupal_import_user_successful');
880 variable_del('phpbb2drupal_import_user_started');
881 variable_del('phpbb2drupal_import_category_successful');
882 variable_del('phpbb2drupal_replace_url_successful');
883 variable_del('phpbb2drupal_import_category_started');
884 variable_del('phpbb2drupal_import_topic_successful');
885 variable_del('phpbb2drupal_import_topic_started');
886 variable_del('phpbb2drupal_import_post_successful');
887 variable_del('phpbb2drupal_import_post_started');
888 variable_del('phpbb2drupal_ready');
889 variable_del('phpbb2drupal_regdate_us_english');
890 variable_del('phpbb2drupal_input_format');
891 variable_del('phpbb2drupal_db_url');
892 variable_del('phpbb2drupal_tested');
893 variable_del('phpbb2drupal_same_db');
894 variable_del('phpbb2drupal_table_prefix');
895 variable_del('phpbb2drupal_time_limit');
896 variable_del('phpbb2drupal_import_spammers');
897 variable_del('phpbb2drupal_import_attachments');
898 variable_del('phpbb2drupal_import_polls');
899 variable_del('phpbb2drupal_import_poll_started');
900 variable_del('phpbb2drupal_import_poll_successful');
901 variable_del('phpbb2drupal_import_pm_successful');
902 variable_del('phpbb2drupal_admin_user');
903 variable_del('phpbb2drupal_encode');
904 variable_del('phpbb2drupal_encoding_phpbb');
905 variable_del('phpbb2drupal_encoding_drupal');
906 variable_del('phpbb2drupal_version');
907
908 db_query('DELETE FROM {cache}');
909 }
910
911 /**
912 * Helper Functions
913 */
914 function phpbb2drupal_user_save($phpbb_user, $category = array()) {
915
916 if (!($user = user_load(array('name' => $phpbb_user['name'])))) {
917 $account = new stdClass();
918 $account->uid = FALSE;
919 $user = user_save($account, $phpbb_user);
920 //Drupal overrides the phpBB user registration date when creating a Drupal account.
921 //so we need to update it here.
922 $user = user_save($user, array('created' => $phpbb_user['created']));
923
924 if ($phpbb_user['pass'] && strlen($phpbb_user['pass']) <> 32 && substr($phpbb_user['pass'], 0, 2) == '$H') {
925 // Update the password:import the phpass hash into Drupal phpass mopdule table after modifying the hash identifier - phpbb3 uses $H$ while phpass uses $P$ at the start of every phpass hash
926 // set the normal password as plain 'phpass'. This is needed for the phpass module as it uses the count of passwords as 'phpass' when calculatign wether or not to allow the module to be deactivated.
927 $hash = substr_replace($phpbb_user['pass'],'$P', 0, 2);
928 $result = db_query("UPDATE {users} SET pass = 'phpass' WHERE uid = %d", $user->uid);
929 $result = db_query("INSERT INTO {user_phpass} (hash, uid) VALUES ('%s', %d)", $hash, $user->uid);
930
931 }
932 elseif ($phpbb_user['pass']) {
933 //The password has NOT been converted from md5 to phpass yet
934 $result = db_query("UPDATE {users} SET pass = '%s' WHERE uid = %d", $phpbb_user['pass'], $user->uid);
935 }
936 }
937 $phpbb_user['uid'] = $user->uid;
938
939 db_set_active('default');
940 phpbb2drupal_profile_save_profile($phpbb_user, $user, $category); // add user profile information
941
942 return $user;
943 }
944
945 function phpbb2drupal_profile_save_profile(&$edit, &$user, $category) {
946 $result = db_query('SELECT fid, name, type, category, weight FROM {profile_fields} WHERE register = 1 ORDER BY category, weight');
947
948 while ($field = db_fetch_object($result)) {
949 if (_profile_field_serialize($field->type)) {
950 $edit[$field->name] = serialize($edit[$field->name]);
951 }
952 db_query('DELETE FROM {profile_values} WHERE fid = %d AND uid = %d', $field->fid, $user->uid);
953 db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $field->fid, $user->uid, $edit[$field->name]);
954 // Mark field as handled (prevents saving to user->data).
955 $edit[$field->name] = NULL;
956 }
957 }
958
959 function phpbb2drupal_comment_save($edit) {
960 db_set_active('default');
961 // Here we are building the thread field. See the comment
962 // in comment_render().
963 if ($edit['pid'] == 0) {
964 // This is a comment with no parent comment (depth 0): we start
965 // by retrieving the maximum thread level.
966 $max = db_result(db_query('SELECT MAX(thread) FROM {comments} WHERE nid = %d', $edit['nid']));
967
968 // Strip the "/" from the end of the thread.
969 $max = rtrim($max, '/');
970 $thread = int2vancode(vancode2int($max)+1) .'/';
971
972 }
973 else {
974 // This is comment with a parent comment: we increase
975 // the part of the thread value at the proper depth.
976
977 // Get the parent comment:
978 $parent = db_fetch_object(db_query('SELECT * FROM {comments} WHERE cid = %d', $edit['pid']));
979
980 // Strip the "/" from the end of the parent thread.
981 $parent->thread = (string) rtrim((string) $parent->thread, '/');
982
983 // Get the max value in _this_ thread.
984 $max = db_result(db_query("SELECT MAX(thread) FROM {comments} WHERE thread LIKE '%s.%%' AND nid = %d", $parent->thread, $edit['nid']));
985
986 if ($max == '') {
987 // First child of this parent.
988 $thread = $parent->thread .'.'. int2vancode(1) .'/';
989 }
990 else {
991 // Strip the "/" at the end of the thread.
992 $max = rtrim($max, '/');
993
994 // We need to get the value at the correct depth.
995 $parts = explode('.', $max);
996 $parent_depth = count(explode('.', $parent->thread));
997 $last = $parts[$parent_depth];
998
999 // Finally, build the thread field for this new comment.
1000 $thread = $parent->thread .'.'. int2vancode(vancode2int($last) + 1) .'/';
1001 }
1002 }
1003
1004 $status = 0; // 1 - not published, 0 - published
1005 $format = variable_get('phpbb2drupal_input_format', 0);
1006 $score = 0; // 0 default value, comments get higher score depending on the author's roles
1007 $users = serialize(array(0 => 1)); // default value for everybody!!
1008
1009 if ($edit['uid'] === $user->uid) { // '===' because we want to modify anonymous users too
1010 $edit['name'] = $user->name;
1011 }
1012
1013 db_query("INSERT INTO {comments} (nid, pid, uid, subject, comment, format, hostname, timestamp, status, thread, name) VALUES (%d, %d, %d, '%s', '%s', %d, '%s', %d, %d, '%s', '%s')", $edit['nid'], $edit['pid'], $edit['uid'], $edit['subject'], $edit['comment'], $edit['format'], ip_address(), $edit['timestamp'], $edit['status'], $thread, $edit['name']);
1014 $edit['cid'] = db_last_insert_id('comments', 'cid');
1015 _comment_update_node_statistics($edit['nid']);
1016
1017 return $edit['cid'];
1018 }
1019
1020 /**
1021 * PHPBB function for decoding the user ip
1022 */
1023 function phpbb2drupal_decode_ip($int_ip) {
1024 $hexipbang = explode('.', chunk_split($int_ip, 2, '.'));
1025 return hexdec($hexipbang[0]) .'.'. hexdec($hexipbang[1]) .'.'. hexdec($hexipbang[2]) .'.'. hexdec($hexipbang[3]);
1026 }
1027
1028 /**
1029 * Strips text of extra phpbb3 markup and if requested, also strips all bbcode from text.
1030 */
1031 function _phpbb2drupal_strip_bbcode($text) {
1032 // Strip the text of extra markup - regular expressions taken from phpbb3 includes/function.php, function get_preg_expression().
1033 $match = array(
1034 '#<!\-\- e \-\-><a href="mailto:(.*?)">.*?</a><!\-\- e \-\->#',
1035 '#<!\-\- l \-\-><a (?:class="[\w-]+" )?href="(.*?)(?:(&amp;|\?)sid=[0-9a-f]{32})?">.*?</a><!\-\- l \-\->#',
1036 '#<!\-\- ([mw]) \-\-><a (?:class="[\w-]+" )?href="(.*?)">.*?</a><!\-\- \1 \-\->#',
1037 '#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/.*? \/><!\-\- s\1 \-\->#',
1038 '#<!\-\- .*? \-\->#s',
1039 '#<.*?>#s',
1040 );
1041 $replace = array('$1', '$1', '$2', '$1', '', '');
1042 $text = preg_replace($match, $replace, $text);
1043
1044 // If bbcode conversion to has been selected, the following will convert the bbcode to normal html.
1045 if (variable_get('phpbb2drupal_bbcode', 0)) {
1046 $input_format = variable_get('phpbb2drupal_input_format', 0);
1047 $text = bbcode_filter('process', 0 , $input_format, $text);
1048 }
1049 return $text;
1050 }
1051
1052 /**
1053 * function to properly encode strings.
1054 */
1055 function _phpbb2drupal_text_sanitise($text) {
1056 $text = html_entity_decode($text, ENT_QUOTES, 'utf-8');
1057 return $text;
1058 }
1059
1060 // grep replace functions.
1061 function _phpbb2drupal_replace_links_topic($matches) {
1062 //print_r($matches);
1063 $result = db_result(db_query('SELECT nid FROM {phpbb2drupal_temp_topic} WHERE topic_id = %d', $matches[1]));
1064 $link = 'node/'. $result . $matches[2];
1065 return $link;
1066 }
1067
1068 function _phpbb2drupal_replace_links_post($matches) {
1069 //print_r($matches);
1070 $result = db_fetch_object(db_query('SELECT c.cid, c.nid FROM {phpbb2drupal_temp_post} p JOIN {comments} c ON c.cid = p.cid WHERE post_id = %d', $matches[1]));
1071 $link = 'node/'. $result->nid .'#comment-'. $result->cid . $matches[3];
1072 return $link;
1073 }
1074
1075 function _phpbb2drupal_replace_links_forum($matches) {
1076 //print_r($matches);
1077 $result = db_fetch_object(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $matches[1]));
1078 $link = 'forum/'. $result->tid . $matches[2] ;
1079 return $link;
1080 }
1081
1082
1083 /**
1084 * Replace all types of links.
1085 */
1086 function _phpbb2drupal_replace_links($html) {
1087 $html = preg_replace_callback('{forum/viewtopic.php\?p=(\d+)#(\d+)[^"|\'|>|<|\s|\]]*(["|\'|>|<|\s|\\|&quot;|\]])}i', '_phpbb2drupal_replace_links_post', $html);
1088 $html = preg_replace_callback('{forum/viewtopic.php\?t=(\d+)[^"|\'|>|<|\s|\]]*(["|\'|>|<|\s|\\|&quot;|\]])}i', '_phpbb2drupal_replace_links_topic', $html);
1089 $html = preg_replace_callback('{forum/viewforum.php\?f=(\d+)[^"|\'|>|<|\s|\]]*(["|\'|>|<|\s|\\|&quot;|\]])}i', '_phpbb2drupal_replace_links_forum', $html);
1090 // TODO look at removing $1. it looks like dead code.
1091 $html = preg_replace('{forum/index.php[^"|\'|>|\s|\]]*(["|\'|<|>|\s|\\|&quot;|\]])}i', "forum$1", $html);
1092 // You can use the line below to test locally the url's when you are testing:
1093 //$html = preg_replace("{www.reuniting.info}i", "127.0.0.1/drupal", $html);
1094 return $html;
1095 }
1096
1097
1098 /**
1099 * Replace URLs to old phpBB forum to new Drupal forum
1100 */
1101 function phpbb2drupal_replace_url() {
1102 db_set_active('default');
1103
1104 // transform nodes:
1105 // As the topics have just been imported, there is only one vid for each nid,
1106 // so the query works as it is.
1107 $result = db_query('SELECT ptt.nid, n.body, n.teaser FROM {phpbb2drupal_temp_topic} AS ptt LEFT JOIN {node_revisions} AS n ON ptt.nid = n.nid');
1108 while ($node = db_fetch_object($result)) {
1109 $node->body = _phpbb2drupal_replace_links($node->body);
1110 $node->teaser = _phpbb2drupal_replace_links($node->teaser);
1111 db_query("UPDATE {node_revisions} SET body= '%s', teaser = '%s' WHERE nid = %d", $node->body, $node->teaser, $node->nid);
1112 }
1113
1114 // transform comments:
1115 $result = db_query('SELECT c.cid, c.comment FROM {phpbb2drupal_temp_post} AS p LEFT JOIN {comments} AS c ON p.cid = c.cid');
1116 while ($comment = db_fetch_object($result)) {
1117 $comment->comment = _phpbb2drupal_replace_links($comment->comment);
1118 db_query("UPDATE {comments} SET comment= '%s' WHERE cid = %d", $comment->comment, $comment->cid);
1119 }
1120
1121 variable_set('phpbb2drupal_replace_url_successful', '1');
1122 }

  ViewVC Help
Powered by ViewVC 1.1.2