1 | <?php |
||
13 | class SMF2_0 extends Importers\AbstractSourceImporter |
||
14 | { |
||
15 | protected $setting_file = '/Settings.php'; |
||
16 | |||
17 | protected $smf_attach_folders = null; |
||
18 | |||
19 | protected $_is_nibogo_like = null; |
||
20 | |||
21 | public function getName() |
||
22 | { |
||
23 | return 'SMF2_0'; |
||
24 | } |
||
25 | |||
26 | public function getVersion() |
||
27 | { |
||
28 | return 'ElkArte 1.0'; |
||
29 | } |
||
30 | |||
31 | public function setDefines() |
||
32 | { |
||
33 | if (!defined('SMF')) |
||
34 | define('SMF', 1); |
||
35 | } |
||
36 | |||
37 | public function getPrefix() |
||
38 | { |
||
39 | $db_name = $this->getDbName(); |
||
40 | $db_prefix = $this->fetchSetting('db_prefix'); |
||
41 | |||
42 | return '`' . $db_name . '`.' . $db_prefix; |
||
43 | } |
||
44 | |||
45 | public function getDbName() |
||
46 | { |
||
47 | return $this->fetchSetting('db_name'); |
||
48 | } |
||
49 | |||
50 | public function getTableTest() |
||
51 | { |
||
52 | return 'members'; |
||
53 | } |
||
54 | |||
55 | public function fetchSetting($name) |
||
56 | { |
||
57 | static $content = null; |
||
58 | |||
59 | if ($content === null) |
||
60 | $content = file_get_contents($this->path . '/Settings.php'); |
||
61 | |||
62 | $match = array(); |
||
63 | preg_match('~\$' . $name . '\s*=\s*\'(.*?)\';~', $content, $match); |
||
64 | |||
65 | return isset($match[1]) ? $match[1] : ''; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Read the attachment directory structure from the source db |
||
70 | * |
||
71 | * @return array|null |
||
72 | */ |
||
73 | public function getAttachmentDirs() |
||
74 | { |
||
75 | if ($this->smf_attach_folders === null) |
||
|
|||
76 | { |
||
77 | $from_prefix = $this->config->from_prefix; |
||
78 | |||
79 | $request = $this->db->query(" |
||
80 | SELECT value |
||
81 | FROM {$from_prefix}settings |
||
82 | WHERE variable='attachmentUploadDir';"); |
||
83 | list ($smf_attachments_dir) = $this->db->fetch_row($request); |
||
84 | |||
85 | $this->smf_attach_folders = @unserialize($smf_attachments_dir); |
||
86 | |||
87 | if (!is_array($this->smf_attach_folders)) |
||
88 | $this->smf_attach_folders = array(1 => $smf_attachments_dir); |
||
89 | } |
||
90 | |||
91 | return $this->smf_attach_folders; |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Import likes from one of the known addons |
||
96 | * |
||
97 | * @return array |
||
98 | */ |
||
99 | public function fetchLikes() |
||
100 | { |
||
101 | if ($this->isNibogo()) |
||
102 | return $this->fetchNibogo(); |
||
103 | else |
||
104 | return $this->fetchIllori(); |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Nibogo version of likes |
||
109 | * |
||
110 | * @return array |
||
111 | */ |
||
112 | protected function fetchNibogo() |
||
113 | { |
||
114 | $from_prefix = $this->config->from_prefix; |
||
115 | |||
116 | $request = $this->db->query(" |
||
117 | SELECT l.id_member, t.id_first_msg, t.id_member_started |
||
118 | FROM {$from_prefix}likes |
||
119 | INNER JOIN {$from_prefix}topics AS t ON (t.id_topic = l.id_topic)"); |
||
120 | $return = array(); |
||
121 | while ($row = $this->db->fetch_assoc($request)) |
||
122 | $return[] = array( |
||
123 | 'id_member' => $row['id_member'], |
||
124 | 'id_msg' => $row['id_first_msg'], |
||
125 | 'id_poster' => $row['id_member_started'], |
||
126 | 'like_timestamp' => 0, |
||
127 | ); |
||
128 | $this->db->free_result($request); |
||
129 | |||
130 | return $return; |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * Illori version of likes |
||
135 | * |
||
136 | * @return array |
||
137 | */ |
||
138 | protected function fetchIllori() |
||
139 | { |
||
140 | $from_prefix = $this->config->from_prefix; |
||
141 | |||
142 | $request = $this->db->query(" |
||
143 | SELECT l.id_member, l.id_message, m.id_member as id_poster |
||
144 | FROM {$from_prefix}likes AS l |
||
145 | INNER JOIN {$from_prefix}messages AS m ON (m.id_msg = l.id_message)"); |
||
146 | $return = array(); |
||
147 | while ($row = $this->db->fetch_assoc($request)) |
||
148 | $return[] = array( |
||
149 | 'id_member' => $row['id_member'], |
||
150 | 'id_msg' => $row['id_message'], |
||
151 | 'id_poster' => $row['id_poster'], |
||
152 | 'like_timestamp' => 0, |
||
153 | ); |
||
154 | $this->db->free_result($request); |
||
155 | |||
156 | return $return; |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * Figure out which likes system may be in use |
||
161 | * |
||
162 | * @return bool|null |
||
163 | */ |
||
164 | protected function isNibogo() |
||
165 | { |
||
166 | $from_prefix = $this->config->from_prefix; |
||
167 | |||
168 | if ($this->_is_nibogo_like !== null) |
||
169 | return $this->_is_nibogo_like; |
||
170 | |||
171 | $request = $this->db->query(" |
||
172 | SHOW COLUMNS |
||
173 | FROM {$from_prefix}likes"); |
||
174 | while ($row = $this->db->fetch_assoc($request)) |
||
175 | { |
||
176 | // This is Nibogo |
||
177 | if ($row['Field'] == 'id_topic') |
||
178 | { |
||
179 | $this->_is_nibogo_like = true; |
||
180 | return $this->_is_nibogo_like; |
||
181 | } |
||
182 | } |
||
183 | |||
184 | // Not Nibogo means Illori |
||
185 | $this->_is_nibogo_like = false; |
||
186 | return $this->_is_nibogo_like; |
||
187 | } |
||
188 | } |
||
189 | |||
235 |