1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
|
<?php
/**
*
* @package install
* @version $Id$
* @copyright (c) 2006 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* Helper functions for phpBB 2.0.x to phpBB 3.0.x conversion
*/
/**
* Set forum flags - only prune old polls by default
*/
function phpbb_forum_flags()
{
// Set forum flags
$forum_flags = 0;
// FORUM_FLAG_LINK_TRACK
$forum_flags += 0;
// FORUM_FLAG_PRUNE_POLL
$forum_flags += FORUM_FLAG_PRUNE_POLL;
// FORUM_FLAG_PRUNE_ANNOUNCE
$forum_flags += 0;
// FORUM_FLAG_PRUNE_STICKY
$forum_flags += 0;
// FORUM_FLAG_ACTIVE_TOPICS
$forum_flags += 0;
// FORUM_FLAG_POST_REVIEW
$forum_flags += FORUM_FLAG_POST_REVIEW;
return $forum_flags;
}
/**
* Insert/Convert forums
*/
function phpbb_insert_forums()
{
global $db, $src_db, $same_db, $convert, $user, $config;
$db->sql_query($convert->truncate_statement . FORUMS_TABLE);
// Determine the highest id used within the old forums table (we add the categories after the forum ids)
$sql = 'SELECT MAX(forum_id) AS max_forum_id
FROM ' . $convert->src_table_prefix . 'forums';
$result = $src_db->sql_query($sql);
$max_forum_id = (int) $src_db->sql_fetchfield('max_forum_id');
$src_db->sql_freeresult($result);
$max_forum_id++;
// Insert categories
$sql = 'SELECT cat_id, cat_title
FROM ' . $convert->src_table_prefix . 'categories
ORDER BY cat_order';
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'binary'");
}
$result = $src_db->sql_query($sql);
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'utf8'");
}
switch ($db->sql_layer)
{
case 'mssql':
case 'mssql_odbc':
$db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' ON');
break;
}
$cats_added = array();
while ($row = $src_db->sql_fetchrow($result))
{
$sql_ary = array(
'forum_id' => $max_forum_id,
'forum_name' => ($row['cat_title']) ? htmlspecialchars(phpbb_set_default_encoding($row['cat_title']), ENT_COMPAT, 'UTF-8') : $user->lang['CATEGORY'],
'parent_id' => 0,
'forum_parents' => '',
'forum_desc' => '',
'forum_type' => FORUM_CAT,
'forum_status' => ITEM_UNLOCKED,
'forum_rules' => '',
);
$sql = 'SELECT MAX(right_id) AS right_id
FROM ' . FORUMS_TABLE;
$_result = $db->sql_query($sql);
$cat_row = $db->sql_fetchrow($_result);
$db->sql_freeresult($_result);
$sql_ary['left_id'] = $cat_row['right_id'] + 1;
$sql_ary['right_id'] = $cat_row['right_id'] + 2;
$sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
$cats_added[$row['cat_id']] = $max_forum_id;
$max_forum_id++;
}
$src_db->sql_freeresult($result);
// There may be installations having forums with non-existant category ids.
// We try to catch them and add them to an "unknown" category instead of leaving them out.
$sql = 'SELECT cat_id
FROM ' . $convert->src_table_prefix . 'forums
GROUP BY cat_id';
$result = $src_db->sql_query($sql);
$unknown_cat_id = false;
while ($row = $src_db->sql_fetchrow($result))
{
// Catch those categories not been added before
if (!isset($cats_added[$row['cat_id']]))
{
$unknown_cat_id = true;
}
}
$src_db->sql_freeresult($result);
// Is there at least one category not known?
if ($unknown_cat_id === true)
{
$unknown_cat_id = 'ghost';
$sql_ary = array(
'forum_id' => $max_forum_id,
'forum_name' => $user->lang['CATEGORY'],
'parent_id' => 0,
'forum_parents' => '',
'forum_desc' => '',
'forum_type' => FORUM_CAT,
'forum_status' => ITEM_UNLOCKED,
'forum_rules' => '',
);
$sql = 'SELECT MAX(right_id) AS right_id
FROM ' . FORUMS_TABLE;
$_result = $db->sql_query($sql);
$cat_row = $db->sql_fetchrow($_result);
$db->sql_freeresult($_result);
$sql_ary['left_id'] = $cat_row['right_id'] + 1;
$sql_ary['right_id'] = $cat_row['right_id'] + 2;
$sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
$cats_added[$unknown_cat_id] = $max_forum_id;
$max_forum_id++;
}
// Now insert the forums
$sql = 'SELECT f.forum_id, f.forum_name, f.cat_id, f.forum_desc, f.forum_status, f.prune_enable, f.prune_next, fp.prune_days, fp.prune_freq FROM ' . $convert->src_table_prefix . 'forums f
LEFT JOIN ' . $convert->src_table_prefix . 'forum_prune fp ON f.forum_id = fp.forum_id
GROUP BY f.forum_id, f.forum_name, f.cat_id, f.forum_desc, f.forum_status, f.prune_enable, f.prune_next, f.forum_order, fp.prune_days, fp.prune_freq
ORDER BY f.cat_id, f.forum_order';
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'binary'");
}
$result = $src_db->sql_query($sql);
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'utf8'");
}
while ($row = $src_db->sql_fetchrow($result))
{
// Some might have forums here with an id not being "possible"...
// To be somewhat friendly we "change" the category id for those to a previously created ghost category
if (!isset($cats_added[$row['cat_id']]) && $unknown_cat_id !== false)
{
$row['cat_id'] = $unknown_cat_id;
}
if (!isset($cats_added[$row['cat_id']]))
{
continue;
}
// Define the new forums sql ary
$sql_ary = array(
'forum_id' => (int) $row['forum_id'],
'forum_name' => htmlspecialchars(phpbb_set_default_encoding($row['forum_name']), ENT_COMPAT, 'UTF-8'),
'parent_id' => $cats_added[$row['cat_id']],
'forum_parents' => '',
'forum_desc' => htmlspecialchars(phpbb_set_default_encoding($row['forum_desc']), ENT_COMPAT, 'UTF-8'),
'forum_type' => FORUM_POST,
'forum_status' => is_item_locked($row['forum_status']),
'enable_prune' => $row['prune_enable'],
'prune_next' => null_to_zero($row['prune_next']),
'prune_days' => null_to_zero($row['prune_days']),
'prune_viewed' => 0,
'prune_freq' => null_to_zero($row['prune_freq']),
'forum_flags' => phpbb_forum_flags(),
// Default values
'forum_desc_bitfield' => '',
'forum_desc_options' => 7,
'forum_desc_uid' => '',
'forum_link' => '',
'forum_password' => '',
'forum_style' => 0,
'forum_image' => '',
'forum_rules' => '',
'forum_rules_link' => '',
'forum_rules_bitfield' => '',
'forum_rules_options' => 7,
'forum_rules_uid' => '',
'forum_topics_per_page' => 0,
'forum_posts' => 0,
'forum_topics' => 0,
'forum_topics_real' => 0,
'forum_last_post_id' => 0,
'forum_last_poster_id' => 0,
'forum_last_post_subject' => '',
'forum_last_post_time' => 0,
'forum_last_poster_name' => '',
'forum_last_poster_colour' => '',
'display_on_index' => 1,
'enable_indexing' => 1,
'enable_icons' => 0,
);
// Now add the forums with proper left/right ids
$sql = 'SELECT left_id, right_id
FROM ' . FORUMS_TABLE . '
WHERE forum_id = ' . $cats_added[$row['cat_id']];
$_result = $db->sql_query($sql);
$cat_row = $db->sql_fetchrow($_result);
$db->sql_freeresult($_result);
$sql = 'UPDATE ' . FORUMS_TABLE . '
SET left_id = left_id + 2, right_id = right_id + 2
WHERE left_id > ' . $cat_row['right_id'];
$db->sql_query($sql);
$sql = 'UPDATE ' . FORUMS_TABLE . '
SET right_id = right_id + 2
WHERE ' . $cat_row['left_id'] . ' BETWEEN left_id AND right_id';
$db->sql_query($sql);
$sql_ary['left_id'] = $cat_row['right_id'];
$sql_ary['right_id'] = $cat_row['right_id'] + 1;
$sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
}
$src_db->sql_freeresult($result);
switch ($db->sql_layer)
{
case 'mssql':
case 'mssql_odbc':
$db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' OFF');
break;
}
}
/**
* Function for recoding text with the default language
*
* @param string $text text to recode to utf8
* @param bool $grab_user_lang if set to true the function tries to use $convert_row['user_lang'] (and falls back to $convert_row['poster_id']) instead of the boards default language
*/
function phpbb_set_encoding($text, $grab_user_lang = true)
{
global $lang_enc_array, $convert_row;
global $convert, $phpEx;
/*static $lang_enc_array = array(
'korean' => 'euc-kr',
'serbian' => 'windows-1250',
'polish' => 'iso-8859-2',
'kurdish' => 'windows-1254',
'slovak' => 'Windows-1250',
'russian' => 'windows-1251',
'estonian' => 'iso-8859-4',
'chinese_simplified' => 'gb2312',
'macedonian' => 'windows-1251',
'azerbaijani' => 'UTF-8',
'romanian' => 'iso-8859-2',
'romanian_diacritice' => 'iso-8859-2',
'lithuanian' => 'windows-1257',
'turkish' => 'iso-8859-9',
'ukrainian' => 'windows-1251',
'japanese' => 'shift_jis',
'hungarian' => 'ISO-8859-2',
'romanian_no_diacritics' => 'iso-8859-2',
'mongolian' => 'UTF-8',
'slovenian' => 'windows-1250',
'bosnian' => 'windows-1250',
'czech' => 'Windows-1250',
'farsi' => 'Windows-1256',
'croatian' => 'windows-1250',
'greek' => 'iso-8859-7',
'russian_tu' => 'windows-1251',
'sakha' => 'UTF-8',
'serbian_cyrillic' => 'windows-1251',
'bulgarian' => 'windows-1251',
'chinese_traditional_taiwan' => 'big5',
'chinese_traditional' => 'big5',
'arabic' => 'windows-1256',
'hebrew' => 'WINDOWS-1255',
'thai' => 'windows-874',
//'chinese_traditional_taiwan' => 'utf-8' // custom modified, we may have to do an include :-(
);*/
if (empty($lang_enc_array))
{
$lang_enc_array = array();
}
$get_lang = trim(get_config_value('default_lang'));
// Do we need the users language encoding?
if ($grab_user_lang && !empty($convert_row))
{
if (!empty($convert_row['user_lang']))
{
$get_lang = trim($convert_row['user_lang']);
}
else if (!empty($convert_row['poster_id']))
{
global $src_db, $same_db;
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'binary'");
}
$sql = 'SELECT user_lang
FROM ' . $convert->src_table_prefix . 'users
WHERE user_id = ' . (int) $convert_row['poster_id'];
$result = $src_db->sql_query($sql);
$get_lang = (string) $src_db->sql_fetchfield('user_lang');
$src_db->sql_freeresult($result);
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'utf8'");
}
$get_lang = (!trim($get_lang)) ? trim(get_config_value('default_lang')) : trim($get_lang);
}
}
if (!isset($lang_enc_array[$get_lang]))
{
$filename = $convert->options['forum_path'] . '/language/lang_' . $get_lang . '/lang_main.' . $phpEx;
if (!file_exists($filename))
{
$get_lang = trim(get_config_value('default_lang'));
}
if (!isset($lang_enc_array[$get_lang]))
{
include($convert->options['forum_path'] . '/language/lang_' . $get_lang . '/lang_main.' . $phpEx);
$lang_enc_array[$get_lang] = $lang['ENCODING'];
unset($lang);
}
}
$encoding = $lang_enc_array[$get_lang];
return utf8_recode($text, $lang_enc_array[$get_lang]);
}
/**
* Same as phpbb_set_encoding, but forcing boards default language
*/
function phpbb_set_default_encoding($text)
{
return phpbb_set_encoding($text, false);
}
/**
* Convert Birthday from Birthday MOD to phpBB Format
*/
function phpbb_get_birthday($birthday = '')
{
if (defined('MOD_BIRTHDAY_TERRA'))
{
$birthday = (string) $birthday;
// stored as month, day, year
if (!$birthday)
{
return ' 0- 0- 0';
}
$month = substr($birthday, 0, 2);
$day = substr($birthday, 2, 2);
$year = substr($birthday, -4);
return sprintf('%2d-%2d-%4d', $day, $month, $year);
}
else
{
$birthday = (int) $birthday;
if (!$birthday || $birthday == 999999 || $birthday < 0)
{
return ' 0- 0- 0';
}
// The birthday mod from niels is using this code to transform to day/month/year
return gmdate('d-m-Y', $birthday * 86400 + 1);
}
}
/**
* Return correct user id value
* Everyone's id will be one higher to allow the guest/anonymous user to have a positive id as well
*/
function phpbb_user_id($user_id)
{
global $config;
// Increment user id if the old forum is having a user with the id 1
if (!isset($config['increment_user_id']))
{
global $src_db, $same_db, $convert;
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'binary'");
}
// Now let us set a temporary config variable for user id incrementing
$sql = "SELECT user_id
FROM {$convert->src_table_prefix}users
WHERE user_id = 1";
$result = $src_db->sql_query($sql);
$id = (int) $src_db->sql_fetchfield('user_id');
$src_db->sql_freeresult($result);
// Try to get the maximum user id possible...
$sql = "SELECT MAX(user_id) AS max_user_id
FROM {$convert->src_table_prefix}users";
$result = $src_db->sql_query($sql);
$max_id = (int) $src_db->sql_fetchfield('max_user_id');
$src_db->sql_freeresult($result);
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'utf8'");
}
// If there is a user id 1, we need to increment user ids. :/
if ($id === 1)
{
set_config('increment_user_id', ($max_id + 1), true);
$config['increment_user_id'] = $max_id + 1;
}
else
{
set_config('increment_user_id', 0, true);
$config['increment_user_id'] = 0;
}
}
// If the old user id is -1 in 2.0.x it is the anonymous user...
if ($user_id == -1)
{
return ANONYMOUS;
}
if (!empty($config['increment_user_id']) && $user_id == 1)
{
return $config['increment_user_id'];
}
// A user id of 0 can happen, for example within the ban table if no user is banned...
// Within the posts and topics table this can be "dangerous" but is the fault of the user
// having mods installed (a poster id of 0 is not possible in 2.0.x).
// Therefore, we return the user id "as is".
return $user_id;
}
/* Copy additional table fields from old forum to new forum if user wants this (for Mod compatibility for example)
function phpbb_copy_table_fields()
{
}
*/
/**
* Convert authentication
* user, group and forum table has to be filled in order to work
*/
function phpbb_convert_authentication($mode)
{
global $db, $src_db, $same_db, $convert, $user, $config, $cache;
if ($mode == 'start')
{
$db->sql_query($convert->truncate_statement . ACL_USERS_TABLE);
$db->sql_query($convert->truncate_statement . ACL_GROUPS_TABLE);
// What we will do is handling all 2.0.x admins as founder to replicate what is common in 2.0.x.
// After conversion the main admin need to make sure he is removing permissions and the founder status if wanted.
// Grab user ids of users with user_level of ADMIN
$sql = "SELECT user_id
FROM {$convert->src_table_prefix}users
WHERE user_level = 1
ORDER BY user_regdate ASC";
$result = $src_db->sql_query($sql);
while ($row = $src_db->sql_fetchrow($result))
{
$user_id = (int) phpbb_user_id($row['user_id']);
// Set founder admin...
$sql = 'UPDATE ' . USERS_TABLE . '
SET user_type = ' . USER_FOUNDER . "
WHERE user_id = $user_id";
$db->sql_query($sql);
}
$src_db->sql_freeresult($result);
}
// Grab forum auth information
$sql = "SELECT *
FROM {$convert->src_table_prefix}forums";
$result = $src_db->sql_query($sql);
$forum_access = array();
while ($row = $src_db->sql_fetchrow($result))
{
$forum_access[] = $row;
}
$src_db->sql_freeresult($result);
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'binary'");
}
// Grab user auth information from 2.0.x board
$sql = "SELECT ug.user_id, aa.*
FROM {$convert->src_table_prefix}auth_access aa, {$convert->src_table_prefix}user_group ug, {$convert->src_table_prefix}groups g
WHERE g.group_id = aa.group_id
AND g.group_single_user = 1
AND ug.group_id = g.group_id";
$result = $src_db->sql_query($sql);
$user_access = array();
while ($row = $src_db->sql_fetchrow($result))
{
$user_access[$row['forum_id']][] = $row;
}
$src_db->sql_freeresult($result);
// Grab group auth information
$sql = "SELECT g.group_id, aa.*
FROM {$convert->src_table_prefix}auth_access aa, {$convert->src_table_prefix}groups g
WHERE g.group_id = aa.group_id
AND g.group_single_user <> 1";
$result = $src_db->sql_query($sql);
$group_access = array();
while ($row = $src_db->sql_fetchrow($result))
{
$group_access[$row['forum_id']][] = $row;
}
$src_db->sql_freeresult($result);
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'utf8'");
}
// Add Forum Access List
$auth_map = array(
'auth_view' => array('f_', 'f_list'),
'auth_read' => array('f_read', 'f_search'),
'auth_post' => array('f_post', 'f_bbcode', 'f_smilies', 'f_img', 'f_sigs', 'f_postcount', 'f_report', 'f_subscribe', 'f_print', 'f_email'),
'auth_reply' => 'f_reply',
'auth_edit' => 'f_edit',
'auth_delete' => 'f_delete',
'auth_pollcreate' => 'f_poll',
'auth_vote' => 'f_vote',
'auth_announce' => 'f_announce',
'auth_sticky' => 'f_sticky',
'auth_attachments' => array('f_attach', 'f_download'),
'auth_download' => 'f_download',
);
// Define the ACL constants used in 2.0 to make the code slightly more readable
define('AUTH_ALL', 0);
define('AUTH_REG', 1);
define('AUTH_ACL', 2);
define('AUTH_MOD', 3);
define('AUTH_ADMIN', 5);
// A mapping of the simple permissions used by 2.0
$simple_auth_ary = array(
'public' => array(
'auth_view' => AUTH_ALL,
'auth_read' => AUTH_ALL,
'auth_post' => AUTH_ALL,
'auth_reply' => AUTH_ALL,
'auth_edit' => AUTH_REG,
'auth_delete' => AUTH_REG,
'auth_sticky' => AUTH_MOD,
'auth_announce' => AUTH_MOD,
'auth_vote' => AUTH_REG,
'auth_pollcreate' => AUTH_REG,
),
'registered' => array(
'auth_view' => AUTH_ALL,
'auth_read' => AUTH_ALL,
'auth_post' => AUTH_REG,
'auth_reply' => AUTH_REG,
'auth_edit' => AUTH_REG,
'auth_delete' => AUTH_REG,
'auth_sticky' => AUTH_MOD,
'auth_announce' => AUTH_MOD,
'auth_vote' => AUTH_REG,
'auth_pollcreate' => AUTH_REG,
),
'registered_hidden' => array(
'auth_view' => AUTH_REG,
'auth_read' => AUTH_REG,
'auth_post' => AUTH_REG,
'auth_reply' => AUTH_REG,
'auth_edit' => AUTH_REG,
'auth_delete' => AUTH_REG,
'auth_sticky' => AUTH_MOD,
'auth_announce' => AUTH_MOD,
'auth_vote' => AUTH_REG,
'auth_pollcreate' => AUTH_REG,
),
'private' => array(
'auth_view' => AUTH_ALL,
'auth_read' => AUTH_ACL,
'auth_post' => AUTH_ACL,
'auth_reply' => AUTH_ACL,
'auth_edit' => AUTH_ACL,
'auth_delete' => AUTH_ACL,
'auth_sticky' => AUTH_ACL,
'auth_announce' => AUTH_MOD,
'auth_vote' => AUTH_ACL,
'auth_pollcreate' => AUTH_ACL,
),
'private_hidden' => array(
'auth_view' => AUTH_ACL,
'auth_read' => AUTH_ACL,
'auth_post' => AUTH_ACL,
'auth_reply' => AUTH_ACL,
'auth_edit' => AUTH_ACL,
'auth_delete' => AUTH_ACL,
'auth_sticky' => AUTH_ACL,
'auth_announce' => AUTH_MOD,
'auth_vote' => AUTH_ACL,
'auth_pollcreate' => AUTH_ACL,
),
'moderator' => array(
'auth_view' => AUTH_ALL,
'auth_read' => AUTH_MOD,
'auth_post' => AUTH_MOD,
'auth_reply' => AUTH_MOD,
'auth_edit' => AUTH_MOD,
'auth_delete' => AUTH_MOD,
'auth_sticky' => AUTH_MOD,
'auth_announce' => AUTH_MOD,
'auth_vote' => AUTH_MOD,
'auth_pollcreate' => AUTH_MOD,
),
'moderator_hidden' => array(
'auth_view' => AUTH_MOD,
'auth_read' => AUTH_MOD,
'auth_post' => AUTH_MOD,
'auth_reply' => AUTH_MOD,
'auth_edit' => AUTH_MOD,
'auth_delete' => AUTH_MOD,
'auth_sticky' => AUTH_MOD,
'auth_announce' => AUTH_MOD,
'auth_vote' => AUTH_MOD,
'auth_pollcreate' => AUTH_MOD,
),
);
if ($mode == 'start')
{
user_group_auth('guests', 'SELECT user_id, {GUESTS} FROM ' . USERS_TABLE . ' WHERE user_id = ' . ANONYMOUS, false);
user_group_auth('registered', 'SELECT user_id, {REGISTERED} FROM ' . USERS_TABLE . ' WHERE user_id <> ' . ANONYMOUS, false);
// Selecting from old table
if (!empty($config['increment_user_id']))
{
$auth_sql = 'SELECT user_id, {ADMINISTRATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1 AND user_id <> 1';
user_group_auth('administrators', $auth_sql, true);
$auth_sql = 'SELECT ' . $config['increment_user_id'] . ' as user_id, {ADMINISTRATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1 AND user_id = 1';
user_group_auth('administrators', $auth_sql, true);
}
else
{
$auth_sql = 'SELECT user_id, {ADMINISTRATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1';
user_group_auth('administrators', $auth_sql, true);
}
if (!empty($config['increment_user_id']))
{
$auth_sql = 'SELECT user_id, {GLOBAL_MODERATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1 AND user_id <> 1';
user_group_auth('global_moderators', $auth_sql, true);
$auth_sql = 'SELECT ' . $config['increment_user_id'] . ' as user_id, {GLOBAL_MODERATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1 AND user_id = 1';
user_group_auth('global_moderators', $auth_sql, true);
}
else
{
$auth_sql = 'SELECT user_id, {GLOBAL_MODERATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1';
user_group_auth('global_moderators', $auth_sql, true);
}
}
else if ($mode == 'first')
{
// Go through all 2.0.x forums
foreach ($forum_access as $forum)
{
$new_forum_id = (int) $forum['forum_id'];
// Administrators have full access to all forums whatever happens
mass_auth('group_role', $new_forum_id, 'administrators', 'FORUM_FULL');
$matched_type = '';
foreach ($simple_auth_ary as $key => $auth_levels)
{
$matched = 1;
foreach ($auth_levels as $k => $level)
{
if ($forum[$k] != $auth_levels[$k])
{
$matched = 0;
}
}
if ($matched)
{
$matched_type = $key;
break;
}
}
switch ($matched_type)
{
case 'public':
mass_auth('group_role', $new_forum_id, 'guests', 'FORUM_LIMITED');
mass_auth('group_role', $new_forum_id, 'registered', 'FORUM_LIMITED_POLLS');
mass_auth('group_role', $new_forum_id, 'bots', 'FORUM_BOT');
break;
case 'registered':
mass_auth('group_role', $new_forum_id, 'guests', 'FORUM_READONLY');
mass_auth('group_role', $new_forum_id, 'bots', 'FORUM_BOT');
// no break;
case 'registered_hidden':
mass_auth('group_role', $new_forum_id, 'registered', 'FORUM_POLLS');
break;
case 'private':
case 'private_hidden':
case 'moderator':
case 'moderator_hidden':
default:
// The permissions don't match a simple set, so we're going to have to map them directly
// No post approval for all, in 2.0.x this feature does not exist
mass_auth('group', $new_forum_id, 'guests', 'f_noapprove', ACL_YES);
mass_auth('group', $new_forum_id, 'registered', 'f_noapprove', ACL_YES);
// Go through authentication map
foreach ($auth_map as $old_auth_key => $new_acl)
{
// If old authentication key does not exist we continue
// This is helpful for mods adding additional authentication fields, we need to add them to the auth_map array
if (!isset($forum[$old_auth_key]))
{
continue;
}
// Now set the new ACL correctly
switch ($forum[$old_auth_key])
{
// AUTH_ALL
case AUTH_ALL:
mass_auth('group', $new_forum_id, 'guests', $new_acl, ACL_YES);
mass_auth('group', $new_forum_id, 'bots', $new_acl, ACL_YES);
mass_auth('group', $new_forum_id, 'registered', $new_acl, ACL_YES);
break;
// AUTH_REG
case AUTH_REG:
mass_auth('group', $new_forum_id, 'registered', $new_acl, ACL_YES);
break;
// AUTH_ACL
case AUTH_ACL:
// Go through the old group access list for this forum
if (isset($group_access[$forum['forum_id']]))
{
foreach ($group_access[$forum['forum_id']] as $index => $access)
{
// We only check for ACL_YES equivalence entry
if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
{
mass_auth('group', $new_forum_id, (int) $access['group_id'], $new_acl, ACL_YES);
}
}
}
if (isset($user_access[$forum['forum_id']]))
{
foreach ($user_access[$forum['forum_id']] as $index => $access)
{
// We only check for ACL_YES equivalence entry
if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
{
mass_auth('user', $new_forum_id, (int) phpbb_user_id($access['user_id']), $new_acl, ACL_YES);
}
}
}
break;
// AUTH_MOD
case AUTH_MOD:
if (isset($group_access[$forum['forum_id']]))
{
foreach ($group_access[$forum['forum_id']] as $index => $access)
{
// We only check for ACL_YES equivalence entry
if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
{
mass_auth('group', $new_forum_id, (int) $access['group_id'], $new_acl, ACL_YES);
}
}
}
if (isset($user_access[$forum['forum_id']]))
{
foreach ($user_access[$forum['forum_id']] as $index => $access)
{
// We only check for ACL_YES equivalence entry
if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
{
mass_auth('user', $new_forum_id, (int) phpbb_user_id($access['user_id']), $new_acl, ACL_YES);
}
}
}
break;
}
}
break;
}
}
}
else if ($mode == 'second')
{
// Assign permission roles and other default permissions
// guests having u_download and u_search ability
$db->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) SELECT ' . get_group_id('guests') . ', 0, auth_option_id, 0, 1 FROM ' . ACL_OPTIONS_TABLE . " WHERE auth_option IN ('u_', 'u_download', 'u_search')");
// administrators/global mods having full user features
mass_auth('group_role', 0, 'administrators', 'USER_FULL');
mass_auth('group_role', 0, 'global_moderators', 'USER_FULL');
// By default all converted administrators are given full access
mass_auth('group_role', 0, 'administrators', 'ADMIN_FULL');
// All registered users are assigned the standard user role
mass_auth('group_role', 0, 'registered', 'USER_STANDARD');
mass_auth('group_role', 0, 'registered_coppa', 'USER_STANDARD');
// Instead of administrators being global moderators we give the MOD_FULL role to global mods (admins already assigned to this group)
mass_auth('group_role', 0, 'global_moderators', 'MOD_FULL');
// And now those who have had their avatar rights removed get assigned a more restrictive role
$sql = 'SELECT user_id FROM ' . $convert->src_table_prefix . 'users
WHERE user_allowavatar = 0
AND user_id > 0';
$result = $src_db->sql_query($sql);
while ($row = $src_db->sql_fetchrow($result))
{
mass_auth('user_role', 0, (int) phpbb_user_id($row['user_id']), 'USER_NOAVATAR');
}
$src_db->sql_freeresult($result);
// And the same for those who have had their PM rights removed
$sql = 'SELECT user_id FROM ' . $convert->src_table_prefix . 'users
WHERE user_allow_pm = 0
AND user_id > 0';
$result = $src_db->sql_query($sql);
while ($row = $src_db->sql_fetchrow($result))
{
mass_auth('user_role', 0, (int) phpbb_user_id($row['user_id']), 'USER_NOPM');
}
$src_db->sql_freeresult($result);
}
else if ($mode == 'third')
{
// And now the moderators
// We make sure that they have at least standard access to the forums they moderate in addition to the moderating permissions
foreach ($user_access as $forum_id => $access_map)
{
$forum_id = (int) $forum_id;
foreach ($access_map as $access)
{
if (isset($access['auth_mod']) && $access['auth_mod'] == 1)
{
mass_auth('user_role', $forum_id, (int) phpbb_user_id($access['user_id']), 'MOD_STANDARD');
mass_auth('user_role', $forum_id, (int) phpbb_user_id($access['user_id']), 'FORUM_STANDARD');
}
}
}
foreach ($group_access as $forum_id => $access_map)
{
$forum_id = (int) $forum_id;
foreach ($access_map as $access)
{
if (isset($access['auth_mod']) && $access['auth_mod'] == 1)
{
mass_auth('group_role', $forum_id, (int) $access['group_id'], 'MOD_STANDARD');
mass_auth('group_role', $forum_id, (int) $access['group_id'], 'FORUM_STANDARD');
}
}
}
// We grant everyone readonly access to the categories to ensure that the forums are visible
$sql = 'SELECT forum_id, forum_name, parent_id, left_id, right_id
FROM ' . FORUMS_TABLE . '
ORDER BY left_id ASC';
$result = $db->sql_query($sql);
$parent_forums = $forums = array();
while ($row = $db->sql_fetchrow($result))
{
if ($row['parent_id'] == 0)
{
mass_auth('group_role', $row['forum_id'], 'administrators', 'FORUM_FULL');
mass_auth('group_role', $row['forum_id'], 'global_moderators', 'FORUM_FULL');
$parent_forums[] = $row;
}
else
{
$forums[] = $row;
}
}
$db->sql_freeresult($result);
global $auth;
// Let us see which groups have access to these forums...
foreach ($parent_forums as $row)
{
// Get the children
$branch = $forum_ids = array();
foreach ($forums as $key => $_row)
{
if ($_row['left_id'] > $row['left_id'] && $_row['left_id'] < $row['right_id'])
{
$branch[] = $_row;
$forum_ids[] = $_row['forum_id'];
continue;
}
}
if (sizeof($forum_ids))
{
// Now make sure the user is able to read these forums
$hold_ary = $auth->acl_group_raw_data(false, 'f_list', $forum_ids);
if (empty($hold_ary))
{
continue;
}
foreach ($hold_ary as $g_id => $f_id_ary)
{
$set_group = false;
foreach ($f_id_ary as $f_id => $auth_ary)
{
foreach ($auth_ary as $auth_option => $setting)
{
if ($setting == ACL_YES)
{
$set_group = true;
break 2;
}
}
}
if ($set_group)
{
mass_auth('group', $row['forum_id'], $g_id, 'f_list', ACL_YES);
}
}
}
}
}
}
/**
* Set primary group.
* Really simple and only based on user_level (remaining groups will be assigned later)
*/
function phpbb_set_primary_group($user_level)
{
global $convert_row;
if ($user_level == 1)
{
return get_group_id('administrators');
}
/* else if ($user_level == 2)
{
return get_group_id('global_moderators');
}
else if ($user_level == 0 && $convert_row['user_active'])*/
else if ($convert_row['user_active'])
{
return get_group_id('registered');
}
return 0;
}
/**
* Convert the group name, making sure to avoid conflicts with 3.0 special groups
*/
function phpbb_convert_group_name($group_name)
{
$default_groups = array(
'GUESTS',
'REGISTERED',
'REGISTERED_COPPA',
'GLOBAL_MODERATORS',
'ADMINISTRATORS',
'BOTS',
);
if (in_array(strtoupper($group_name), $default_groups))
{
return 'phpBB2 - ' . $group_name;
}
return phpbb_set_default_encoding($group_name);
}
/**
* Convert the group type constants
*/
function phpbb_convert_group_type($group_type)
{
switch ($group_type)
{
case 0:
return GROUP_OPEN;
break;
case 1:
return GROUP_CLOSED;
break;
case 2:
return GROUP_HIDDEN;
break;
}
return GROUP_SPECIAL;
}
/**
* Convert the topic type constants
*/
function phpbb_convert_topic_type($topic_type)
{
switch ($topic_type)
{
case 0:
return POST_NORMAL;
break;
case 1:
return POST_STICKY;
break;
case 2:
return POST_ANNOUNCE;
break;
case 3:
return POST_GLOBAL;
break;
}
return POST_NORMAL;
}
function phpbb_replace_size($matches)
{
return '[size=' . min(200, ceil(100.0 * (((double) $matches[1])/12.0))) . ':' . $matches[2] . ']';
}
/**
* Reparse the message stripping out the bbcode_uid values and adding new ones and setting the bitfield
* @todo What do we want to do about HTML in messages - currently it gets converted to the entities, but there may be some objections to this
*/
function phpbb_prepare_message($message)
{
global $phpbb_root_path, $phpEx, $db, $convert, $user, $config, $cache, $convert_row, $message_parser;
if (!$message)
{
$convert->row['mp_bbcode_bitfield'] = $convert_row['mp_bbcode_bitfield'] = 0;
return '';
}
// Decode phpBB 2.0.x Message
if (isset($convert->row['old_bbcode_uid']) && $convert->row['old_bbcode_uid'] != '')
{
// Adjust size...
if (strpos($message, '[size=') !== false)
{
$message = preg_replace_callback('/\[size=(\d*):(' . $convert->row['old_bbcode_uid'] . ')\]/', 'phpbb_replace_size', $message);
}
$message = preg_replace('/\:(([a-z0-9]:)?)' . $convert->row['old_bbcode_uid'] . '/s', '', $message);
}
if (strpos($message, '[quote=') !== false)
{
$message = preg_replace('/\[quote="(.*?)"\]/s', '[quote="\1"]', $message);
}
// Already the new user id ;)
$user_id = $convert->row['poster_id'];
$message = str_replace('<', '<', $message);
$message = str_replace('>', '>', $message);
$message = str_replace('<br />', "\n", $message);
// make the post UTF-8
$message = phpbb_set_encoding($message);
$message_parser->warn_msg = array(); // Reset the errors from the previous message
$message_parser->bbcode_uid = make_uid($convert->row['post_time']);
$message_parser->message = $message;
unset($message);
// Make sure options are set.
// $enable_html = (!isset($row['enable_html'])) ? false : $row['enable_html'];
$enable_bbcode = (!isset($convert->row['enable_bbcode'])) ? true : $convert->row['enable_bbcode'];
$enable_smilies = (!isset($convert->row['enable_smilies'])) ? true : $convert->row['enable_smilies'];
$enable_magic_url = (!isset($convert->row['enable_magic_url'])) ? true : $convert->row['enable_magic_url'];
// parse($allow_bbcode, $allow_magic_url, $allow_smilies, $allow_img_bbcode = true, $allow_flash_bbcode = true, $allow_quote_bbcode = true, $allow_url_bbcode = true, $update_this_message = true, $mode = 'post')
$message_parser->parse($enable_bbcode, $enable_magic_url, $enable_smilies);
if (sizeof($message_parser->warn_msg))
{
$msg_id = isset($convert->row['post_id']) ? $convert->row['post_id'] : $convert->row['privmsgs_id'];
$convert->p_master->error('<span style="color:red">' . $user->lang['POST_ID'] . ': ' . $msg_id . ' ' . $user->lang['CONV_ERROR_MESSAGE_PARSER'] . ': <br /><br />' . implode('<br />', $message_parser->warn_msg), __LINE__, __FILE__, true);
}
$convert->row['mp_bbcode_bitfield'] = $convert_row['mp_bbcode_bitfield'] = $message_parser->bbcode_bitfield;
$message = $message_parser->message;
unset($message_parser->message);
return $message;
}
/**
* Return the bitfield calculated by the previous function
*/
function get_bbcode_bitfield()
{
global $convert_row;
return $convert_row['mp_bbcode_bitfield'];
}
/**
* Determine the last user to edit a post
* In practice we only tracked edits by the original poster in 2.0.x so this will only be set if they had edited their own post
*/
function phpbb_post_edit_user()
{
global $convert_row, $config;
if (isset($convert_row['post_edit_count']))
{
return phpbb_user_id($convert_row['poster_id']);
}
return 0;
}
/**
* Obtain the path to uploaded files on the 2.0.x forum
* This is only used if the Attachment MOD was installed
*/
function phpbb_get_files_dir()
{
if (!defined('MOD_ATTACHMENT'))
{
return;
}
global $src_db, $same_db, $convert, $user, $config, $cache;
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'binary'");
}
$sql = 'SELECT config_value AS upload_dir
FROM ' . $convert->src_table_prefix . "attachments_config
WHERE config_name = 'upload_dir'";
$result = $src_db->sql_query($sql);
$upload_path = $src_db->sql_fetchfield('upload_dir');
$src_db->sql_freeresult($result);
$sql = 'SELECT config_value AS ftp_upload
FROM ' . $convert->src_table_prefix . "attachments_config
WHERE config_name = 'allow_ftp_upload'";
$result = $src_db->sql_query($sql);
$ftp_upload = (int) $src_db->sql_fetchfield('ftp_upload');
$src_db->sql_freeresult($result);
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'utf8'");
}
if ($ftp_upload)
{
$convert->p_master->error($user->lang['CONV_ERROR_ATTACH_FTP_DIR'], __LINE__, __FILE__);
}
return $upload_path;
}
/**
* Copy thumbnails of uploaded images from the 2.0.x forum
* This is only used if the Attachment MOD was installed
*/
function phpbb_copy_thumbnails()
{
global $db, $convert, $user, $config, $cache, $phpbb_root_path;
$src_path = $convert->options['forum_path'] . '/' . phpbb_get_files_dir() . '/thumbs/';
if ($handle = @opendir($src_path))
{
while ($entry = readdir($handle))
{
if ($entry[0] == '.')
{
continue;
}
if (is_dir($src_path . $entry))
{
continue;
}
else
{
copy_file($src_path . $entry, $config['upload_path'] . '/' . preg_replace('/^t_/', 'thumb_', $entry));
@unlink($phpbb_root_path . $config['upload_path'] . '/thumbs/' . $entry);
}
}
closedir($handle);
}
}
/**
* Convert the attachment category constants
* This is only used if the Attachment MOD was installed
*/
function phpbb_attachment_category($cat_id)
{
switch ($cat_id)
{
case 1:
return ATTACHMENT_CATEGORY_IMAGE;
break;
case 2:
return ATTACHMENT_CATEGORY_WM;
break;
case 3:
return ATTACHMENT_CATEGORY_FLASH;
break;
}
return ATTACHMENT_CATEGORY_NONE;
}
/**
* Obtain list of forums in which different attachment categories can be used
*/
function phpbb_attachment_forum_perms($forum_permissions)
{
if (empty($forum_permissions))
{
return '';
}
// Decode forum permissions
$forum_ids = array();
$one_char_encoding = '#';
$two_char_encoding = '.';
$auth_len = 1;
for ($pos = 0; $pos < strlen($forum_permissions); $pos += $auth_len)
{
$forum_auth = substr($forum_permissions, $pos, 1);
if ($forum_auth == $one_char_encoding)
{
$auth_len = 1;
continue;
}
else if ($forum_auth == $two_char_encoding)
{
$auth_len = 2;
$pos--;
continue;
}
$forum_auth = substr($forum_permissions, $pos, $auth_len);
$forum_id = base64_unpack($forum_auth);
$forum_ids[] = (int) $forum_id;
}
if (sizeof($forum_ids))
{
return attachment_forum_perms($forum_ids);
}
return '';
}
/**
* Convert the avatar type constants
*/
function phpbb_avatar_type($type)
{
switch ($type)
{
case 1:
return AVATAR_UPLOAD;
break;
case 2:
return AVATAR_REMOTE;
break;
case 3:
return AVATAR_GALLERY;
break;
}
return 0;
}
/**
* Transfer avatars, copying the image if it was uploaded
*/
function phpbb_import_avatar($user_avatar)
{
global $convert_row;
if (!$convert_row['user_avatar_type'])
{
return '';
}
else if ($convert_row['user_avatar_type'] == 1)
{
// Uploaded avatar
return import_avatar($user_avatar);
}
else if ($convert_row['user_avatar_type'] == 2)
{
// Remote avatar
return $user_avatar;
}
else if ($convert_row['user_avatar_type'] == 3)
{
// Gallery avatar
return $user_avatar;
}
return '';
}
/**
* Calculate the correct to_address field for private messages
*/
function phpbb_privmsgs_to_userid($to_userid)
{
global $config;
return 'u_' . phpbb_user_id($to_userid);
}
/**
* Calculate whether a private message was unread using the bitfield
*/
function phpbb_unread_pm($pm_type)
{
return ($pm_type == 5) ? 1 : 0;
}
/**
* Calculate whether a private message was new using the bitfield
*/
function phpbb_new_pm($pm_type)
{
return ($pm_type == 1) ? 1 : 0;
}
/**
* Obtain the folder_id for the custom folder created to replace the savebox from 2.0.x (used to store saved private messages)
*/
function phpbb_get_savebox_id($user_id)
{
global $db;
$user_id = phpbb_user_id($user_id);
// Only one custom folder, check only one
$sql = 'SELECT folder_id
FROM ' . PRIVMSGS_FOLDER_TABLE . '
WHERE user_id = ' . $user_id;
$result = $db->sql_query_limit($sql, 1);
$folder_id = (int) $db->sql_fetchfield('folder_id');
$db->sql_freeresult($result);
return $folder_id;
}
/**
* Transfer attachment specific configuration options
* These were not stored in the main config table on 2.0.x
* This is only used if the Attachment MOD was installed
*/
function phpbb_import_attach_config()
{
global $db, $src_db, $same_db, $convert, $config;
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'binary'");
}
$sql = 'SELECT *
FROM ' . $convert->src_table_prefix . 'attachments_config';
$result = $src_db->sql_query($sql);
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'utf8'");
}
$attach_config = array();
while ($row = $src_db->sql_fetchrow($result))
{
$attach_config[$row['config_name']] = $row['config_value'];
}
$src_db->sql_freeresult($result);
set_config('allow_attachments', 1);
// old attachment mod? Must be very old if this entry do not exist...
if (!empty($attach_config['display_order']))
{
set_config('display_order', $attach_config['display_order']);
}
set_config('max_filesize', $attach_config['max_filesize']);
set_config('max_filesize_pm', $attach_config['max_filesize_pm']);
set_config('attachment_quota', $attach_config['attachment_quota']);
set_config('max_attachments', $attach_config['max_attachments']);
set_config('max_attachments_pm', $attach_config['max_attachments_pm']);
set_config('allow_pm_attach', $attach_config['allow_pm_attach']);
set_config('img_display_inlined', $attach_config['img_display_inlined']);
set_config('img_max_width', $attach_config['img_max_width']);
set_config('img_max_height', $attach_config['img_max_height']);
set_config('img_link_width', $attach_config['img_link_width']);
set_config('img_link_height', $attach_config['img_link_height']);
set_config('img_create_thumbnail', $attach_config['img_create_thumbnail']);
set_config('img_max_thumb_width', 400);
set_config('img_min_thumb_filesize', $attach_config['img_min_thumb_filesize']);
set_config('img_imagick', $attach_config['img_imagick']);
}
/**
* Calculate the date a user became inactive
*/
function phpbb_inactive_time()
{
global $convert_row;
if ($convert_row['user_active'])
{
return 0;
}
if ($convert_row['user_lastvisit'])
{
return $convert_row['user_lastvisit'];
}
return $convert_row['user_regdate'];
}
/**
* Calculate the reason a user became inactive
* We can't actually tell the difference between a manual deactivation and one for profile changes
* from the data available to assume the latter
*/
function phpbb_inactive_reason()
{
global $convert_row;
if ($convert_row['user_active'])
{
return 0;
}
if ($convert_row['user_lastvisit'])
{
return INACTIVE_PROFILE;
}
return INACTIVE_REGISTER;
}
/**
* Adjust 2.0.x disallowed names to 3.0.x format
*/
function phpbb_disallowed_username($username)
{
// Replace * with %
$username = phpbb_set_default_encoding(str_replace('*', '%', $username));
return utf8_htmlspecialchars($username);
}
?>
|