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