1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Implementation of Mingle Forums converter. |
---|
5 | * |
---|
6 | * @since bbPress (r4691) |
---|
7 | * @link Codex Docs http://codex.bbpress.org/import-forums/mingle |
---|
8 | */ |
---|
9 | class Mingle extends BBP_Converter_Base { |
---|
10 | |
---|
11 | /** |
---|
12 | * Main constructor |
---|
13 | * |
---|
14 | * @uses Mingle::setup_globals() |
---|
15 | */ |
---|
16 | function __construct() { |
---|
17 | parent::__construct(); |
---|
18 | $this->setup_globals(); |
---|
19 | } |
---|
20 | |
---|
21 | /** |
---|
22 | * Sets up the field mappings |
---|
23 | */ |
---|
24 | public function setup_globals() { |
---|
25 | |
---|
26 | /** Forum Section ******************************************************/ |
---|
27 | |
---|
28 | // Forum id (Stored in postmeta) |
---|
29 | $this->field_map[] = array( |
---|
30 | 'from_tablename' => 'forum_forums', |
---|
31 | 'from_fieldname' => 'id', |
---|
32 | 'to_type' => 'forum', |
---|
33 | 'to_fieldname' => '_bbp_forum_id' |
---|
34 | ); |
---|
35 | |
---|
36 | // Forum parent id (If no parent, then 0. Stored in postmeta) |
---|
37 | $this->field_map[] = array( |
---|
38 | 'from_tablename' => 'forum_forums', |
---|
39 | 'from_fieldname' => 'parent_id', |
---|
40 | 'to_type' => 'forum', |
---|
41 | 'to_fieldname' => '_bbp_forum_parent_id' |
---|
42 | ); |
---|
43 | |
---|
44 | // Forum title. |
---|
45 | $this->field_map[] = array( |
---|
46 | 'from_tablename' => 'forum_forums', |
---|
47 | 'from_fieldname' => 'name', |
---|
48 | 'to_type' => 'forum', |
---|
49 | 'to_fieldname' => 'post_title' |
---|
50 | ); |
---|
51 | |
---|
52 | // Forum slug (Clean name to avoid confilcts) |
---|
53 | $this->field_map[] = array( |
---|
54 | 'from_tablename' => 'forum_forums', |
---|
55 | 'from_fieldname' => 'name', |
---|
56 | 'to_type' => 'forum', |
---|
57 | 'to_fieldname' => 'post_name', |
---|
58 | 'callback_method' => 'callback_slug' |
---|
59 | ); |
---|
60 | // Forum description. |
---|
61 | $this->field_map[] = array( |
---|
62 | 'from_tablename' => 'forum_forums', |
---|
63 | 'from_fieldname' => 'description', |
---|
64 | 'to_type' => 'forum', |
---|
65 | 'to_fieldname' => 'post_content', |
---|
66 | 'callback_method' => 'callback_null' |
---|
67 | ); |
---|
68 | |
---|
69 | // Forum display order (Starts from 1) |
---|
70 | $this->field_map[] = array( |
---|
71 | 'from_tablename' => 'forum_forums', |
---|
72 | 'from_fieldname' => 'sort', |
---|
73 | 'to_type' => 'forum', |
---|
74 | 'to_fieldname' => 'menu_order' |
---|
75 | ); |
---|
76 | |
---|
77 | // Forum dates. |
---|
78 | $this->field_map[] = array( |
---|
79 | 'to_type' => 'forum', |
---|
80 | 'to_fieldname' => 'post_date', |
---|
81 | 'default' => date('Y-m-d H:i:s') |
---|
82 | ); |
---|
83 | $this->field_map[] = array( |
---|
84 | 'to_type' => 'forum', |
---|
85 | 'to_fieldname' => 'post_date_gmt', |
---|
86 | 'default' => date('Y-m-d H:i:s') |
---|
87 | ); |
---|
88 | $this->field_map[] = array( |
---|
89 | 'to_type' => 'forum', |
---|
90 | 'to_fieldname' => 'post_modified', |
---|
91 | 'default' => date('Y-m-d H:i:s') |
---|
92 | ); |
---|
93 | $this->field_map[] = array( |
---|
94 | 'to_type' => 'forum', |
---|
95 | 'to_fieldname' => 'post_modified_gmt', |
---|
96 | 'default' => date('Y-m-d H:i:s') |
---|
97 | ); |
---|
98 | |
---|
99 | /** Topic Section ******************************************************/ |
---|
100 | |
---|
101 | // Topic id (Stored in postmeta) |
---|
102 | $this->field_map[] = array( |
---|
103 | 'from_tablename' => 'forum_threads', |
---|
104 | 'from_fieldname' => 'id', |
---|
105 | 'to_type' => 'topic', |
---|
106 | 'to_fieldname' => '_bbp_topic_id' |
---|
107 | ); |
---|
108 | |
---|
109 | // Topic parent forum id (If no parent, then 0. Stored in postmeta) |
---|
110 | $this->field_map[] = array( |
---|
111 | 'from_tablename' => 'forum_threads', |
---|
112 | 'from_fieldname' => 'parent_id', |
---|
113 | 'to_type' => 'topic', |
---|
114 | 'to_fieldname' => '_bbp_forum_id', |
---|
115 | 'callback_method' => 'callback_forumid' |
---|
116 | ); |
---|
117 | |
---|
118 | // Topic author. |
---|
119 | $this->field_map[] = array( |
---|
120 | 'from_tablename' => 'forum_threads', |
---|
121 | 'from_fieldname' => 'starter', |
---|
122 | 'to_type' => 'topic', |
---|
123 | 'to_fieldname' => 'post_author', |
---|
124 | 'callback_method' => 'callback_userid' |
---|
125 | ); |
---|
126 | |
---|
127 | // Topic content. |
---|
128 | // Note: We join the forum_posts table because forum_topics do not have topic content. |
---|
129 | $this->field_map[] = array( |
---|
130 | 'from_tablename' => 'forum_posts', |
---|
131 | 'from_fieldname' => 'text', |
---|
132 | 'join_tablename' => 'forum_threads', |
---|
133 | 'join_type' => 'INNER', |
---|
134 | 'join_expression' => 'ON forum_posts.parent_id = forum_threads.id GROUP BY forum_threads.id', |
---|
135 | 'to_type' => 'topic', |
---|
136 | 'to_fieldname' => 'post_content', |
---|
137 | 'callback_method' => 'callback_html' |
---|
138 | ); |
---|
139 | // Topic title. |
---|
140 | $this->field_map[] = array( |
---|
141 | 'from_tablename' => 'forum_threads', |
---|
142 | 'from_fieldname' => 'subject', |
---|
143 | 'to_type' => 'topic', |
---|
144 | 'to_fieldname' => 'post_title' |
---|
145 | ); |
---|
146 | |
---|
147 | // Topic slug (Clean name to avoid conflicts) |
---|
148 | $this->field_map[] = array( |
---|
149 | 'from_tablename' => 'forum_threads', |
---|
150 | 'from_fieldname' => 'subject', |
---|
151 | 'to_type' => 'topic', |
---|
152 | 'to_fieldname' => 'post_name', |
---|
153 | 'callback_method' => 'callback_slug' |
---|
154 | ); |
---|
155 | |
---|
156 | // Topic parent forum id (If no parent, then 0) |
---|
157 | $this->field_map[] = array( |
---|
158 | 'from_tablename' => 'forum_threads', |
---|
159 | 'from_fieldname' => 'parent_id', |
---|
160 | 'to_type' => 'topic', |
---|
161 | 'to_fieldname' => 'post_parent', |
---|
162 | 'callback_method' => 'callback_forumid' |
---|
163 | ); |
---|
164 | |
---|
165 | // Topic dates. |
---|
166 | $this->field_map[] = array( |
---|
167 | 'from_tablename' => 'forum_threads', |
---|
168 | 'from_fieldname' => 'date', |
---|
169 | 'to_type' => 'topic', |
---|
170 | 'to_fieldname' => 'post_date' |
---|
171 | ); |
---|
172 | $this->field_map[] = array( |
---|
173 | 'from_tablename' => 'forum_threads', |
---|
174 | 'from_fieldname' => 'date', |
---|
175 | 'to_type' => 'topic', |
---|
176 | 'to_fieldname' => 'post_date_gmt' |
---|
177 | ); |
---|
178 | $this->field_map[] = array( |
---|
179 | 'from_tablename' => 'forum_threads', |
---|
180 | 'from_fieldname' => 'last_post', |
---|
181 | 'to_type' => 'topic', |
---|
182 | 'to_fieldname' => 'post_modified' |
---|
183 | ); |
---|
184 | $this->field_map[] = array( |
---|
185 | 'from_tablename' => 'forum_threads', |
---|
186 | 'from_fieldname' => 'last_post', |
---|
187 | 'to_type' => 'topic', |
---|
188 | 'to_fieldname' => 'post_modified_gmt' |
---|
189 | ); |
---|
190 | $this->field_map[] = array( |
---|
191 | 'from_tablename' => 'forum_threads', |
---|
192 | 'from_fieldname' => 'last_post', |
---|
193 | 'to_type' => 'topic', |
---|
194 | 'to_fieldname' => '_bbp_last_active_time' |
---|
195 | ); |
---|
196 | |
---|
197 | // Topic status (Open or Closed) |
---|
198 | $this->field_map[] = array( |
---|
199 | 'from_tablename' => 'forum_threads', |
---|
200 | 'from_fieldname' => 'closed', |
---|
201 | 'to_type' => 'topic', |
---|
202 | 'to_fieldname' => 'post_status', |
---|
203 | 'callback_method' => 'callback_topic_status' |
---|
204 | ); |
---|
205 | |
---|
206 | /** Tags Section ******************************************************/ |
---|
207 | |
---|
208 | /** |
---|
209 | * Mingle Forums do not support topic tags |
---|
210 | */ |
---|
211 | |
---|
212 | /** Reply Section ******************************************************/ |
---|
213 | |
---|
214 | // Reply id (Stored in postmeta) |
---|
215 | $this->field_map[] = array( |
---|
216 | 'from_tablename' => 'forum_posts', |
---|
217 | 'from_fieldname' => 'id', |
---|
218 | 'to_type' => 'reply', |
---|
219 | 'to_fieldname' => '_bbp_post_id' |
---|
220 | ); |
---|
221 | |
---|
222 | // Setup reply section table joins |
---|
223 | // We need join the 'forum_threads' table to only import replies |
---|
224 | $this->field_map[] = array( |
---|
225 | 'from_tablename' => 'forum_threads', |
---|
226 | 'from_fieldname' => 'date', |
---|
227 | 'join_tablename' => 'forum_posts', |
---|
228 | 'join_type' => 'INNER', |
---|
229 | 'join_expression' => 'ON forum_posts.parent_id = forum_threads.id', |
---|
230 | 'from_expression' => 'WHERE forum_threads.subject != forum_posts.subject', |
---|
231 | 'to_type' => 'reply', |
---|
232 | 'to_fieldname' => '_bbp_last_active_time' |
---|
233 | ); |
---|
234 | |
---|
235 | // Reply parent forum id (If no parent, then 0. Stored in postmeta) |
---|
236 | $this->field_map[] = array( |
---|
237 | 'from_tablename' => 'forum_posts', |
---|
238 | 'from_fieldname' => 'parent_id', |
---|
239 | 'to_type' => 'reply', |
---|
240 | 'to_fieldname' => '_bbp_forum_id', |
---|
241 | 'callback_method' => 'callback_topicid_to_forumid' |
---|
242 | ); |
---|
243 | |
---|
244 | // Reply parent topic id (If no parent, then 0. Stored in postmeta) |
---|
245 | $this->field_map[] = array( |
---|
246 | 'from_tablename' => 'forum_posts', |
---|
247 | 'from_fieldname' => 'parent_id', |
---|
248 | 'to_type' => 'reply', |
---|
249 | 'to_fieldname' => '_bbp_topic_id', |
---|
250 | 'callback_method' => 'callback_topicid' |
---|
251 | ); |
---|
252 | |
---|
253 | // Reply author. |
---|
254 | $this->field_map[] = array( |
---|
255 | 'from_tablename' => 'forum_posts', |
---|
256 | 'from_fieldname' => 'author_id', |
---|
257 | 'to_type' => 'reply', |
---|
258 | 'to_fieldname' => 'post_author', |
---|
259 | 'callback_method' => 'callback_userid' |
---|
260 | ); |
---|
261 | |
---|
262 | // Reply title. |
---|
263 | $this->field_map[] = array( |
---|
264 | 'from_tablename' => 'forum_posts', |
---|
265 | 'from_fieldname' => 'subject', |
---|
266 | 'to_type' => 'reply', |
---|
267 | 'to_fieldname' => 'post_title' |
---|
268 | ); |
---|
269 | |
---|
270 | // Reply slug (Clean name to avoid conflicts) |
---|
271 | $this->field_map[] = array( |
---|
272 | 'from_tablename' => 'forum_posts', |
---|
273 | 'from_fieldname' => 'subject', |
---|
274 | 'to_type' => 'reply', |
---|
275 | 'to_fieldname' => 'post_name', |
---|
276 | 'callback_method' => 'callback_slug' |
---|
277 | ); |
---|
278 | |
---|
279 | // Reply content. |
---|
280 | $this->field_map[] = array( |
---|
281 | 'from_tablename' => 'forum_posts', |
---|
282 | 'from_fieldname' => 'text', |
---|
283 | 'to_type' => 'reply', |
---|
284 | 'to_fieldname' => 'post_content', |
---|
285 | 'callback_method' => 'callback_html' |
---|
286 | ); |
---|
287 | |
---|
288 | // Reply parent topic id (If no parent, then 0) |
---|
289 | $this->field_map[] = array( |
---|
290 | 'from_tablename' => 'forum_posts', |
---|
291 | 'from_fieldname' => 'parent_id', |
---|
292 | 'to_type' => 'reply', |
---|
293 | 'to_fieldname' => 'post_parent', |
---|
294 | 'callback_method' => 'callback_topicid' |
---|
295 | ); |
---|
296 | |
---|
297 | // Reply dates. |
---|
298 | $this->field_map[] = array( |
---|
299 | 'from_tablename' => 'forum_posts', |
---|
300 | 'from_fieldname' => 'date', |
---|
301 | 'to_type' => 'reply', |
---|
302 | 'to_fieldname' => 'post_date' |
---|
303 | ); |
---|
304 | $this->field_map[] = array( |
---|
305 | 'from_tablename' => 'forum_posts', |
---|
306 | 'from_fieldname' => 'date', |
---|
307 | 'to_type' => 'reply', |
---|
308 | 'to_fieldname' => 'post_date_gmt' |
---|
309 | ); |
---|
310 | $this->field_map[] = array( |
---|
311 | 'from_tablename' => 'forum_posts', |
---|
312 | 'from_fieldname' => 'date', |
---|
313 | 'to_type' => 'reply', |
---|
314 | 'to_fieldname' => 'post_modified' |
---|
315 | ); |
---|
316 | $this->field_map[] = array( |
---|
317 | 'from_tablename' => 'forum_posts', |
---|
318 | 'from_fieldname' => 'date', |
---|
319 | 'to_type' => 'reply', |
---|
320 | 'to_fieldname' => 'post_modified_gmt' |
---|
321 | ); |
---|
322 | |
---|
323 | /** User Section ******************************************************/ |
---|
324 | |
---|
325 | // Store old User id (Stored in usermeta) |
---|
326 | $this->field_map[] = array( |
---|
327 | 'from_tablename' => 'users', |
---|
328 | 'from_fieldname' => 'ID', |
---|
329 | 'to_type' => 'user', |
---|
330 | 'to_fieldname' => '_bbp_user_id' |
---|
331 | ); |
---|
332 | |
---|
333 | // Store old User password (Stored in usermeta) |
---|
334 | $this->field_map[] = array( |
---|
335 | 'from_tablename' => 'users', |
---|
336 | 'from_fieldname' => 'user_pass', |
---|
337 | 'to_type' => 'user', |
---|
338 | 'to_fieldname' => '_bbp_password' |
---|
339 | ); |
---|
340 | |
---|
341 | // User name. |
---|
342 | $this->field_map[] = array( |
---|
343 | 'from_tablename' => 'users', |
---|
344 | 'from_fieldname' => 'user_login', |
---|
345 | 'to_type' => 'user', |
---|
346 | 'to_fieldname' => 'user_login' |
---|
347 | ); |
---|
348 | |
---|
349 | // User nice name. |
---|
350 | $this->field_map[] = array( |
---|
351 | 'from_tablename' => 'users', |
---|
352 | 'from_fieldname' => 'user_nicename', |
---|
353 | 'to_type' => 'user', |
---|
354 | 'to_fieldname' => 'user_nicename' |
---|
355 | ); |
---|
356 | |
---|
357 | // User email. |
---|
358 | $this->field_map[] = array( |
---|
359 | 'from_tablename' => 'users', |
---|
360 | 'from_fieldname' => 'user_email', |
---|
361 | 'to_type' => 'user', |
---|
362 | 'to_fieldname' => 'user_email' |
---|
363 | ); |
---|
364 | |
---|
365 | // User homepage. |
---|
366 | $this->field_map[] = array( |
---|
367 | 'from_tablename' => 'users', |
---|
368 | 'from_fieldname' => 'user_url', |
---|
369 | 'to_type' => 'user', |
---|
370 | 'to_fieldname' => 'user_url' |
---|
371 | ); |
---|
372 | |
---|
373 | // User registered. |
---|
374 | $this->field_map[] = array( |
---|
375 | 'from_tablename' => 'users', |
---|
376 | 'from_fieldname' => 'user_registered', |
---|
377 | 'to_type' => 'user', |
---|
378 | 'to_fieldname' => 'user_registered' |
---|
379 | ); |
---|
380 | |
---|
381 | // User status. |
---|
382 | $this->field_map[] = array( |
---|
383 | 'from_tablename' => 'users', |
---|
384 | 'from_fieldname' => 'user_status', |
---|
385 | 'to_type' => 'user', |
---|
386 | 'to_fieldname' => 'user_status' |
---|
387 | ); |
---|
388 | |
---|
389 | // User display name. |
---|
390 | $this->field_map[] = array( |
---|
391 | 'from_tablename' => 'users', |
---|
392 | 'from_fieldname' => 'display_name', |
---|
393 | 'to_type' => 'user', |
---|
394 | 'to_fieldname' => 'display_name' |
---|
395 | ); |
---|
396 | } |
---|
397 | |
---|
398 | /** |
---|
399 | * This method allows us to indicates what is or is not converted for each |
---|
400 | * converter. |
---|
401 | */ |
---|
402 | public function info() { |
---|
403 | return ''; |
---|
404 | } |
---|
405 | |
---|
406 | /** |
---|
407 | * This method is to save the salt and password together. That |
---|
408 | * way when we authenticate it we can get it out of the database |
---|
409 | * as one value. Array values are auto sanitized by WordPress. |
---|
410 | */ |
---|
411 | public function callback_savepass( $field, $row ) { |
---|
412 | return false; |
---|
413 | } |
---|
414 | |
---|
415 | /** |
---|
416 | * This method is to take the pass out of the database and compare |
---|
417 | * to a pass the user has typed in. |
---|
418 | */ |
---|
419 | public function authenticate_pass( $password, $serialized_pass ) { |
---|
420 | return false; |
---|
421 | } |
---|
422 | |
---|
423 | /** |
---|
424 | * Translate the topic status from Mingle numeric's to WordPress's strings. |
---|
425 | * |
---|
426 | * @param int $status Mingle v1.x numeric topic status |
---|
427 | * @return string WordPress safe |
---|
428 | */ |
---|
429 | public function callback_topic_status( $status = 0 ) { |
---|
430 | switch ( $status ) { |
---|
431 | case 1 : |
---|
432 | $status = 'closed'; |
---|
433 | break; |
---|
434 | |
---|
435 | case 0 : |
---|
436 | default : |
---|
437 | $status = 'publish'; |
---|
438 | break; |
---|
439 | } |
---|
440 | return $status; |
---|
441 | } |
---|
442 | |
---|
443 | /** |
---|
444 | * This callback processes any custom BBCodes with parser.php |
---|
445 | */ |
---|
446 | protected function callback_html( $field ) { |
---|
447 | require_once( bbpress()->admin->admin_dir . 'parser.php' ); |
---|
448 | $bbcode = BBCode::getInstance(); |
---|
449 | $bbcode->enable_smileys = false; |
---|
450 | $bbcode->smiley_regex = false; |
---|
451 | return html_entity_decode( $bbcode->Parse( $field ) ); |
---|
452 | } |
---|
453 | |
---|
454 | } |
---|