Skip to:
Content

bbPress.org

Ticket #2415: PHPFox.php

File PHPFox.php, 17.0 KB (added by netweb, 13 years ago)

PHPFox.php 1st Pass

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