Skip to:
Content

bbPress.org

Ticket #2382: Phorum.php

File Phorum.php, 14.6 KB (added by netweb, 11 years ago)

Phorum.php 3rd Pass

Line 
1<?php
2
3/**
4 * Implementation of Phorum Forum converter.
5 *
6 * @since bbPress (r5057)
7 * @link Codex Docs http://codex.bbpress.org/import-forums/phorum
8 */
9class Phorum extends BBP_Converter_Base {
10
11        /**
12         * Main Constructor
13         *
14         * @uses Phorum::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' => 'forums',
31                        'from_fieldname' => 'forum_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'  => 'forums',
39                        'from_fieldname'  => 'parent_id',
40                        'to_type'         => 'forum',
41                        'to_fieldname'    => '_bbp_forum_parent_id'
42                );
43
44                // Forum topic count (Stored in postmeta)
45                $this->field_map[] = array(
46                        'from_tablename' => 'forums',
47                        'from_fieldname' => 'thread_count',
48                        'to_type'        => 'forum',
49                        'to_fieldname'   => '_bbp_topic_count'
50                );
51
52                // Forum reply count (Stored in postmeta)
53                $this->field_map[] = array(
54                        'from_tablename' => 'forums',
55                        'from_fieldname' => 'message_count',
56                        'to_type'        => 'forum',
57                        'to_fieldname'   => '_bbp_reply_count'
58                );
59
60                // Forum title.
61                $this->field_map[] = array(
62                        'from_tablename' => 'forums',
63                        'from_fieldname' => 'name',
64                        'to_type'        => 'forum',
65                        'to_fieldname'   => 'post_title'
66                );
67
68                // Forum slug (Clean name to avoid conflicts)
69                $this->field_map[] = array(
70                        'from_tablename'  => 'forums',
71                        'from_fieldname'  => 'name',
72                        'to_type'         => 'forum',
73                        'to_fieldname'    => 'post_name',
74                        'callback_method' => 'callback_slug'
75                );
76
77                // Forum description.
78                $this->field_map[] = array(
79                        'from_tablename'  => 'forums',
80                        'from_fieldname'  => 'description',
81                        'to_type'         => 'forum',
82                        'to_fieldname'    => 'post_content',
83                        'callback_method' => 'callback_null'
84                );
85
86                // Forum display order (Starts from 1)
87                $this->field_map[] = array(
88                        'from_tablename' => 'forums',
89                        'from_fieldname' => 'display_order',
90                        'to_type'        => 'forum',
91                        'to_fieldname'   => 'menu_order'
92                );
93
94                // Forum type (Category = 1 or Forum = 0, Stored in postmeta)
95                $this->field_map[] = array(
96                        'from_tablename'  => 'forums',
97                        'from_fieldname'  => 'folder_flag',
98                        'to_type'         => 'forum',
99                        'to_fieldname'    => '_bbp_forum_type',
100                        'callback_method' => 'callback_forum_type'
101                );
102
103                // Forum dates.
104                $this->field_map[] = array(
105                        'to_type'      => 'forum',
106                        'to_fieldname' => 'post_date',
107                        'default'      => date('Y-m-d H:i:s')
108                );
109                $this->field_map[] = array(
110                        'to_type'      => 'forum',
111                        'to_fieldname' => 'post_date_gmt',
112                        'default'      => date('Y-m-d H:i:s')
113                );
114                $this->field_map[] = array(
115                        'to_type'      => 'forum',
116                        'to_fieldname' => 'post_modified',
117                        'default'      => date('Y-m-d H:i:s')
118                );
119                $this->field_map[] = array(
120                        'to_type'      => 'forum',
121                        'to_fieldname' => 'post_modified_gmt',
122                        'default'      => date('Y-m-d H:i:s')
123                );
124
125                /** Topic Section *****************************************************/
126
127                // Topic id (Stored in postmeta)
128                $this->field_map[] = array(
129                        'from_tablename'  => 'messages',
130                        'from_fieldname'  => 'thread',
131                        'from_expression' => 'WHERE parent_id = 0',
132                        'to_type'         => 'topic',
133                        'to_fieldname'    => '_bbp_topic_id'
134                );
135
136                // Topic reply count (Stored in postmeta)
137                $this->field_map[] = array(
138                        'from_tablename'  => 'messages',
139                        'from_fieldname'  => 'thread_count',
140                        'to_type'         => 'topic',
141                        'to_fieldname'    => '_bbp_reply_count',
142                        'callback_method' => 'callback_topic_reply_count'
143                );
144
145                // Topic total reply count (Includes unpublished replies, Stored in postmeta)
146                $this->field_map[] = array(
147                        'from_tablename'  => 'messages',
148                        'from_fieldname'  => 'thread_count',
149                        'to_type'         => 'topic',
150                        'to_fieldname'    => '_bbp_total_reply_count',
151                        'callback_method' => 'callback_topic_reply_count'
152                );
153
154                // Topic parent forum id (If no parent, then 0, Stored in postmeta)
155                $this->field_map[] = array(
156                        'from_tablename'  => 'messages',
157                        'from_fieldname'  => 'forum_id',
158                        'to_type'         => 'topic',
159                        'to_fieldname'    => '_bbp_forum_id',
160                        'callback_method' => 'callback_forumid'
161                );
162
163                // Topic author.
164                $this->field_map[] = array(
165                        'from_tablename'  => 'messages',
166                        'from_fieldname'  => 'user_id',
167                        'to_type'         => 'topic',
168                        'to_fieldname'    => 'post_author',
169                        'callback_method' => 'callback_userid'
170                );
171
172                // Topic Author ip (Stored in postmeta)
173                $this->field_map[] = array(
174                        'from_tablename'  => 'messages',
175                        'from_fieldname'  => 'ip',
176                        'to_type'         => 'topic',
177                        'to_fieldname'    => '_bbp_author_ip'
178                );
179
180                // Topic content.
181                $this->field_map[] = array(
182                        'from_tablename'  => 'messages',
183                        'from_fieldname'  => 'body',
184                        'to_type'         => 'topic',
185                        'to_fieldname'    => 'post_content',
186                        'callback_method' => 'callback_html'
187                );
188
189                // Topic title.
190                $this->field_map[] = array(
191                        'from_tablename' => 'messages',
192                        'from_fieldname' => 'subject',
193                        'to_type'        => 'topic',
194                        'to_fieldname'   => 'post_title'
195                );
196
197                // Topic slug (Clean name to avoid conflicts)
198                $this->field_map[] = array(
199                        'from_tablename'  => 'messages',
200                        'from_fieldname'  => 'subject',
201                        'to_type'         => 'topic',
202                        'to_fieldname'    => 'post_name',
203                        'callback_method' => 'callback_slug'
204                );
205
206                // Topic parent forum id (If no parent, then 0)
207                $this->field_map[] = array(
208                        'from_tablename'  => 'messages',
209                        'from_fieldname'  => 'forum_id',
210                        'to_type'         => 'topic',
211                        'to_fieldname'    => 'post_parent',
212                        'callback_method' => 'callback_forumid'
213                );
214
215                // Topic dates.
216                $this->field_map[] = array(
217                        'from_tablename'  => 'messages',
218                        'from_fieldname'  => 'datestamp',
219                        'to_type'         => 'topic',
220                        'to_fieldname'    => 'post_date',
221                        'callback_method' => 'callback_datetime'
222                );
223                $this->field_map[] = array(
224                        'from_tablename'  => 'messages',
225                        'from_fieldname'  => 'datestamp',
226                        'to_type'         => 'topic',
227                        'to_fieldname'    => 'post_date_gmt',
228                        'callback_method' => 'callback_datetime'
229                );
230                $this->field_map[] = array(
231                        'from_tablename'  => 'messages',
232                        'from_fieldname'  => 'datestamp',
233                        'to_type'         => 'topic',
234                        'to_fieldname'    => 'post_modified',
235                        'callback_method' => 'callback_datetime'
236                );
237                $this->field_map[] = array(
238                        'from_tablename'  => 'messages',
239                        'from_fieldname'  => 'datestamp',
240                        'to_type'         => 'topic',
241                        'to_fieldname'    => 'post_modified_gmt',
242                        'callback_method' => 'callback_datetime'
243                );
244                $this->field_map[] = array(
245                        'from_tablename'  => 'messages',
246                        'from_fieldname'  => 'datestamp',
247                        'to_type'         => 'topic',
248                        'to_fieldname'    => '_bbp_last_active_time',
249                        'callback_method' => 'callback_datetime'
250                );
251
252                // Topic status (Open = 0 or Closed = 1)
253                $this->field_map[] = array(
254                        'from_tablename'  => 'messages',
255                        'from_fieldname'  => 'closed',
256                        'to_type'         => 'topic',
257                        'to_fieldname'    => 'post_status',
258                        'callback_method' => 'callback_topic_status'
259                );
260
261                /** Tags Section ******************************************************/
262
263                /**
264                 * Phorum v5.2.19 Forums do not support topic tags out of the box
265                 */
266
267                /** Reply Section *****************************************************/
268
269                // Reply id (Stored in postmeta)
270                $this->field_map[] = array(
271                        'from_tablename'  => 'messages',
272                        'from_fieldname'  => 'message_id',
273                        'from_expression' => 'WHERE parent_id != 0',
274                        'to_type'         => 'reply',
275                        'to_fieldname'    => '_bbp_post_id'
276                );
277
278                // Reply parent forum id (If no parent, then 0. Stored in postmeta)
279                $this->field_map[] = array(
280                        'from_tablename'  => 'messages',
281                        'from_fieldname'  => 'forum_id',
282                        'to_type'         => 'reply',
283                        'to_fieldname'    => '_bbp_forum_id',
284                        'callback_method' => 'callback_topicid_to_forumid'
285                );
286
287                // Reply parent topic id (If no parent, then 0. Stored in postmeta)
288                $this->field_map[] = array(
289                        'from_tablename'  => 'messages',
290                        'from_fieldname'  => 'thread',
291                        'to_type'         => 'reply',
292                        'to_fieldname'    => '_bbp_topic_id',
293                        'callback_method' => 'callback_topicid'
294                );
295
296                // Reply author ip (Stored in postmeta)
297                $this->field_map[] = array(
298                        'from_tablename' => 'messages',
299                        'from_fieldname' => 'ip',
300                        'to_type'        => 'reply',
301                        'to_fieldname'   => '_bbp_author_ip'
302                );
303
304                // Reply author.
305                $this->field_map[] = array(
306                        'from_tablename'  => 'messages',
307                        'from_fieldname'  => 'user_id',
308                        'to_type'         => 'reply',
309                        'to_fieldname'    => 'post_author',
310                        'callback_method' => 'callback_userid'
311                );
312
313                // Reply title.
314                $this->field_map[] = array(
315                        'from_tablename' => 'messages',
316                        'from_fieldname' => 'subject',
317                        'to_type'        => 'reply',
318                        'to_fieldname'   => 'post_title'
319                );
320
321                // Reply slug (Clean name to avoid conflicts)
322                $this->field_map[] = array(
323                        'from_tablename'  => 'messages',
324                        'from_fieldname'  => 'subject',
325                        'to_type'         => 'reply',
326                        'to_fieldname'    => 'post_name',
327                        'callback_method' => 'callback_slug'
328                );
329
330                // Reply content.
331                $this->field_map[] = array(
332                        'from_tablename'  => 'messages',
333                        'from_fieldname'  => 'body',
334                        'to_type'         => 'reply',
335                        'to_fieldname'    => 'post_content',
336                        'callback_method' => 'callback_html'
337                );
338
339                // Reply parent topic id (If no parent, then 0)
340                $this->field_map[] = array(
341                        'from_tablename'  => 'messages',
342                        'from_fieldname'  => 'thread',
343                        'to_type'         => 'reply',
344                        'to_fieldname'    => 'post_parent',
345                        'callback_method' => 'callback_topicid'
346                );
347
348                // Reply dates.
349                $this->field_map[] = array(
350                        'from_tablename'  => 'messages',
351                        'from_fieldname'  => 'datestamp',
352                        'to_type'         => 'reply',
353                        'to_fieldname'    => 'post_date',
354                        'callback_method' => 'callback_datetime'
355                );
356                $this->field_map[] = array(
357                        'from_tablename'  => 'messages',
358                        'from_fieldname'  => 'datestamp',
359                        'to_type'         => 'reply',
360                        'to_fieldname'    => 'post_date_gmt',
361                        'callback_method' => 'callback_datetime'
362                );
363                $this->field_map[] = array(
364                        'from_tablename'  => 'messages',
365                        'from_fieldname'  => 'datestamp',
366                        'to_type'         => 'reply',
367                        'to_fieldname'    => 'post_modified',
368                        'callback_method' => 'callback_datetime'
369                );
370                $this->field_map[] = array(
371                        'from_tablename'  => 'messages',
372                        'from_fieldname'  => 'datestamp',
373                        'to_type'         => 'reply',
374                        'to_fieldname'    => 'post_modified_gmt',
375                        'callback_method' => 'callback_datetime'
376                );
377
378                /** User Section ******************************************************/
379
380                // Store old User id (Stored in usermeta)
381                $this->field_map[] = array(
382                        'from_tablename' => 'users',
383                        'from_fieldname' => 'user_id',
384                        'to_type'        => 'user',
385                        'to_fieldname'   => '_bbp_user_id'
386                );
387
388                // Store old User password (Stored in usermeta serialized with salt)
389                $this->field_map[] = array(
390                        'from_tablename'  => 'users',
391                        'from_fieldname'  => 'password',
392                        'to_type'         => 'user',
393                        'to_fieldname'    => '_bbp_password',
394                        'callback_method' => 'callback_savepass'
395                );
396
397                // Store old User Salt (This is only used for the SELECT row info for the above password save)
398//              $this->field_map[] = array(
399//                      'from_tablename' => 'users',
400//                      'from_fieldname' => 'salt',
401//                      'to_type'        => 'user',
402//                      'to_fieldname'   => ''
403//              );
404
405                // User password verify class (Stored in usermeta for verifying password)
406                $this->field_map[] = array(
407                        'to_type'      => 'users',
408                        'to_fieldname' => '_bbp_class',
409                        'default'      => 'Phorum'
410                );
411
412                // User name.
413                $this->field_map[] = array(
414                        'from_tablename' => 'users',
415                        'from_fieldname' => 'username',
416                        'to_type'        => 'user',
417                        'to_fieldname'   => 'user_login'
418                );
419
420                // User nice name.
421                $this->field_map[] = array(
422                        'from_tablename' => 'users',
423                        'from_fieldname' => 'display_name',
424                        'to_type'        => 'user',
425                        'to_fieldname'   => 'user_nicename'
426                );
427
428                // User email.
429                $this->field_map[] = array(
430                        'from_tablename' => 'users',
431                        'from_fieldname' => 'email',
432                        'to_type'        => 'user',
433                        'to_fieldname'   => 'user_email'
434                );
435
436                // User registered.
437                $this->field_map[] = array(
438                        'from_tablename'  => 'users',
439                        'from_fieldname'  => 'date_added',
440                        'to_type'         => 'user',
441                        'to_fieldname'    => 'user_registered',
442                        'callback_method' => 'callback_datetime'
443                );
444
445                // User display name.
446                $this->field_map[] = array(
447                        'from_tablename' => 'users',
448                        'from_fieldname' => 'real_name',
449                        'to_type'        => 'user',
450                        'to_fieldname'   => 'display_name'
451                );
452
453                // Store Signature (Stored in usermeta)
454                $this->field_map[] = array(
455                        'from_tablename' => 'users',
456                        'from_fieldname' => 'signature',
457                        'to_type'        => 'user',
458                        'to_fieldname'   => '_bbp_phorum_user_sig',
459                        'callback_method' => 'callback_html'
460                );
461
462        }
463
464        /**
465         * This method allows us to indicates what is or is not converted for each
466         * converter.
467         */
468        public function info()
469        {
470                return '';
471        }
472
473        /**
474         * This method is to save the salt and password together.  That
475         * way when we authenticate it we can get it out of the database
476         * as one value. Array values are auto sanitized by WordPress.
477         */
478        public function callback_savepass( $field, $row )
479        {
480                $pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
481                return $pass_array;
482        }
483
484        /**
485         * This method is to take the pass out of the database and compare
486         * to a pass the user has typed in.
487         */
488        public function authenticate_pass( $password, $serialized_pass )
489        {
490                $pass_array = unserialize( $serialized_pass );
491                return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) );
492        }
493
494        /**
495         * Translate the forum type from Phorum v5.2.19 numeric's to WordPress's strings.
496         *
497         * @param int $status Phorum v5.2.19 numeric forum type
498         * @return string WordPress safe
499         */
500        public function callback_forum_type( $status = 0 ) {
501                switch ( $status ) {
502                        case 1 :
503                                $status = 'category';
504                                break;
505
506                        case 0  :
507                        default :
508                                $status = 'forum';
509                                break;
510                }
511                return $status;
512        }
513
514        /**
515         * Translate the post status from Phorum v5.2.19 numeric's to WordPress's strings.
516         *
517         * @param int $status Phorum v5.2.19 numeric topic status
518         * @return string WordPress safe
519         */
520        public function callback_topic_status( $status = 0 ) {
521                switch ( $status ) {
522                        case 1 :
523                                $status = 'closed';
524                                break;
525
526                        case 0  :
527                        default :
528                                $status = 'publish';
529                                break;
530                }
531                return $status;
532        }
533
534        /**
535         * Verify the topic/reply count.
536         *
537         * @param int $count Phorum v5.2.19 topic/reply counts
538         * @return string WordPress safe
539         */
540        public function callback_topic_reply_count( $count = 1 ) {
541                $count = absint( (int) $count - 1 );
542                return $count;
543        }
544
545}