Skip to:
Content

bbPress.org

Ticket #2074: SimplePress5.2.php

File SimplePress5.2.php, 14.2 KB (added by netweb, 11 years ago)
Line 
1<?php
2
3/**
4 * Implementation of SimplePress5 converter.
5 */
6class 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_simplepress'
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                /** Tags Section ******************************************************/
185                /*
186                // Topic id.
187                $this->field_map[] = array(
188                        'from_tablename'  => 'tagcontent',
189                        'from_fieldname'  => 'contentid',
190                        'to_type'         => 'tags',
191                        'to_fieldname'    => 'objectid',
192                        'callback_method' => 'callback_topicid'
193                );
194               
195                // Tags text.
196                $this->field_map[] = array(
197                        'from_tablename'  => 'tag',
198                        'from_fieldname'  => 'tagtext',
199                        'join_tablename'  => 'tagcontent',
200                        'join_type'       => 'INNER',
201                        'join_expression' => 'USING (tagid)',
202                        'to_type'         => 'tags',
203                        'to_fieldname'    => 'name'
204                );             
205                */
206               
207                /** Post Section ******************************************************/
208
209                // Post id. Stores in postmeta.
210                $this->field_map[] = array(
211                        'from_tablename' => 'sfposts',
212                        'from_fieldname' => 'post_id',
213                        'to_type'        => 'reply',
214                        'to_fieldname'   => '_bbp_post_id'
215                );
216               
217                // Topic content.
218                $this->field_map[] = array(
219                        'from_tablename'  => 'sftopics',
220                        'from_fieldname'  => 'topic_id',
221                        'join_tablename'  => 'sfposts',
222                        'join_type'       => 'LEFT',
223                        'join_expression' => 'USING (topic_id) WHERE sfposts.post_index != 1',
224                        'to_type'         => 'reply'
225                );     
226               
227                // Forum id. Stores in postmeta.
228                $this->field_map[] = array(
229                        'from_tablename'  => 'sfposts',
230                        'from_fieldname'  => 'forum_id',
231                        'to_type'         => 'reply',
232                        'to_fieldname'    => '_bbp_forum_id',
233                        'callback_method' => 'callback_topicid_to_forumid'
234                );
235               
236                // Topic id. Stores in postmeta.
237                $this->field_map[] = array(
238                        'from_tablename'  => 'sfposts',
239                        'from_fieldname'  => 'topic_id',
240                        'to_type'         => 'reply',
241                        'to_fieldname'    => '_bbp_topic_id',
242                        'callback_method' => 'callback_topicid'
243                );
244               
245                // Author ip.
246                $this->field_map[] = array(
247                        'from_tablename' => 'sfposts',
248                        'from_fieldname' => 'poster_ip',
249                        'to_type'        => 'reply',
250                        'to_fieldname'   => '_bbp_author_ip'
251                );     
252                       
253                // Post author.
254                $this->field_map[] = array(
255                        'from_tablename'  => 'sfposts',
256                        'from_fieldname'  => 'user_id',
257                        'to_type'         => 'reply',
258                        'to_fieldname'    => 'post_author',
259                        'callback_method' => 'callback_userid'
260                );
261               
262                // Topic title.
263                // Note: We join the sftopics table because sfposts do not have topic_name.
264                $this->field_map[] = array(
265                        'from_tablename'  => 'sftopics',
266                        'from_fieldname'  => 'topic_name',
267                        'join_tablename'  => 'sfposts',
268                        'join_type'       => 'INNER',
269                        'join_expression' => 'USING (topic_id) WHERE sfposts.post_id = sftopics.post_id_held',
270                        'to_type'         => 'reply',
271                        'to_fieldname'    => 'post_title'
272                );
273
274                // Topic slug. Clean name.
275                // Note: We join the sftopics table because sfposts do not have topic_name.
276                $this->field_map[] = array(
277                        'from_tablename'  => 'sftopics',
278                        'from_fieldname'  => 'topic_name',
279                        'join_tablename'  => 'sfposts',
280                        'join_type'       => 'INNER',
281                        'join_expression' => 'USING (topic_id) WHERE sfposts.post_id = sftopics.post_id_held',
282                        'to_type'         => 'reply',
283                        'to_fieldname'    => 'post_name',
284                        'callback_method' => 'callback_slug'
285                );
286               
287                // Post content.
288                $this->field_map[] = array(
289                        'from_tablename'  => 'sfposts',
290                        'from_fieldname'  => 'post_content',
291                        'to_type'         => 'reply',
292                        'to_fieldname'    => 'post_content',
293                        'callback_method' => 'callback_html_simplepress'
294                );
295               
296                // Topic id.  If no parent, than 0.
297                $this->field_map[] = array(
298                        'from_tablename'  => 'sfposts',
299                        'from_fieldname'  => 'topic_id',
300                        'to_type'         => 'reply',
301                        'to_fieldname'    => 'post_parent',
302                        'callback_method' => 'callback_topicid'
303                );
304
305                // Topic date update.
306                $this->field_map[] = array(
307                        'from_tablename'  => 'sfposts',
308                        'from_fieldname'  => 'post_date',
309                        'to_type'         => 'reply',
310                        'to_fieldname'    => 'post_date',
311                        'callback_method' => 'callback_datetime'
312                );
313                $this->field_map[] = array(
314                        'from_tablename'  => 'sfposts',
315                        'from_fieldname'  => 'post_date',
316                        'to_type'         => 'reply',
317                        'to_fieldname'    => 'post_date_gmt',
318                        'callback_method' => 'callback_datetime'
319                );
320                $this->field_map[] = array(
321                        'from_tablename'  => 'sfposts',
322                        'from_fieldname'  => 'post_date',
323                        'to_type'         => 'reply',
324                        'to_fieldname'    => 'post_modified',
325                        'callback_method' => 'callback_datetime'
326                );
327                $this->field_map[] = array(
328                        'from_tablename'  => 'sfposts',
329                        'from_fieldname'  => 'post_date',
330                        'to_type'         => 'reply',
331                        'to_fieldname'    => 'post_modified_gmt',
332                        'callback_method' => 'callback_datetime'
333                );
334
335                /** User Section ******************************************************/
336
337                // Store old User id. Stores in usermeta.
338                $this->field_map[] = array(
339                        'from_tablename' => 'users',
340                        'from_fieldname' => 'ID',
341                        'to_type'        => 'user',
342                        'to_fieldname'   => '_bbp_user_id'
343                );
344               
345                // Store old User password. Stores in usermeta.
346                $this->field_map[] = array(
347                        'from_tablename' => 'users',
348                        'from_fieldname' => 'user_pass',
349                        'to_type'        => 'user',
350                        'to_fieldname'   => '_bbp_password'
351                );
352                               
353                // User name.
354                $this->field_map[] = array(
355                        'from_tablename' => 'users',
356                        'from_fieldname' => 'user_login',
357                        'to_type'        => 'user',
358                        'to_fieldname'   => 'user_login'
359                );
360
361                // User nice name.
362                $this->field_map[] = array(
363                        'from_tablename' => 'users',
364                        'from_fieldname' => 'user_nicename',
365                        'to_type'        => 'user',
366                        'to_fieldname'   => 'user_nicename'
367                );
368                               
369                // User email.
370                $this->field_map[] = array(
371                        'from_tablename' => 'users',
372                        'from_fieldname' => 'user_email',
373                        'to_type'        => 'user',
374                        'to_fieldname'   => 'user_email'
375                );
376               
377                // User homepage.
378                $this->field_map[] = array(
379                        'from_tablename' => 'users',
380                        'from_fieldname' => 'user_url',
381                        'to_type'        => 'user',
382                        'to_fieldname'   => 'user_url'
383                );
384               
385                // User registered.
386                $this->field_map[] = array(
387                        'from_tablename' => 'users',
388                        'from_fieldname' => 'user_registered',
389                        'to_type'        => 'user',
390                        'to_fieldname'   => 'user_registered'
391                );
392               
393                // User status.
394                $this->field_map[] = array(
395                        'from_tablename' => 'users',
396                        'from_fieldname' => 'user_status',
397                        'to_type'        => 'user',
398                        'to_fieldname'   => 'user_status'
399                );
400               
401                // User display name.
402                $this->field_map[] = array(
403                        'from_tablename' => 'users',
404                        'from_fieldname' => 'display_name',
405                        'to_type'        => 'user',
406                        'to_fieldname'   => 'display_name'
407                );
408        }
409
410        /**
411         * This method allows us to indicates what is or is not converted for each
412         * converter.
413         */
414        public function info() {
415                return '';
416        }
417
418        /**
419         * This method is to save the salt and password together. That
420         * way when we authenticate it we can get it out of the database
421         * as one value. Array values are auto sanitized by wordpress.
422         */
423        public function callback_savepass( $field, $row ) {
424                return false;
425        }
426
427        /**
428         * This method is to take the pass out of the database and compare
429         * to a pass the user has typed in.
430         */
431        public function authenticate_pass( $password, $serialized_pass ) {
432                return false;
433        }
434
435        /**
436         * This callback processes any custom parser.php attributes and custom code with preg_replace
437         */
438        protected function callback_html_simplepress( $field ) {
439
440                $simplepress_markup = $field;
441                $simplepress_markup = html_entity_decode ( $simplepress_markup );
442
443                // Replace any SimplePress smilies from path '/sp-resources/forum-smileys/sf-smily.gif' with the equivelant WordPress Smilie
444                $simplepress_markup = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-confused.gif(.*?)" \/>/'   , ':?'      , $simplepress_markup );
445                $simplepress_markup = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-cool.gif(.*?)" \/>/'       , ':cool:'  , $simplepress_markup );
446                $simplepress_markup = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-cry.gif(.*?)" \/>/'        , ':cry:'   , $simplepress_markup );
447                $simplepress_markup = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-embarassed.gif(.*?)" \/>/' , ':oops:'  , $simplepress_markup );
448                $simplepress_markup = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-frown.gif(.*?)" \/>/'      , ':('      , $simplepress_markup );
449                $simplepress_markup = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-kiss.gif(.*?)" \/>/'       , ':P'      , $simplepress_markup );
450                $simplepress_markup = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-laugh.gif(.*?)" \/>/'      , ':D'      , $simplepress_markup );
451                $simplepress_markup = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-smile.gif(.*?)" \/>/'      , ':smile:' , $simplepress_markup );
452                $simplepress_markup = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-surprised.gif(.*?)" \/>/'  , ':o'      , $simplepress_markup );
453                $simplepress_markup = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-wink.gif(.*?)" \/>/'       , ':wink:'  , $simplepress_markup );
454                $simplepress_markup = preg_replace ( '/<img src=(.*?)\/sp-resources\/forum-smileys\/sf-yell.gif(.*?)" \/>/'       , ':x'      , $simplepress_markup );
455
456                $field = $simplepress_markup;
457
458                require_once( bbpress()->admin->admin_dir . 'parser.php' );
459                $bbcode = BBCode::getInstance(); 
460                $bbcode->enable_smileys = true;
461                $bbcode->smiley_regex   = true;
462                return html_entity_decode( $bbcode->Parse( $field ) );
463        }       
464}