1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @name OpenImporter |
4
|
|
|
* @copyright OpenImporter contributors |
5
|
|
|
* @license BSD https://opensource.org/licenses/BSD-3-Clause |
6
|
|
|
* |
7
|
|
|
* @version 1.0 |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class SMF2_0 |
12
|
|
|
*/ |
13
|
|
|
class SMF2_0 extends Importers\AbstractSourceImporter |
14
|
|
|
{ |
15
|
|
|
protected $setting_file = '/Settings.php'; |
16
|
|
|
|
17
|
|
|
public function getName() |
18
|
|
|
{ |
19
|
|
|
return 'SMF2_0'; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function getVersion() |
23
|
|
|
{ |
24
|
|
|
return 'Wedge 0.1'; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function setDefines() |
28
|
|
|
{ |
29
|
|
|
if (!defined('SMF')) |
30
|
|
|
{ |
31
|
|
|
define('SMF', 1); |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function getPrefix() |
36
|
|
|
{ |
37
|
|
|
$db_name = $this->getDbName(); |
38
|
|
|
$db_prefix = $this->fetchSetting('db_prefix'); |
39
|
|
|
return '`' . $db_name . '`.' . $db_prefix; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getDbName() |
43
|
|
|
{ |
44
|
|
|
return $this->fetchSetting('db_name'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getTableTest() |
48
|
|
|
{ |
49
|
|
|
return 'members'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function fetchSetting($name) |
53
|
|
|
{ |
54
|
|
|
static $content = null; |
55
|
|
|
|
56
|
|
|
if ($content === null) |
57
|
|
|
$content = file_get_contents($this->path . '/Settings.php'); |
58
|
|
|
|
59
|
|
|
$match = array(); |
60
|
|
|
preg_match('~\$' . $name . '\s*=\s*\'(.*?)\';~', $content, $match); |
61
|
|
|
|
62
|
|
|
return isset($match[1]) ? $match[1] : ''; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
// Utility functions specific to phpbb |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param $row |
70
|
|
|
* @param $db |
71
|
|
|
* @param $from_prefix |
72
|
|
|
* @param $attachmentUploadDir |
73
|
|
|
*/ |
74
|
|
|
function moveAttachment($row, $db, $from_prefix, $attachmentUploadDir) |
75
|
|
|
{ |
76
|
|
|
static $smf_folders = null; |
77
|
|
|
|
78
|
|
|
if ($smf_folders === null) |
79
|
|
|
{ |
80
|
|
|
$request = $db->query(" |
81
|
|
|
SELECT value |
82
|
|
|
FROM {$from_prefix}settings |
83
|
|
|
WHERE variable='attachmentUploadDir';"); |
84
|
|
|
list ($smf_attachments_dir) = $db->fetch_row($request); |
85
|
|
|
|
86
|
|
|
$smf_folders = @unserialize($smf_attachments_dir); |
87
|
|
|
if (!is_array($smf_folders)) |
88
|
|
|
$smf_folders = array(1 => $smf_attachments_dir); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$smf_attachments_dir = $smf_folders[$row['id_folder']]; |
92
|
|
|
|
93
|
|
|
if (empty($row['file_hash'])) |
94
|
|
|
{ |
95
|
|
|
$row['file_hash'] = createAttachmentFileHash($row['filename']); |
96
|
|
|
$source_file = $row['filename']; |
97
|
|
|
} |
98
|
|
|
else |
99
|
|
|
$source_file = $row['id_attach'] . '_' . $row['file_hash']; |
100
|
|
|
|
101
|
|
|
copy_file($smf_attachments_dir . '/' . $source_file, $attachmentUploadDir . '/' . $row['id_attach'] . '_' . $row['file_hash'] . '.elk'); |
102
|
|
|
} |