1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Implementation of WP Symposium converter |
---|
5 | * |
---|
6 | * @since bbPress (rXXXX) |
---|
7 | * @link Codex Docs http://codex.bbpress.org/import-forums/wp-symposium |
---|
8 | */ |
---|
9 | class WPSymposium extends BBP_Converter_Base { |
---|
10 | |
---|
11 | /** |
---|
12 | * Main Constructor |
---|
13 | * |
---|
14 | * @uses WPSymposium::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' => 'symposium_cats', |
---|
31 | 'from_fieldname' => 'cid', |
---|
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' => 'symposium_cats', |
---|
39 | 'from_fieldname' => 'cat_parent', |
---|
40 | 'to_type' => 'forum', |
---|
41 | 'to_fieldname' => '_bbp_forum_parent_id' |
---|
42 | ); |
---|
43 | |
---|
44 | // Forum title. |
---|
45 | $this->field_map[] = array( |
---|
46 | 'from_tablename' => 'symposium_cats', |
---|
47 | 'from_fieldname' => 'title', |
---|
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' => 'symposium_cats', |
---|
55 | 'from_fieldname' => 'stub', |
---|
56 | 'to_type' => 'forum', |
---|
57 | 'to_fieldname' => 'post_name', |
---|
58 | ); |
---|
59 | |
---|
60 | // Forum description. |
---|
61 | $this->field_map[] = array( |
---|
62 | 'from_tablename' => 'symposium_cats', |
---|
63 | 'from_fieldname' => 'cat_desc', |
---|
64 | 'to_type' => 'forum', |
---|
65 | 'to_fieldname' => 'post_content', |
---|
66 | ); |
---|
67 | |
---|
68 | // Forum status (Open or Closed) |
---|
69 | $this->field_map[] = array( |
---|
70 | 'from_tablename' => 'symposium_cats', |
---|
71 | 'from_fieldname' => 'allow_new', |
---|
72 | 'to_type' => 'forum', |
---|
73 | 'to_fieldname' => '_bbp_status', |
---|
74 | 'callback_method' => 'callback_forum_status' |
---|
75 | ); |
---|
76 | |
---|
77 | // Forum display order (Starts from 1) |
---|
78 | $this->field_map[] = array( |
---|
79 | 'from_tablename' => 'symposium_cats', |
---|
80 | 'from_fieldname' => 'listorder', |
---|
81 | 'to_type' => 'forum', |
---|
82 | 'to_fieldname' => 'menu_order' |
---|
83 | ); |
---|
84 | |
---|
85 | // Forum dates. |
---|
86 | $this->field_map[] = array( |
---|
87 | 'to_type' => 'forum', |
---|
88 | 'to_fieldname' => 'post_date', |
---|
89 | 'default' => date('Y-m-d H:i:s') |
---|
90 | ); |
---|
91 | $this->field_map[] = array( |
---|
92 | 'to_type' => 'forum', |
---|
93 | 'to_fieldname' => 'post_date_gmt', |
---|
94 | 'default' => date('Y-m-d H:i:s') |
---|
95 | ); |
---|
96 | $this->field_map[] = array( |
---|
97 | 'to_type' => 'forum', |
---|
98 | 'to_fieldname' => 'post_modified', |
---|
99 | 'default' => date('Y-m-d H:i:s') |
---|
100 | ); |
---|
101 | $this->field_map[] = array( |
---|
102 | 'to_type' => 'forum', |
---|
103 | 'to_fieldname' => 'post_modified_gmt', |
---|
104 | 'default' => date('Y-m-d H:i:s') |
---|
105 | ); |
---|
106 | |
---|
107 | /** Topic Section *****************************************************/ |
---|
108 | |
---|
109 | // Topic id (Stored in postmeta) |
---|
110 | $this->field_map[] = array( |
---|
111 | 'from_tablename' => 'symposium_topics', |
---|
112 | 'from_fieldname' => 'tid', |
---|
113 | 'from_expression' => 'WHERE symposium_topics.topic_parent = 0 AND symposium_topics.topic_group = 0', |
---|
114 | 'to_type' => 'topic', |
---|
115 | 'to_fieldname' => '_bbp_topic_id' |
---|
116 | ); |
---|
117 | |
---|
118 | // Topic parent forum id (If no parent, then 0. Stored in postmeta) |
---|
119 | $this->field_map[] = array( |
---|
120 | 'from_tablename' => 'symposium_topics', |
---|
121 | 'from_fieldname' => 'topic_category', |
---|
122 | 'to_type' => 'topic', |
---|
123 | 'to_fieldname' => '_bbp_forum_id', |
---|
124 | 'callback_method' => 'callback_forumid' |
---|
125 | ); |
---|
126 | |
---|
127 | // Topic author. |
---|
128 | $this->field_map[] = array( |
---|
129 | 'from_tablename' => 'symposium_topics', |
---|
130 | 'from_fieldname' => 'topic_owner', |
---|
131 | 'to_type' => 'topic', |
---|
132 | 'to_fieldname' => 'post_author', |
---|
133 | 'callback_method' => 'callback_userid' |
---|
134 | ); |
---|
135 | |
---|
136 | // Topic content. |
---|
137 | $this->field_map[] = array( |
---|
138 | 'from_tablename' => 'symposium_topics', |
---|
139 | 'from_fieldname' => 'topic_post', |
---|
140 | 'to_type' => 'topic', |
---|
141 | 'to_fieldname' => 'post_content', |
---|
142 | 'callback_method' => 'callback_html' |
---|
143 | ); |
---|
144 | |
---|
145 | // Topic title. |
---|
146 | $this->field_map[] = array( |
---|
147 | 'from_tablename' => 'symposium_topics', |
---|
148 | 'from_fieldname' => 'topic_subject', |
---|
149 | 'to_type' => 'topic', |
---|
150 | 'to_fieldname' => 'post_title' |
---|
151 | ); |
---|
152 | |
---|
153 | // Topic slug (Clean name to avoid conflicts) |
---|
154 | $this->field_map[] = array( |
---|
155 | 'from_tablename' => 'symposium_topics', |
---|
156 | 'from_fieldname' => 'stub', |
---|
157 | 'to_type' => 'topic', |
---|
158 | 'to_fieldname' => 'post_name', |
---|
159 | 'callback_method' => 'callback_slug' |
---|
160 | ); |
---|
161 | |
---|
162 | // Topic status (Open or Closed) |
---|
163 | $this->field_map[] = array( |
---|
164 | 'from_tablename' => 'symposium_topics', |
---|
165 | 'from_fieldname' => 'allow_replies', |
---|
166 | 'to_type' => 'topic', |
---|
167 | 'to_fieldname' => 'post_status', |
---|
168 | 'callback_method' => 'callback_topic_status' |
---|
169 | ); |
---|
170 | |
---|
171 | // Topic parent forum id (If no parent, then 0) |
---|
172 | $this->field_map[] = array( |
---|
173 | 'from_tablename' => 'symposium_topics', |
---|
174 | 'from_fieldname' => 'topic_category', |
---|
175 | 'to_type' => 'topic', |
---|
176 | 'to_fieldname' => 'post_parent', |
---|
177 | 'callback_method' => 'callback_forumid' |
---|
178 | ); |
---|
179 | |
---|
180 | // Sticky status (Stored in postmeta)) |
---|
181 | $this->field_map[] = array( |
---|
182 | 'from_tablename' => 'symposium_topics', |
---|
183 | 'from_fieldname' => 'topic_sticky', |
---|
184 | 'to_type' => 'topic', |
---|
185 | 'to_fieldname' => '_bbp_old_sticky_status', |
---|
186 | 'callback_method' => 'callback_sticky_status' |
---|
187 | ); |
---|
188 | |
---|
189 | // Topic dates. |
---|
190 | $this->field_map[] = array( |
---|
191 | 'from_tablename' => 'symposium_topics', |
---|
192 | 'from_fieldname' => 'topic_started', |
---|
193 | 'to_type' => 'topic', |
---|
194 | 'to_fieldname' => 'post_date', |
---|
195 | 'callback_method' => 'callback_datetime' |
---|
196 | ); |
---|
197 | $this->field_map[] = array( |
---|
198 | 'from_tablename' => 'symposium_topics', |
---|
199 | 'from_fieldname' => 'topic_started', |
---|
200 | 'to_type' => 'topic', |
---|
201 | 'to_fieldname' => 'post_date_gmt', |
---|
202 | 'callback_method' => 'callback_datetime' |
---|
203 | ); |
---|
204 | $this->field_map[] = array( |
---|
205 | 'from_tablename' => 'symposium_topics', |
---|
206 | 'from_fieldname' => 'topic_date', |
---|
207 | 'to_type' => 'topic', |
---|
208 | 'to_fieldname' => 'post_modified', |
---|
209 | 'callback_method' => 'callback_datetime' |
---|
210 | ); |
---|
211 | $this->field_map[] = array( |
---|
212 | 'from_tablename' => 'symposium_topics', |
---|
213 | 'from_fieldname' => 'topic_date', |
---|
214 | 'to_type' => 'topic', |
---|
215 | 'to_fieldname' => 'post_modified_gmt', |
---|
216 | 'callback_method' => 'callback_datetime' |
---|
217 | ); |
---|
218 | $this->field_map[] = array( |
---|
219 | 'from_tablename' => 'symposium_topics', |
---|
220 | 'from_fieldname' => 'topic_date', |
---|
221 | 'to_type' => 'topic', |
---|
222 | 'to_fieldname' => '_bbp_last_active_time', |
---|
223 | 'callback_method' => 'callback_datetime' |
---|
224 | ); |
---|
225 | |
---|
226 | /** Reply Section *****************************************************/ |
---|
227 | |
---|
228 | // Reply id (Stored in postmeta) |
---|
229 | $this->field_map[] = array( |
---|
230 | 'from_tablename' => 'symposium_topics', |
---|
231 | 'from_fieldname' => 'tid', |
---|
232 | 'from_expression' => 'INNER JOIN wp_symposium_topics t ON symposium_topics.topic_parent = t.tid WHERE symposium_topics.topic_parent != 0 AND symposium_topics.topic_group = 0 AND t.topic_parent = 0', |
---|
233 | 'to_type' => 'reply', |
---|
234 | 'to_fieldname' => '_bbp_post_id' |
---|
235 | ); |
---|
236 | |
---|
237 | // Reply parent forum id (If no parent, then 0. Stored in postmeta) |
---|
238 | $this->field_map[] = array( |
---|
239 | 'from_tablename' => 'symposium_topics', |
---|
240 | 'from_fieldname' => 'topic_category', |
---|
241 | 'to_type' => 'reply', |
---|
242 | 'to_fieldname' => '_bbp_forum_id', |
---|
243 | 'callback_method' => 'callback_forumid' |
---|
244 | ); |
---|
245 | |
---|
246 | // Reply parent topic id (If no parent, then 0. Stored in postmeta) |
---|
247 | $this->field_map[] = array( |
---|
248 | 'from_tablename' => 'symposium_topics', |
---|
249 | 'from_fieldname' => 'topic_parent', |
---|
250 | 'to_type' => 'reply', |
---|
251 | 'to_fieldname' => '_bbp_topic_id', |
---|
252 | 'callback_method' => 'callback_topicid' |
---|
253 | ); |
---|
254 | |
---|
255 | // Reply author. |
---|
256 | $this->field_map[] = array( |
---|
257 | 'from_tablename' => 'symposium_topics', |
---|
258 | 'from_fieldname' => 'topic_owner', |
---|
259 | 'to_type' => 'reply', |
---|
260 | 'to_fieldname' => 'post_author', |
---|
261 | 'callback_method' => 'callback_userid' |
---|
262 | ); |
---|
263 | |
---|
264 | // Reply content. |
---|
265 | $this->field_map[] = array( |
---|
266 | 'from_tablename' => 'symposium_topics', |
---|
267 | 'from_fieldname' => 'topic_post', |
---|
268 | 'to_type' => 'reply', |
---|
269 | 'to_fieldname' => 'post_content', |
---|
270 | 'callback_method' => 'callback_html' |
---|
271 | ); |
---|
272 | |
---|
273 | // Reply parent topic id (If no parent, then 0) |
---|
274 | $this->field_map[] = array( |
---|
275 | 'from_tablename' => 'symposium_topics', |
---|
276 | 'from_fieldname' => 'topic_parent', |
---|
277 | 'to_type' => 'reply', |
---|
278 | 'to_fieldname' => 'post_parent', |
---|
279 | 'callback_method' => 'callback_topicid' |
---|
280 | ); |
---|
281 | |
---|
282 | // Reply dates. |
---|
283 | $this->field_map[] = array( |
---|
284 | 'from_tablename' => 'symposium_topics', |
---|
285 | 'from_fieldname' => 'topic_started', |
---|
286 | 'to_type' => 'reply', |
---|
287 | 'to_fieldname' => 'post_date', |
---|
288 | 'callback_method' => 'callback_datetime' |
---|
289 | ); |
---|
290 | $this->field_map[] = array( |
---|
291 | 'from_tablename' => 'symposium_topics', |
---|
292 | 'from_fieldname' => 'topic_started', |
---|
293 | 'to_type' => 'reply', |
---|
294 | 'to_fieldname' => 'post_date_gmt', |
---|
295 | 'callback_method' => 'callback_datetime' |
---|
296 | ); |
---|
297 | $this->field_map[] = array( |
---|
298 | 'from_tablename' => 'symposium_topics', |
---|
299 | 'from_fieldname' => 'topic_started', |
---|
300 | 'to_type' => 'reply', |
---|
301 | 'to_fieldname' => 'post_modified', |
---|
302 | 'callback_method' => 'callback_datetime' |
---|
303 | ); |
---|
304 | $this->field_map[] = array( |
---|
305 | 'from_tablename' => 'symposium_topics', |
---|
306 | 'from_fieldname' => 'topic_started', |
---|
307 | 'to_type' => 'reply', |
---|
308 | 'to_fieldname' => 'post_modified_gmt', |
---|
309 | 'callback_method' => 'callback_datetime' |
---|
310 | ); |
---|
311 | |
---|
312 | /** User Section ******************************************************/ |
---|
313 | |
---|
314 | // Store old User id (Stored in usermeta) |
---|
315 | $this->field_map[] = array( |
---|
316 | 'from_tablename' => 'users', |
---|
317 | 'from_fieldname' => 'ID', |
---|
318 | 'to_type' => 'user', |
---|
319 | 'to_fieldname' => '_bbp_user_id' |
---|
320 | ); |
---|
321 | |
---|
322 | // Store old User password (Stored in usermeta) |
---|
323 | $this->field_map[] = array( |
---|
324 | 'from_tablename' => 'users', |
---|
325 | 'from_fieldname' => 'user_pass', |
---|
326 | 'to_type' => 'user', |
---|
327 | 'to_fieldname' => '_bbp_password' |
---|
328 | ); |
---|
329 | |
---|
330 | // User name. |
---|
331 | $this->field_map[] = array( |
---|
332 | 'from_tablename' => 'users', |
---|
333 | 'from_fieldname' => 'user_login', |
---|
334 | 'to_type' => 'user', |
---|
335 | 'to_fieldname' => 'user_login' |
---|
336 | ); |
---|
337 | |
---|
338 | // User nice name. |
---|
339 | $this->field_map[] = array( |
---|
340 | 'from_tablename' => 'users', |
---|
341 | 'from_fieldname' => 'user_nicename', |
---|
342 | 'to_type' => 'user', |
---|
343 | 'to_fieldname' => 'user_nicename' |
---|
344 | ); |
---|
345 | |
---|
346 | // User email. |
---|
347 | $this->field_map[] = array( |
---|
348 | 'from_tablename' => 'users', |
---|
349 | 'from_fieldname' => 'user_email', |
---|
350 | 'to_type' => 'user', |
---|
351 | 'to_fieldname' => 'user_email' |
---|
352 | ); |
---|
353 | |
---|
354 | // User homepage. |
---|
355 | $this->field_map[] = array( |
---|
356 | 'from_tablename' => 'users', |
---|
357 | 'from_fieldname' => 'user_url', |
---|
358 | 'to_type' => 'user', |
---|
359 | 'to_fieldname' => 'user_url' |
---|
360 | ); |
---|
361 | |
---|
362 | // User registered. |
---|
363 | $this->field_map[] = array( |
---|
364 | 'from_tablename' => 'users', |
---|
365 | 'from_fieldname' => 'user_registered', |
---|
366 | 'to_type' => 'user', |
---|
367 | 'to_fieldname' => 'user_registered' |
---|
368 | ); |
---|
369 | |
---|
370 | // User status. |
---|
371 | $this->field_map[] = array( |
---|
372 | 'from_tablename' => 'users', |
---|
373 | 'from_fieldname' => 'user_status', |
---|
374 | 'to_type' => 'user', |
---|
375 | 'to_fieldname' => 'user_status' |
---|
376 | ); |
---|
377 | |
---|
378 | // User display name. |
---|
379 | $this->field_map[] = array( |
---|
380 | 'from_tablename' => 'users', |
---|
381 | 'from_fieldname' => 'display_name', |
---|
382 | 'to_type' => 'user', |
---|
383 | 'to_fieldname' => 'display_name' |
---|
384 | ); |
---|
385 | } |
---|
386 | |
---|
387 | /** |
---|
388 | * This method allows us to indicates what is or is not converted for each |
---|
389 | * converter. |
---|
390 | */ |
---|
391 | public function info() { |
---|
392 | return ''; |
---|
393 | } |
---|
394 | |
---|
395 | /** |
---|
396 | * This method is to save the salt and password together. That |
---|
397 | * way when we authenticate it we can get it out of the database |
---|
398 | * as one value. Array values are auto sanitized by WordPress. |
---|
399 | */ |
---|
400 | public function callback_savepass( $field, $row ) { |
---|
401 | $pass_array = array( 'hash' => $field, 'salt' => $row['salt'] ); |
---|
402 | return $pass_array; |
---|
403 | } |
---|
404 | |
---|
405 | /** |
---|
406 | * This method is to take the pass out of the database and compare |
---|
407 | * to a pass the user has typed in. |
---|
408 | */ |
---|
409 | public function authenticate_pass( $password, $serialized_pass ) { |
---|
410 | $pass_array = unserialize( $serialized_pass ); |
---|
411 | return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) ); |
---|
412 | } |
---|
413 | |
---|
414 | /** |
---|
415 | * Translate the forum status from WP Symposium strings to bbPress strings. |
---|
416 | * |
---|
417 | * @param string $status WP Symposium string forum status, 'on' or '' |
---|
418 | * @return string WordPress safe |
---|
419 | * |
---|
420 | */ |
---|
421 | public function callback_forum_status( $status = 'on' ) { |
---|
422 | switch ( $status ) { |
---|
423 | case '' : |
---|
424 | $status = 'closed'; // WP Symposium closed forum "allow_new = ''" |
---|
425 | break; |
---|
426 | |
---|
427 | case 'on' : |
---|
428 | default : |
---|
429 | $status = 'open'; // WP Symposium forum open to new topics "allow_new = 'on'" |
---|
430 | break; |
---|
431 | } |
---|
432 | return $status; |
---|
433 | } |
---|
434 | |
---|
435 | /** |
---|
436 | * Translate the topic status from WP Symposium strings to bbPress strings. |
---|
437 | * |
---|
438 | * @param string $status WP Symposium string topic status, 'on' or '' |
---|
439 | * @return string WordPress safe |
---|
440 | */ |
---|
441 | public function callback_topic_status( $status = 'on' ) { |
---|
442 | switch ( $status ) { |
---|
443 | case '' : |
---|
444 | $status = 'closed'; // WP Symposium closed topic "allow_replies = ''" |
---|
445 | break; |
---|
446 | |
---|
447 | case 'on' : |
---|
448 | default : |
---|
449 | $status = 'publish'; // WP Symposium Normal Topic "allow_replies = 'on'" |
---|
450 | break; |
---|
451 | } |
---|
452 | return $status; |
---|
453 | } |
---|
454 | |
---|
455 | /** |
---|
456 | * Translate the topic sticky status type from WP Symposium numeric's to bbPress strings. |
---|
457 | * |
---|
458 | * @param int $status WP Symposium numeric forum type |
---|
459 | * @return string WordPress safe |
---|
460 | */ |
---|
461 | public function callback_sticky_status( $status = 0 ) { |
---|
462 | switch ( $status ) { |
---|
463 | case 1 : |
---|
464 | $status = 'sticky'; // WP Symposium Sticky topic 'topic_sticky = 1' |
---|
465 | break; |
---|
466 | |
---|
467 | case 0 : |
---|
468 | default : |
---|
469 | $status = 'normal'; // WP Symposium normal topic 'topic_sticky = 0' |
---|
470 | break; |
---|
471 | } |
---|
472 | return $status; |
---|
473 | } |
---|
474 | |
---|
475 | /** |
---|
476 | * This callback processes any custom parser.php attributes and custom code with preg_replace |
---|
477 | */ |
---|
478 | protected function callback_html( $field ) { |
---|
479 | |
---|
480 | // Strips WP Symposium custom HTML first from $field before parsing $field to parser.php |
---|
481 | $wps_markup = $field; |
---|
482 | $wps_markup = html_entity_decode( $wps_markup ); |
---|
483 | |
---|
484 | // Replace '[youtube]$1[/youtube]' with 'https://youtu.be/$1" |
---|
485 | $wps_markup = preg_replace( '/\[youtube\](.*?)\[\/youtube\]/', 'https://youtu.be/$1', $wps_markup ); |
---|
486 | |
---|
487 | // Now that WP Symposium custom HTML has been stripped put the cleaned HTML back in $field |
---|
488 | $field = $wps_markup; |
---|
489 | |
---|
490 | // Parse out any bbCodes in $field with the BBCode 'parser.php' |
---|
491 | require_once( bbpress()->admin->admin_dir . 'parser.php' ); |
---|
492 | $bbcode = BBCode::getInstance(); |
---|
493 | $bbcode->enable_smileys = false; |
---|
494 | $bbcode->smiley_regex = false; |
---|
495 | return html_entity_decode( $bbcode->Parse( $field ) ); |
---|
496 | } |
---|
497 | } |
---|