|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @name OpenImporter |
|
4
|
|
|
* @copyright OpenImporter contributors |
|
5
|
|
|
* @license BSD http://opensource.org/licenses/BSD-3-Clause |
|
6
|
|
|
* |
|
7
|
|
|
* @version 1.0 Alpha |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class XenForo1_4 |
|
12
|
|
|
*/ |
|
13
|
|
|
class XenForo1_4 extends Importers\AbstractSourceImporter |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
protected $setting_file = '/library/config.php'; |
|
16
|
|
|
|
|
17
|
|
|
public function getName() |
|
18
|
|
|
{ |
|
19
|
|
|
return 'XenForo 1.4'; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function getVersion() |
|
23
|
|
|
{ |
|
24
|
|
|
return 'ElkArte 1.0'; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function getPrefix() |
|
28
|
|
|
{ |
|
29
|
|
|
$db_name = $this->getDbName(); |
|
30
|
|
|
|
|
31
|
|
|
// Seems to only be xf_ in recent versions |
|
32
|
|
|
$db_prefix = 'xf_'; |
|
33
|
|
|
|
|
34
|
|
|
return '`' . $db_name . '`.' . $db_prefix; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getDbName() |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->fetchSetting('dbname'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function getTableTest() |
|
43
|
|
|
{ |
|
44
|
|
|
return 'user'; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
protected function fetchSetting($name) |
|
48
|
|
|
{ |
|
49
|
|
|
static $content = null; |
|
50
|
|
|
|
|
51
|
|
|
if ($content === null) |
|
52
|
|
|
{ |
|
53
|
|
|
$content = file_get_contents($this->path . $this->setting_file); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$match = array(); |
|
57
|
|
|
preg_match('~\$config\[\'db\'\]\[\'' . $name . '\'\]\s*=\s*\'(.*?)\';~', $content, $match); |
|
58
|
|
|
|
|
59
|
|
|
return isset($match[1]) ? $match[1] : ''; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function xen_copy_files($dir, $row, $id_attach, $destination_path, $thumb = false) |
|
63
|
|
|
{ |
|
64
|
|
|
// Extra details |
|
65
|
|
|
list($ext, $basename, $mime_type) = attachment_type($row['filename']); |
|
66
|
|
|
|
|
67
|
|
|
// Prep for the copy |
|
68
|
|
|
$file = xen_attach_filename($row) . ($thumb ? '.' . $ext : '.data'); |
|
69
|
|
|
$source = $dir . '/' . $file; |
|
70
|
|
|
$file_hash = createAttachmentFileHash($file); |
|
71
|
|
|
$destination = $destination_path . '/' . $id_attach . '_' . $file_hash . '.elk'; |
|
72
|
|
|
$type = 0; |
|
73
|
|
|
|
|
74
|
|
|
// Copy it over |
|
75
|
|
|
copy_file($source, $destination); |
|
76
|
|
|
|
|
77
|
|
|
// If its an image, then make sure it has legit width/height |
|
78
|
|
|
if (!empty($ext)) |
|
79
|
|
|
{ |
|
80
|
|
|
list ($width) = getimagesize($destination); |
|
81
|
|
|
if (!empty($width)) |
|
82
|
|
|
{ |
|
83
|
|
|
$type = ($thumb) ? 3 : 0; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
// Prepare our insert |
|
88
|
|
|
return array( |
|
89
|
|
|
'id_attach' => $id_attach, |
|
90
|
|
|
'id_thumb' => !$thumb && !empty($row['thumbnail_width']) ? ++$id_attach : 0, |
|
91
|
|
|
'size' => file_exists($destination) ? filesize($destination) : 0, |
|
92
|
|
|
'filename' => $basename . '.' . ($thumb ? $ext . '_thumb' : $ext), |
|
93
|
|
|
'file_hash' => $file_hash, |
|
94
|
|
|
'file_ext' => $ext, |
|
95
|
|
|
'mime_type' => $mime_type, |
|
96
|
|
|
'attachment_type' => $type, |
|
97
|
|
|
'id_msg' => $row['content_id'], |
|
98
|
|
|
'downloads' => $row['view_count'], |
|
99
|
|
|
'width' => $thumb ? $row['thumbnail_width'] : $row['width'], |
|
100
|
|
|
'height' => $thumb ? $row['thumbnail_height'] : $row['height'] |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function fetchLikes() |
|
105
|
|
|
{ |
|
106
|
|
|
$from_prefix = $this->config->from_prefix; |
|
107
|
|
|
|
|
108
|
|
|
$request = $this->db->query(" |
|
109
|
|
|
SELECT |
|
110
|
|
|
likes, like_users, post_id, user_id, post_date |
|
111
|
|
|
FROM {$from_prefix}post |
|
112
|
|
|
WHERE likes != '0'"); |
|
113
|
|
|
$return = array(); |
|
114
|
|
|
while ($row = $this->db->fetch_assoc($request)) |
|
115
|
|
|
{ |
|
116
|
|
|
$likers = unserialize($row['like_users']); |
|
117
|
|
|
foreach ($likers as $likes) |
|
118
|
|
|
{ |
|
119
|
|
|
$return[] = array( |
|
120
|
|
|
'id_member' => $likes['user_id'], |
|
121
|
|
|
'id_msg' => $row['post_id'], |
|
122
|
|
|
'id_poster' => $row['user_id'], |
|
123
|
|
|
'like_timestamp' => $row['post_date'], |
|
124
|
|
|
); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return $return; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
// Utility Functions |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Converts a binary string containing IPv4 back to standard format |
|
136
|
|
|
* |
|
137
|
|
|
* I'm not really sure what is being stored in the DB but found |
|
138
|
|
|
* 7f 00 00 01 for 127.0.0.1 which is a dec2hex(long2ip($ip)) |
|
139
|
|
|
* |
|
140
|
|
|
* @param string $ip IP data |
|
141
|
|
|
* |
|
142
|
|
|
* @return bool|string |
|
143
|
|
|
*/ |
|
144
|
|
|
function convertIp($ip) |
|
145
|
|
|
{ |
|
146
|
|
|
if (strlen($ip) == 8) |
|
147
|
|
|
{ |
|
148
|
|
|
return long2ip(hexdec($ip) + 0); |
|
149
|
|
|
} |
|
150
|
|
|
else if (strlen($ip) == 4) |
|
151
|
|
|
{ |
|
152
|
|
|
$parts = array(); |
|
153
|
|
|
foreach (str_split($ip) AS $char) |
|
154
|
|
|
{ |
|
155
|
|
|
$parts[] = ord($char); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
return implode('.', $parts); |
|
159
|
|
|
} |
|
160
|
|
|
else if (preg_match('/^[0-9]+$/', $ip)) |
|
161
|
|
|
{ |
|
162
|
|
|
return long2ip($ip + 0); |
|
163
|
|
|
} |
|
164
|
|
|
else |
|
165
|
|
|
{ |
|
166
|
|
|
return '127.0.0.1'; |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Return the subdir/filename combo to a given file |
|
172
|
|
|
* |
|
173
|
|
|
* Does not include the .data, .jpg, etc |
|
174
|
|
|
* |
|
175
|
|
|
* @param $row |
|
176
|
|
|
* |
|
177
|
|
|
* @return string |
|
178
|
|
|
*/ |
|
179
|
|
|
function xen_attach_filename($row) |
|
180
|
|
|
{ |
|
181
|
|
|
$subdir = floor($row['data_id'] / 1000); |
|
182
|
|
|
$name = $subdir . "/{$row['data_id']}-{$row['file_hash']}"; |
|
183
|
|
|
|
|
184
|
|
|
return $name; |
|
185
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.