-
Notifications
You must be signed in to change notification settings - Fork 14
/
mybb18_importer.php
106 lines (93 loc) · 2.2 KB
/
mybb18_importer.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
<?php
/**
* @name OpenImporter
* @copyright OpenImporter contributors
* @license BSD http://opensource.org/licenses/BSD-3-Clause
*
* @version 1.0 Alpha
*/
/**
* Class mybb18
* Settings for the MyBB 1.8 system.
*/
class mybb18 extends Importers\AbstractSourceImporter
{
protected $setting_file = '/inc/config.php';
public function getName()
{
return 'MyBB 1.8';
}
public function getVersion()
{
return 'ElkArte 1.0';
}
public function getPrefix()
{
global $config;
return '`' . $this->getDbName() . '`.' . $config['database']['table_prefix'];
}
public function getDbName()
{
global $config;
return $config['database']['database'];
}
public function getTableTest()
{
return 'users';
}
/**
* Copy attachment files
*
* @param string g$dir
* @param array $row
* @param int $id_attach
* @param string $destination_path
* @param bool $thumb
*
* @return array
*/
public function mybb_copy_files($dir, $row, $id_attach, $destination_path, $thumb = false)
{
// Some extra details
list($ext, $basename, $mime_type) = attachment_type($row['filename']);
// Prepare for the copy
$file = $thumb ? $row['thumbnail'] : $row['attachname'];
$source = $dir . '/' . $file;
$file_hash = createAttachmentFileHash($file);
$destination = $destination_path . '/' . $id_attach . '_' . $file_hash . '.elk';
$width = 0;
$height = 0;
$type = 0;
// Copy it over
copy_file($source, $destination);
// If its an image, then make sure it has legit width/height
if (!empty($ext))
{
list ($width, $height) = getimagesize($destination);
if (empty($width))
{
$width = 0;
$height = 0;
}
else
{
$type = ($thumb) ? 3 : 0;
}
}
// Prepare our insert
return array(
'id_attach' => $id_attach,
'id_thumb' => !$thumb && !empty($row['thumbnail']) ? ++$id_attach : 0,
'size' => file_exists($destination) ? filesize($destination) : 0,
'filename' => $basename . '.' . ($thumb ? $ext . '_thumb' : $ext),
'file_hash' => $file_hash,
'file_ext' => $ext,
'mime_type' => $mime_type,
'attachment_type' => $type,
'id_msg' => $row['id_msg'],
'downloads' => $row['downloads'],
'width' => $width,
'height' => $height,
);
}
}