-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.php
3253 lines (2776 loc) · 98.9 KB
/
convert.php
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
<?php
/**********************************************************************************
* convert.php *
***********************************************************************************
* SMF: Simple Machines Forum *
* Open-Source Project Inspired by Zef Hemel ([email protected]) *
* =============================================================================== *
* Software Version: SMF 2.0 *
* Software by: Simple Machines (http://www.simplemachines.org) *
* Copyright 2006-2010 by: Simple Machines LLC (http://www.simplemachines.org) *
* 2001-2006 by: Lewis Media (http://www.lewismedia.com) *
* Support, News, Updates at: http://www.simplemachines.org *
***********************************************************************************
* This program is free software; you may redistribute it and/or modify it under *
* the terms of the provided license as published by Simple Machines LLC. *
* *
* This program is distributed in the hope that it is and will be useful, but *
* WITHOUT ANY WARRANTIES; without even any implied warranty of MERCHANTABILITY *
* or FITNESS FOR A PARTICULAR PURPOSE. *
* *
* See the "license.txt" file for details of the Simple Machines license. *
* The latest version can always be found at http://www.simplemachines.org. *
**********************************************************************************/
define('SMF', 'convert');
error_reporting(E_ALL);
$GLOBALS['required_php_version'] = '4.1.0';
$GLOBALS['required_mysql_version'] = '3.23.28';
$GLOBALS['required_postgresql_version'] = '7.4.10';
// Buy some time
@set_time_limit(600);
// When in debug mode, we log our errors. Request hasn't been properly setup yet though.
if (isset($_GET['debug']) || isset($_POST['debug']))
set_error_handler('convert_error_handler');
// We now have CLI support.
if ((php_sapi_name() == 'cli' || (isset($_SERVER['TERM']) && $_SERVER['TERM'] == 'xterm')) && empty($_SERVER['REMOTE_ADDR']))
{
$command_line = true;
cmdStep0();
exit;
}
else
{
$command_line = false;
initialize_inputs();
}
if (!empty($_GET['step']))
$current_step = $_GET['step'];
template_convert_above();
if (!empty($_GET['step']) && ($_GET['step'] == 1 || $_GET['step'] == 2))
echo '
<div class="panel">
<h2>Converting...</h2>';
if (function_exists('doStep' . $_GET['step']))
call_user_func('doStep' . $_GET['step']);
if (!empty($_GET['step']) && ($_GET['step'] == 1 || $_GET['step'] == 2))
echo '
</div>';
template_convert_below();
function initialize_inputs()
{
global $sourcedir, $smcFunc;
$smcFunc = array();
// Save here so it doesn't get overwritten when sessions are restarted.
$convert_script = @$_REQUEST['convert_script'];
// Clean up after unfriendly php.ini settings.
if (function_exists('set_magic_quotes_runtime'))
@set_magic_quotes_runtime(0);
error_reporting(E_ALL);
ignore_user_abort(true);
umask(0);
@ob_start();
if (@ini_get('session.save_handler') == 'user')
@ini_set('session.save_handler', 'files');
@session_start();
// Add slashes, as long as they aren't already being added.
if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0)
$_POST = convert_stripslashes_recursive($_POST);
// This is really quite simple; if ?delete is on the URL, delete the converter...
if (isset($_GET['delete']))
{
@unlink(dirname(__FILE__) . '/convert_error_log');
@unlink(__FILE__);
if (preg_match('~_to_smf\.(php|sql)$~', $_SESSION['convert_script']) != 0)
@unlink(dirname(__FILE__) . '/' . $_SESSION['convert_script']);
$_SESSION['convert_script'] = null;
exit;
}
// Empty the error log?
if (isset($_REQUEST['empty_error_log']))
{
unset($_REQUEST['empty_error_log']);
@unlink(dirname(__FILE__) . '/convert_error_log');
}
// The current step - starts at 0.
$_GET['step'] = (int) @$_GET['step'];
$_REQUEST['start'] = (int) @$_REQUEST['start'];
// Check for the password...
if (isset($_POST['db_pass']))
$_SESSION['convert_db_pass'] = $_POST['db_pass'];
elseif (isset($_SESSION['convert_db_pass']))
$_POST['db_pass'] = $_SESSION['convert_db_pass'];
if (isset($_SESSION['convert_paths']) && !empty($_SESSION['convert_paths'][0]) && !empty($_SESSION['convert_paths'][1]) && !isset($_POST['path_from']) && !isset($_POST['path_to']))
list ($_POST['path_from'], $_POST['path_to']) = $_SESSION['convert_paths'];
elseif (isset($_POST['path_from']) || isset($_POST['path_to']))
{
if (isset($_POST['path_from']))
$_POST['path_from'] = substr($_POST['path_from'], -1) == '/' ? substr($_POST['path_from'], 0, -1) : $_POST['path_from'];
if (isset($_POST['path_to']))
$_POST['path_to'] = substr($_POST['path_to'], -1) == '/' ? substr($_POST['path_to'], 0, -1) : $_POST['path_to'];
$_SESSION['convert_paths'] = array(@$_POST['path_from'], @$_POST['path_to']);
}
// If we have $convert_script then set it to the session.
if (!empty($convert_script))
$_SESSION['convert_script'] = $convert_script;
if (isset($_SESSION['convert_script']) && file_exists(dirname(__FILE__) . '/' . $_SESSION['convert_script']) && preg_match('~_to_smf\.(php|sql)$~', $_SESSION['convert_script']) != 0)
{
if (substr($_SESSION['convert_script'], -4) == '.php')
preparse_php(dirname(__FILE__) . '/' . $_SESSION['convert_script']);
else
preparse_sql(dirname(__FILE__) . '/' . $_SESSION['convert_script']);
}
else
unset($_SESSION['convert_script']);
}
function preparse_sql($script_filename)
{
global $convert_data;
$fp = fopen($script_filename, 'r');
$data = fread($fp, 4096);
fclose($fp);
$convert_data['parameters'] = array();
// This loads name, settings, table_test, from_prefix, defines, and globals.
preg_match_all('~---\~ ([^:]+):\s*(.+?)\s*\n~', $data, $matches);
for ($i = 0, $n = count($matches[1]); $i < $n; $i++)
{
// String value?
if (in_array($matches[1][$i], array('name', 'table_test', 'from_prefix', 'version', 'database_type', 'block_size', 'step2_block_size')))
$convert_data[$matches[1][$i]] = stripslashes(substr(trim($matches[2][$i]), 1, -1));
// Maybe it is a eval statement?
elseif ($matches[1][$i] == 'eval')
$convert_data['eval'][] = $matches[2][$i];
// No... so it must be an array.
else
{
if (strpos($matches[2][$i], '"') === false)
preg_match_all('~()([^,]+?)(,|$)~', trim($matches[2][$i]), $values);
else
preg_match_all('~(")?([^,]+?)\\1(,|$)~', trim($matches[2][$i]), $values);
if (!isset($convert_data[$matches[1][$i]]))
$convert_data[$matches[1][$i]] = array();
$convert_data[$matches[1][$i]] = array_merge($convert_data[$matches[1][$i]], $values[2]);
}
}
if (empty($convert_data['defines']))
$convert_data['defines'] = array();
if (empty($convert_data['globals']))
$convert_data['globals'] = array();
if (empty($convert_data['settings']))
$convert_data['settings'] = array();
if (empty($convert_data['variable']))
$convert_data['variable'] = array();
if (empty($convert_data['database_support']))
$convert_data['database_support'] = array('mysql');
// Merge all eval statements together.
if (!empty($convert_data['eval']))
$convert_data['eval'] = implode("\r", $convert_data['eval']);
if (!empty($convert_data['parameters']))
{
foreach ($convert_data['parameters'] as $i => $param)
{
if (is_array($param))
continue;
list ($id, $label) = explode('=', $param);
if (strpos($id, ' ') !== false)
list ($id, $type) = explode(' ', $id);
else
$type = 'text';
$convert_data['parameters'][$i] = array(
'id' => $id,
'label' => $label,
'type' => $type,
);
$convert_data['globals'][] = $id;
}
}
foreach ($convert_data['globals'] as $k => $v)
{
$v = trim($v);
$convert_data['globals'][$k] = $v[0] == '$' ? substr($v, 1) : $v;
}
if (isset($_POST['path_to']) && !empty($_GET['step']))
loadSettings();
}
function preparse_php($script_filename)
{
global $convert_data;
$preparsing = true;
require($script_filename);
if (empty($convert_data['parameters']))
$convert_data['parameters'] = array();
if (empty($convert_data['defines']))
$convert_data['defines'] = array();
if (empty($convert_data['globals']))
$convert_data['globals'] = array();
if (empty($convert_data['settings']))
$convert_data['settings'] = array();
if (empty($convert_data['variable']))
$convert_data['variable'] = array();
if (empty($convert_data['database_support']))
$convert_data['database_support'] = array('mysql');
foreach ($convert_data['globals'] as $k => $v)
{
$v = trim($v);
$convert_data['globals'][$k] = $v[0] == '$' ? substr($v, 1) : $v;
}
if (isset($_POST['path_to']) && !empty($_GET['step']))
loadSettings();
}
function loadSettings()
{
global $convert_data, $from_prefix, $to_prefix, $convert_dbs, $command_line, $smcFunc;
global $db_persist, $db_connection, $db_server, $db_user, $db_passwd, $modSettings;
global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix;
foreach ($convert_data['defines'] as $define)
{
$define = explode('=', $define);
define($define[0], isset($define[1]) ? $define[1] : '1');
}
foreach ($convert_data['globals'] as $global)
global $$global;
define('PATH_CACHE', 'PATH_CACHE');
if (!empty($convert_data['eval']))
eval($convert_data['eval']);
// Cannot find Settings.php?
if (!$command_line && !file_exists($_POST['path_to'] . '/Settings.php'))
{
template_convert_above();
return doStep0('This converter was unable to find SMF in the path you specified.<br /><br />Please double check the path, and that it is already installed there.');
}
elseif ($command_line && !file_exists($_POST['path_to'] . '/Settings.php'))
return print_error('This converter was unable to find SMF in the path you specified.<br /><br />Please double check the path, and that it is already installed there.', true);
$found = empty($convert_data['settings']);
foreach ($convert_data['settings'] as $file)
$found |= file_exists($_POST['path_from'] . $file);
/*
Check if open_basedir is enabled. If it's enabled and the converter file was not found then that means
that the user hasn't moved the files to the public html dir. With this enabled and the file not found, we can't go anywhere from here.
*/
if (!$command_line && @ini_get('open_basedir') != '' && !$found)
{
template_convert_above();
return doStep0('The converter detected that your host has open_basedir enabled on this server. Please ask your host to disable this setting or try moving the contents of your ' . $convert_data['name'] . ' to the public html folder of your site.');
}
elseif ($command_line && @ini_get('open_basedir') != '' && !$found)
return print_error('The converter detected that your host has open_basedir enabled on this server. Please ask your host to disable this setting or try moving the contents of your ' . $convert_data['name'] . ' to the public html folder of your site.', true);
if (!$command_line && !$found)
{
template_convert_above();
return doStep0('Unable to find the settings for ' . $convert_data['name'] . '. Please double check the path and try again.');
}
elseif (!$command_line && !$found)
return print_error('Unable to find the settings for ' . $convert_data['name'] . '. Please double check the path and try again.', true);
// Any parameters to speak of?
if (!empty($convert_data['parameters']) && !empty($_SESSION['convert_parameters']))
{
foreach ($convert_data['parameters'] as $param)
{
if (isset($_POST[$param['id']]))
$_SESSION['convert_parameters'][$param['id']] = $_POST[$param['id']];
}
// Should already be global'd.
foreach ($_SESSION['convert_parameters'] as $k => $v)
$$k = $v;
}
elseif (!empty($convert_data['parameters']))
{
$_SESSION['convert_parameters'] = array();
foreach ($convert_data['parameters'] as $param)
{
if (isset($_POST[$param['id']]))
$_SESSION['convert_parameters'][$param['id']] = $_POST[$param['id']];
else
$_SESSION['convert_parameters'][$param['id']] = null;
}
foreach ($_SESSION['convert_parameters'] as $k => $v)
$$k = $v;
}
// Everything should be alright now... no cross server includes, we hope...
require($_POST['path_to'] . '/Settings.php');
require($sourcedir . '/QueryString.php');
require($sourcedir . '/Subs.php');
require($sourcedir . '/Errors.php');
require($sourcedir . '/Load.php');
require($sourcedir . '/Security.php');
// PHP4 users compatibility
if (@version_compare(PHP_VERSION, '5') == -1)
require_once($sourcedir . '/Subs-Compat.php');
$GLOBALS['boardurl'] = $boardurl;
$modSettings['disableQueryCheck'] = true; // !!! Do we really need this?
if (!$command_line && $_SESSION['convert_db_pass'] != $db_passwd)
{
template_convert_above();
return doStep0('The database password you entered was incorrect. Please make sure you are using the right password (for the SMF user!) and try it again. If in doubt, use the password from Settings.php in the SMF installation.');
}
elseif ($command_line && $_SESSION['convert_db_pass'] != $db_passwd)
return print_error('The database password you entered was incorrect. Please make sure you are using the right password (for the SMF user!) and try it again. If in doubt, use the password from Settings.php in the SMF installation.', true);
// Check the steps that we have decided to go through.
if (!$command_line && isset($_POST['do_steps']) && empty($_POST['do_steps']))
{
template_convert_above();
return doStep0('You must select at least one step to convert.');
}
elseif (!$command_line && isset($_POST['do_steps']))
{
unset($_SESSION['do_steps']);
foreach ($_POST['do_steps'] as $next_step_line => $step)
{
//$explode = explode(',', $step);
//$_SESSION['do_steps'][$key] = array(
// 'cur_step_line' => $explode[0],
// 'prev_step_line' => $explode[1],
// 'next_prev_line' => $explode[2],
//);
$_SESSION['do_steps'][$next_step_line] = $step;
}
}
if (isset($_SESSION['convert_parameters']['database_type']) && !isset($convert_data['database_type']))
$convert_data['database_type'] = $_SESSION['convert_parameters']['database_type'];
if (isset($convert_data['database_type']) && (function_exists($convert_data['database_type'] . '_query') || function_exists($convert_data['database_type'] . '_exec') || ($convert_data['database_type'] == 'ado' && class_exists('com'))))
{
$convert_dbs = $convert_data['database_type'];
if (isset($convert_data['connect_string']))
$connect_string = eval('return "' . $convert_data['connect_string'] . '";');
elseif (isset($_SESSION['convert_parameters']['connect_string']))
$connect_string = $_SESSION['convert_parameters']['connect_string'];
if ($convert_dbs == 'odbc')
$GLOBALS['odbc_connection'] = odbc_connect($connect_string, '', '');
elseif ($convert_dbs == 'ado')
{
$GLOBALS['ado_connection'] = new COM('ADODB.Connection');
$GLOBALS['ado_connection']->Open($connect_string);
register_shutdown_function(create_function('', '$GLOBALS[\'ado_connection\']->Close();'));
}
}
elseif (!$command_line && isset($convert_data['database_type']))
{
template_convert_above();
return doStep0('PHP doesn\'t support the database type this converter was written for, \'' . $convert_data['database_type'] . '\'.');
}
elseif ($command_line && isset($convert_data['database_type']))
return print_error('PHP doesn\'t support the database type this converter was written for, \'' . $convert_data['database_type'] . '\'.', true);
else
$convert_dbs = 'smf_db';
// Create a connection to the SMF database.
loadDatabase();
db_extend('packages');
// Currently SQLite and PostgreSQL do not have support for cross database work.
if ($command_line && in_array($smcFunc['db_title'], array('SQLite', 'PostgreSQL')))
return print_error('The converter detected that you are using ' . $smcFunc['db_title'] . '. The SMF Converter does not currently support this database type.', true);
elseif (in_array($smcFunc['db_title'], array('SQLite', 'PostgreSQL')))
{
template_convert_above();
return doStep0('The converter detected that you are using ' . $smcFunc['db_title'] . '. The SMF Converter does not currently support this database type.');
}
// Does this converter support the current database type being used?
if ($command_line && !in_array(strtolower($smcFunc['db_title']), $convert_data['database_support']))
return print_error('The converter detected that you are using ' . $smcFunc['db_title'] . '. This converter only supports ' . explode (', ', $convert_data['database_support']) . '.', true);
elseif (!in_array(strtolower($smcFunc['db_title']), $convert_data['database_support']))
{
template_convert_above();
return print_error('The converter detected that you are using ' . $smcFunc['db_title'] . '. This converter only supports ' . explode (', ', $convert_data['database_support']) . '.', true);
}
// UTF8
$charset = findSupportedCharsets();
$charset = array_flip($charset);
$charset = isset($_POST['charsets']) && isset($charset[$_POST['charsets']]) ? $_POST['charsets'] : '';
$charset = !empty($charset) ? $charset : (isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1 ? $db_character_set : '');
if (!empty($charset))
$smcFunc['db_query']('', "SET NAMES $charset", 'security_override');
if (strpos($db_prefix, '.') === false)
$to_prefix = is_numeric(substr($db_prefix, 0, 1)) ? $db_name . '.' . $db_prefix : '`' . $db_name . '`.' . $db_prefix;
else
$to_prefix = $db_prefix;
// Keep in mind our important variables, we don't want them swept away by the code we're running
$smf_db_prefix = $db_prefix;
$smf_db_type = $db_type;
foreach ($convert_data['variable'] as $eval_me)
eval($eval_me);
foreach ($convert_data['settings'] as $file)
{
if (file_exists($_POST['path_from'] . $file) && empty($convert_data['flatfile']))
require_once($_POST['path_from'] . $file);
}
if (isset($convert_data['from_prefix']))
$from_prefix = eval('return "' . fixDbPrefix($convert_data['from_prefix'], $smcFunc['db_title']) . '";');
if (preg_match('~^`[^`]+`.\d~', $from_prefix) != 0)
$from_prefix = strtr($from_prefix, array('`' => ''));
// recall our variables in case the software we're converting from defines one itself...
$db_prefix = $smf_db_prefix;
$db_type = $smf_db_type;
if ($_REQUEST['start'] == 0 && empty($_GET['substep']) && empty($_GET['cstep']) && ($_GET['step'] == 1 || $_GET['step'] == 2) && isset($convert_data['table_test']))
{
$result = convert_query("
SELECT COUNT(*)
FROM " . eval('return "' . $convert_data['table_test'] . '";'), true);
if (!$command_line && $result === false)
{
template_convert_above();
doStep0('Sorry, the database connection information used in the specified installation of SMF cannot access the installation of ' . $convert_data['name'] . '. This may either mean that the installation doesn\'t exist, or that the Database account used does not have permissions to access it.<br /><br />The error that was received from the Database was: ' . $smcFunc['db_error']());
}
elseif ($command_line && $result === false)
print_error("Sorry, the database connection information used in the specified installation of SMF cannot access the installation of " . $convert_data['name'] . ". This may either mean that the installation doesn\'t exist, or that the Database account used does not have permissions to access it.\n\nThe error that was received from the Database: " . $smcFunc['db_error'](), true);
convert_free_result($result);
}
// Attempt to allow big selects, only for mysql so far though.
if ($smcFunc['db_title'] == 'MySQL')
{
$results = $smcFunc['db_query']('', "SELECT @@SQL_BIG_SELECTS, @@SQL_MAX_JOIN_SIZE", 'security_override');
list($big_selects, $sql_max_join) = $smcFunc['db_fetch_row']($results);
// Only waste a query if its worth it.
if (empty($big_selects) || ($big_selects != 1 && $big_selects != '1'))
$smcFunc['db_query']('', "SET @@SQL_BIG_SELECTS = 1", 'security_override');
// Lets set MAX_JOIN_SIZE to something we should
if (empty($sql_max_join) || ($sql_max_join == '18446744073709551615' && $sql_max_join == '18446744073709551615'))
$smcFunc['db_query']('', "SET @@SQL_MAX_JOIN_SIZE = 18446744073709551615", 'security_override');
}
// Since we use now the attachment functions in Subs.php, we'll need this:
$result = convert_query("
SELECT value
FROM {$to_prefix}settings
WHERE variable = 'attachmentUploadDir'
LIMIT 1");
list($attachmentUploadDir) = $smcFunc['db_fetch_row']($result);
$modSettings['attachmentUploadDir'] = $attachmentUploadDir;
$smcFunc['db_free_result']($result);
}
function findConvertScripts()
{
global $convert_data;
if (isset($_REQUEST['convert_script']))
{
if ($_REQUEST['convert_script'] != '' && preg_match('~^[a-z0-9\-_\.]*_to_smf\.(sql|php)$~i', $_REQUEST['convert_script']) != 0)
{
$_SESSION['convert_script'] = preg_replace('~[\.]+~', '.', $_REQUEST['convert_script']);
if (substr($_SESSION['convert_script'], -4) == '.php')
preparse_php(dirname(__FILE__) . '/' . $_SESSION['convert_script']);
else
preparse_sql(dirname(__FILE__) . '/' . $_SESSION['convert_script']);
}
else
$_SESSION['convert_script'] = null;
}
$preparsing = true;
$dir = dir(dirname(__FILE__));
$scripts = array();
while ($entry = $dir->read())
{
if (substr($entry, -11) != '_to_smf.sql' && substr($entry, -11) != '_to_smf.php')
continue;
$fp = fopen(dirname(__FILE__) . '/' . $entry, 'r');
$data = fread($fp, 4096);
fclose($fp);
if (substr($entry, -11) == '_to_smf.sql')
{
if (preg_match('~---\~ name:\s*"(.+?)"~', $data, $match) != 0)
$scripts[] = array('path' => $entry, 'name' => $match[1]);
}
elseif (substr($entry, -11) == '_to_smf.php')
{
if (preg_match('~\$convert_data =~', $data) != 0)
{
require(dirname(__FILE__) . '/' . $entry);
$scripts[] = array('path' => $entry, 'name' => $convert_data['name']);
}
}
}
$dir->close();
if (isset($_SESSION['convert_script']))
{
if (count($scripts) > 1)
$GLOBALS['possible_scripts'] = $scripts;
return false;
}
if (count($scripts) == 1)
{
$_SESSION['convert_script'] = basename($scripts[0]['path']);
if (substr($_SESSION['convert_script'], -4) == '.php')
preparse_php(dirname(__FILE__) . '/' . $_SESSION['convert_script']);
else
preparse_sql(dirname(__FILE__) . '/' . $_SESSION['convert_script']);
return false;
}
echo '
<div class="panel">
<h2>Which software are you using?</h2>';
if (!empty($scripts))
{
echo '
<h3>The converter found multiple conversion data files. Please choose the one you wish to use.</h3>
<ul>';
foreach ($scripts as $script)
echo '
<li><a href="', $_SERVER['PHP_SELF'], '?convert_script=', $script['path'], '">', $script['name'], '</a> <em>(', $script['path'], ')</em></li>';
echo '
</ul>
<h2>It\'s not here!</h2>
<h3>If the software you\'re looking for doesn\'t appear above, please check to see if it is available for download at <a href="http://www.simplemachines.org/">www.simplemachines.org</a>. If it isn\'t, we may be able to write one for you - just ask us!</h3>
If you\'re having any other problems with this converter, don\'t hesitate to look for help on our <a href="http://www.simplemachines.org/community/index.php">forum</a>.';
}
else
{
echo '
<h3>The converter did not find any conversion data files. Please check to see if the one you want is available for download at <a href="http://www.simplemachines.org/">www.simplemachines.org</a>. If it isn\'t, we may be able to write one for you - just ask us!</h3>
After you download it, simply upload it into the same folder as <strong>this convert.php file</strong>. If you\'re having any other problems with this converter, don\'t hesitate to look for help on our <a href="http://www.simplemachines.org/community/index.php">forum</a>.<br />
<br />
<a href="', $_SERVER['PHP_SELF'], '?convert_script=">Try again</a>';
}
echo '
</div>';
return true;
}
// Looks at the converter and returns the steps that it's able to make.
function findSteps()
{
global $current_type, $convert_data;
// No file?
if (empty($_SESSION['convert_script']))
return array();
$steps = array();
$count_steps = 1;
// Can we support php files?
if (substr($_SESSION['convert_script'], -4) == '.php')
{
// Load the file.
if (empty($convert_data))
{
$preparsing = true;
require(dirname(__FILE__) . '/' . $_SESSION['convert_script']);
}
if (!empty($convert_data['steps']))
return $convert_data['steps'];
elseif (!empty($convert_data['num_steps']))
{
$i = 1;
while ($i <= $convert_data['num_steps'])
{
$steps[$count_steps] = array(
'name' => 'SubStep #' . $i,
'cur_step_line' => $i,
'prev_step_line' => $i - 1,
'next_step_line' => $i + 1,
'count' => $count_steps++,
);
++$i;
}
return $steps;
}
}
// Load the file.
$lines = file(dirname(__FILE__) . '/' . $_SESSION['convert_script']);
// Need an outside counter for the steps.
foreach ($lines as $line_number => $line)
{
// Get rid of any comments in the beginning of the line...
if (substr(trim($line), 0, 2) === '/*')
$line = preg_replace('~/\*.+?\*/~', '', $line);
if (trim($line) === '')
continue;
// We found the treasure :P.
if (substr($line, 0, 4) === '--- ')
{
$steps[$count_steps] = array(
'name' => trim(substr(htmlspecialchars($line), 4)),
'cur_step_line' => $line_number,
'prev_step_line' => 0,
'next_step_line' => 0,
'count' => $count_steps,
);
// Previous step line number.
if (isset($steps[$count_steps - 1]))
{
$steps[$count_steps]['prev_step_line'] = $steps[$count_steps - 1]['cur_step_line'];
$steps[$count_steps - 1]['next_step_line'] = $line_number;
}
$count_steps++;
}
else
continue;
}
return $steps;
}
function findSupportedCharsets()
{
global $smcFunc;
// Just assume these.
if ($smcFunc['db_title'] == 'SQLite')
return $charsets = array(
'ISO-8859-1' => 'latin1',
'UTF-8' => 'utf8',
);
// The character sets used in SMF's language files with their db equivalent.
$charsets = array(
// Chinese-traditional.
'big5' => 'big5',
// Chinese-simplified.
'gbk' => 'gbk',
// West European.
'ISO-8859-1' => 'latin1',
// Romanian.
'ISO-8859-2' => 'latin2',
// Turkish.
'ISO-8859-9' => 'latin5',
// West European with Euro sign.
'ISO-8859-15' => 'latin9',
// Thai.
'tis-620' => 'tis620',
// Persian, Chinese, etc.
'UTF-8' => 'utf8',
// Russian.
'windows-1251' => 'cp1251',
// Greek.
'windows-1253' => 'utf8',
// Hebrew.
'windows-1255' => 'utf8',
// Arabic.
'windows-1256' => 'cp1256',
);
// Get a list of character sets supported by your Database server.
$result = @$smcFunc['db_query']('', "
SHOW CHARACTER SET", 'security_override');
$db_charsets = array();
while ($row = $smcFunc['db_fetch_assoc']($result))
$db_charsets[] = $row['Charset'];
// Character sets supported by both Database and SMF's language files.
return $charsets = array_intersect($charsets, $db_charsets);
}
// Correct the prefix
function fixDbPrefix($prefix, $db_type)
{
if ($db_type == 'MySQL')
return $prefix;
elseif ($db_type == 'PostgreSQL')
{
$temp = explode('.', $prefix);
return str_replace('`', '', $temp[0] . '.public.' . $temp[1]);
}
elseif ($db_type == 'SQLite')
return str_replace(array('`', '.'), '', $prefix);
else
die('Unknown Database: ' . $db_type);
}
// Main Window
function doStep0($error_message = null)
{
global $convert_data, $current_step;
$current_step = 0;
if (findConvertScripts())
return true;
// If these aren't set (from an error..) default to the current directory.
if (!isset($_POST['path_from']))
$_POST['path_from'] = dirname(__FILE__);
if (!isset($_POST['path_to']))
$_POST['path_to'] = dirname(__FILE__);
$test_from = empty($convert_data['settings']);
foreach ($convert_data['settings'] as $s)
$test_from |= file_exists($_POST['path_from'] . $s);
$test_to = file_exists($_POST['path_to'] . '/Settings.php');
// Do we have steps?
$steps = findSteps();
// How about charater sets.
$charsets = array(
// Chinese-traditional.
'big5' => 'big5',
// Chinese-simplified.
'gbk' => 'gbk',
// West European.
'ISO-8859-1' => 'latin1',
// Romanian.
'ISO-8859-2' => 'latin2',
// Turkish.
'ISO-8859-9' => 'latin5',
// West European with Euro sign.
'ISO-8859-15' => 'latin9',
// Thai.
'tis-620' => 'tis620',
// Persian, Chinese, etc.
'UTF-8' => 'utf8',
// Russian.
'windows-1251' => 'cp1251',
// Greek.
'windows-1253' => 'utf8',
// Hebrew.
'windows-1255' => 'utf8',
// Arabic.
'windows-1256' => 'cp1256',
);
// Was an error message specified?
if ($error_message !== null)
echo '
<div class="error_message">
<div style="color: red;">', $error_message, '</div>
</div>
<br />';
echo '
<div class="panel">
<form action="', $_SERVER['PHP_SELF'], '?step=1', isset($_REQUEST['debug']) ? '&debug=' . $_REQUEST['debug'] : '', '" method="post">
<h2>Before you continue</h2>
<div style="margin-bottom: 2ex;">This converter assumes you have already installed SMF and that your installation is working properly. It copies posts and data from your "source" installation of ', $convert_data['name'], ' into SMF, so it won\'t work without an installation of SMF. All or some of the data in your installation of SMF will be <strong>overwritten</strong>.</div>';
if (empty($convert_data['flatfile']))
echo '
<div style="margin-bottom: 2ex;">If the two softwares are installed in separate directories, the Database account SMF was installed using will need access to the other database. Either way, both must be installed on the same Database server.</div>';
echo '
<h2>Where are they?</h2>
<h3>The converter should only need to know where the two installations are, after which it should be able to handle everything for itself.</h3>
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center">
<tr>
<td width="20%" valign="top" class="textbox"><label for="path_to">Path to SMF:</label></td>
<td style="padding-bottom: 1ex;">
<input type="text" name="path_to" id="path_to" value="', $_POST['path_to'], '" size="60" class="input_text" />
<div style="font-style: italic; font-size: smaller;">', $test_to ? 'This may be the right path.' : 'You will need to change the value in this box.', '</div>
</td>';
if (!empty($convert_data['settings']))
echo '
</tr><tr>
<td valign="top" class="textbox"><label for="path_from">Path to ', $convert_data['name'], ':</label></td>
<td style="padding-bottom: 1ex;">
<input type="text" name="path_from" id="path_from" value="', $_POST['path_from'], '" size="60" class="input_text" />
<div style="font-style: italic; font-size: smaller;">', $test_from ? 'This may be the right path.' : 'You will need to change the value in this box.', '</div>
</td>';
if (!empty($convert_data['parameters']))
{
foreach ($convert_data['parameters'] as $param)
{
echo '
</tr><tr>';
// Is it a checkbox?
if ($param['type'] == 'checked' || $param['type'] == 'checkbox')
echo '
<td valign="top" class="textbox"></td>
<td style="padding-bottom: 1ex;">
<input type="hidden" name="', $param['id'], '" value="0" />
<label for="', $param['id'], '"><input type="checkbox" name="', $param['id'], '" id="', $param['id'], '" value="1"', $param['type'] == 'checked' ? ' checked="checked"' : '', ' class="input_check" /> ', $param['label'], '</label>';
// How about a list?
elseif (($param['type'] == 'list' || $param['type'] == 'select') && isset($param['options']) && is_array($param['options']))
{
echo '
<td valign="top" class="textbox"></td>
<td style="padding-bottom: 1ex;">
<input type="hidden" name="', $param['id'], '" value="0" />
<label for="', $param['id'], '"><select name="', $param['id'], '" id="', $param['id'], '">';
foreach ($param['options'] as $id => $option)
echo '
<option value="', $id, '"', (isset($param['default_option']) && $param['default_option'] == $id ? ' selected="selected"' : ''), '>', $option, '</option>';
echo '
</select></label>';
}
elseif ($param['type'] == 'password')
echo '
<td valign="top" class="textbox"><label for="', $param['id'], '">', $param['label'], ':</label></td>
<td style="padding-bottom: 1ex;">
<input type="password" name="', $param['id'], '" id="', $param['id'], '" value="" size="60" class="input_password" />';
// Fall back to text.
else
echo '
<td valign="top" class="textbox"><label for="', $param['id'], '">', $param['label'], ':</label></td>
<td style="padding-bottom: 1ex;">
<input type="text" name="', $param['id'], '" id="', $param['id'], '" value="" size="60" class="input_text" />';
echo '
</td>';
}
}
echo '
</tr><tr>
<td valign="top" class="textbox" style="padding-top: 2ex;"><label for="db_pass">SMF database password:</label></td>
<td valign="top" style="padding-top: 2ex; padding-bottom: 1ex;">
<input type="password" name="db_pass" size="30" class="text input_password" />
<div style="font-style: italic; font-size: smaller;">The Database password (for verification only.)</div>
</td>
</tr>';
// Now with this UTF-8 stuff we need to work more on charsets.
if (!empty($charsets))
{
echo '
<tr>
<td valign="top" class="textbox"><label for="charsets">Set SMF\'s default character set to:</label></td>
<td valign="top" style="padding-top: 2ex; padding-bottom: 1ex;">
<select name="charsets" id="charsets">';
foreach ($charsets as $name => $id)
echo '
<option value="', $id, '"', $id == 'latin1' ? ' selected="selected"' : '', '>', $name, '</option>';
echo '
</select>
</td>
</tr>';
}
// Now for the steps.
if (!empty($steps) && 1 == 0)
{
echo '
<tr>
<td valign="top" class="textbox">Convert selected areas ONLY:</td>
<td valign="top" style="padding-top: 2ex; padding-bottom: 1ex;">';
foreach ($steps as $key => $step)
echo '
<input type="checkbox" name="do_steps[', $step['next_step_line'], ']" id="do_steps[', $step['next_step_line'], ']" value="', $step['count'], '" checked="checked" class="input_check" /><label for="do_steps[', $step['next_step_line'], ']">', ucfirst(str_replace('Converting ', '', $step['name'])), '</label><br />';
echo '
</td>
</tr>';
}
// Empty our error log?
echo '
</tr><tr>
<td valign="top" class="textbox" style="padding-top: 2ex;"><label for="empty_error_log">Empty the convert error log?</label></td>
<td valign="top" style="padding-top: 2ex; padding-bottom: 1ex;">
<input type="checkbox" name="empty_error_log" value="1" class="input_check" />
</td>
</tr>';
echo '
</table>
<div class="righttext" style="margin: 1ex; margin-top: 0;"><input name="b" type="submit" value="Continue" class="submit button_submit" /></div>
</form>
</div>';
if (!empty($GLOBALS['possible_scripts']))
echo '
<div class="panel">
<h2>Not this software?</h2>
<h3>If this is the wrong software, you can go back and <a href="', $_SERVER['PHP_SELF'], '?convert_script=">pick a different data file</a>.</h3>
</div>';
if ($error_message !== null)
{
template_convert_below();
exit;
}
return;
}
// Do the main step.
function doStep1()
{
global $from_prefix, $to_prefix, $convert_data, $command_line, $smcFunc, $modSettings;
global $current_step, $current_substep, $last_step;
$current_step = 1;
if (substr($_SESSION['convert_script'], -4) == '.php')
return run_php_converter();
foreach ($convert_data['globals'] as $global)
global $$global;
$_GET['substep'] = (int) @$_GET['substep'];
// In CLI we end lines differently.
$endl = $command_line ? "\n" : '<br />' . "\n";
// Staring the converter.
if ($command_line)
print_line($endl . 'Starting Conversion');
$lines = file(dirname(__FILE__) . '/' . $_SESSION['convert_script']);