Skip to:
Content

bbPress.org

Ticket #2384: AEF.php

File AEF.php, 18.4 KB (added by netweb, 12 years ago)

AEF 3rd Pass

Line 
1<?php
2
3/**
4 * Implementation of AEF Forum converter.
5 *
6 * @since bbPress (r5057)
7 * @link Codex Docs http://codex.bbpress.org/import-forums/aef
8 */
9class AEF extends BBP_Converter_Base {
10
11        /**
12         * Main Constructor
13         *
14         * @uses AEF::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' => 'fid',
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'  => 'par_board_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' => 'ntopic',
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' => 'nposts',
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' => 'forums',
63                        'from_fieldname' => 'ntopic',
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' => 'forums',
71                        'from_fieldname' => 'nposts',
72                        'to_type'        => 'forum',
73                        'to_fieldname'   => '_bbp_total_reply_count'
74                );
75
76                // Forum title.
77                $this->field_map[] = array(
78                        'from_tablename' => 'forums',
79                        'from_fieldname' => 'fname',
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'  => 'forums',
87                        'from_fieldname'  => 'fname',
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'  => 'forums',
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' => 'forums',
105                        'from_fieldname' => 'forum_order',
106                        'to_type'        => 'forum',
107                        'to_fieldname'   => 'menu_order'
108                );
109
110                // Forum status (Unlocked = 1 or Locked = 0, Stored in postmeta)
111                $this->field_map[] = array(
112                        'from_tablename'  => 'forums',
113                        'from_fieldname'  => 'status',
114                        'to_type'         => 'forum',
115                        'to_fieldname'    => '_bbp_status',
116                        'callback_method' => 'callback_forum_status'
117                );
118
119                // Forum dates.
120                $this->field_map[] = array(
121                        'to_type'      => 'forum',
122                        'to_fieldname' => 'post_date',
123                        'default'      => date('Y-m-d H:i:s')
124                );
125                $this->field_map[] = array(
126                        'to_type'      => 'forum',
127                        'to_fieldname' => 'post_date_gmt',
128                        'default'      => date('Y-m-d H:i:s')
129                );
130                $this->field_map[] = array(
131                        'to_type'      => 'forum',
132                        'to_fieldname' => 'post_modified',
133                        'default'      => date('Y-m-d H:i:s')
134                );
135                $this->field_map[] = array(
136                        'to_type'      => 'forum',
137                        'to_fieldname' => 'post_modified_gmt',
138                        'default'      => date('Y-m-d H:i:s')
139                );
140
141                /** Topic Section *****************************************************/
142
143                // Topic id (Stored in postmeta)
144                $this->field_map[] = array(
145                        'from_tablename' => 'topics',
146                        'from_fieldname' => 'tid',
147                        'to_type'        => 'topic',
148                        'to_fieldname'   => '_bbp_topic_id'
149                );
150
151                // Topic reply count (Stored in postmeta)
152                $this->field_map[] = array(
153                        'from_tablename'  => 'topics',
154                        'from_fieldname'  => 'n_posts',
155                        'to_type'         => 'topic',
156                        'to_fieldname'    => '_bbp_reply_count',
157                        'callback_method' => 'callback_topic_reply_count'
158                );
159
160                // Topic total reply count (Includes unpublished replies, Stored in postmeta)
161                $this->field_map[] = array(
162                        'from_tablename'  => 'topics',
163                        'from_fieldname'  => 'n_posts',
164                        'to_type'         => 'topic',
165                        'to_fieldname'    => '_bbp_total_reply_count',
166                        'callback_method' => 'callback_topic_reply_count'
167                );
168
169                // Topic parent forum id (If no parent, then 0, Stored in postmeta)
170                $this->field_map[] = array(
171                        'from_tablename'  => 'topics',
172                        'from_fieldname'  => 't_bid',
173                        'to_type'         => 'topic',
174                        'to_fieldname'    => '_bbp_forum_id',
175                        'callback_method' => 'callback_forumid'
176                );
177
178                // Topic author.
179                // Note: We join the 'posts' table because 'topics' table does not include author id.
180                $this->field_map[] = array(
181                        'from_tablename'  => 'posts',
182                        'from_fieldname'  => 'poster_id',
183                        'join_tablename'  => 'topics',
184                        'join_type'       => 'INNER',
185                        'join_expression' => 'ON topics.first_post_id = posts.pid',
186                        'to_type'         => 'topic',
187                        'to_fieldname'    => 'post_author',
188                        'callback_method' => 'callback_userid'
189                );
190
191                // Topic Author ip (Stored in postmeta)
192                // Note: We join the 'posts' table because 'topics' table does not include author ip.
193                $this->field_map[] = array(
194                        'from_tablename'  => 'posts',
195                        'from_fieldname'  => 'poster_ip',
196                        'join_tablename'  => 'topics',
197                        'join_type'       => 'INNER',
198                        'join_expression' => 'ON topics.first_post_id = posts.pid',
199                        'to_type'         => 'topic',
200                        'to_fieldname'    => '_bbp_author_ip'
201                );
202
203                // Topic content.
204                // Note: We join the 'posts' table because 'topics' table does not include topic content.
205                $this->field_map[] = array(
206                        'from_tablename'  => 'posts',
207                        'from_fieldname'  => 'post',
208                        'join_tablename'  => 'topics',
209                        'join_type'       => 'INNER',
210                        'join_expression' => 'ON topics.first_post_id = posts.pid',
211                        'to_type'         => 'topic',
212                        'to_fieldname'    => 'post_content',
213                        'callback_method' => 'callback_html'
214                );
215
216                // Topic title.
217                $this->field_map[] = array(
218                        'from_tablename' => 'topics',
219                        'from_fieldname' => 'topic',
220                        'to_type'        => 'topic',
221                        'to_fieldname'   => 'post_title'
222                );
223
224                // Topic slug (Clean name to avoid conflicts)
225                $this->field_map[] = array(
226                        'from_tablename'  => 'topics',
227                        'from_fieldname'  => 'topic',
228                        'to_type'         => 'topic',
229                        'to_fieldname'    => 'post_name',
230                        'callback_method' => 'callback_slug'
231                );
232
233                // Topic parent forum id (If no parent, then 0)
234                $this->field_map[] = array(
235                        'from_tablename'  => 'topics',
236                        'from_fieldname'  => 't_bid',
237                        'to_type'         => 'topic',
238                        'to_fieldname'    => 'post_parent',
239                        'callback_method' => 'callback_forumid'
240                );
241
242                // Topic dates.
243                // Note: We join the 'posts' table because 'topics' table does not include topic dates.
244                $this->field_map[] = array(
245                        'from_tablename'  => 'posts',
246                        'from_fieldname'  => 'ptime',
247                        'join_tablename'  => 'topics',
248                        'join_type'       => 'INNER',
249                        'join_expression' => 'ON topics.first_post_id = posts.pid',
250                        'to_type'         => 'topic',
251                        'to_fieldname'    => 'post_date',
252                        'callback_method' => 'callback_datetime'
253                );
254                $this->field_map[] = array(
255                        'from_tablename'  => 'posts',
256                        'from_fieldname'  => 'ptime',
257                        'join_tablename'  => 'topics',
258                        'join_type'       => 'INNER',
259                        'join_expression' => 'ON topics.first_post_id = posts.pid',
260                        'to_type'         => 'topic',
261                        'to_fieldname'    => 'post_date_gmt',
262                        'callback_method' => 'callback_datetime'
263                );
264                $this->field_map[] = array(
265                        'from_tablename'  => 'posts',
266                        'from_fieldname'  => 'ptime',
267                        'join_tablename'  => 'topics',
268                        'join_type'       => 'INNER',
269                        'join_expression' => 'ON topics.first_post_id = posts.pid',
270                        'to_type'         => 'topic',
271                        'to_fieldname'    => 'post_modified',
272                        'callback_method' => 'callback_datetime'
273                );
274                $this->field_map[] = array(
275                        'from_tablename'  => 'posts',
276                        'from_fieldname'  => 'ptime',
277                        'join_tablename'  => 'topics',
278                        'join_type'       => 'INNER',
279                        'join_expression' => 'ON topics.first_post_id = posts.pid',
280                        'to_type'         => 'topic',
281                        'to_fieldname'    => 'post_modified_gmt',
282                        'callback_method' => 'callback_datetime'
283                );
284                $this->field_map[] = array(
285                        'from_tablename'  => 'posts',
286                        'from_fieldname'  => 'ptime',
287                        'join_tablename'  => 'topics',
288                        'join_type'       => 'INNER',
289                        'join_expression' => 'ON topics.first_post_id = posts.pid',
290                        'to_type'         => 'topic',
291                        'to_fieldname'    => '_bbp_last_active_time',
292                        'callback_method' => 'callback_datetime'
293                );
294
295                // Topic status (Open = 1 or Closed = 0, AEF v1.0.9)
296                $this->field_map[] = array(
297                        'from_tablename'  => 'topics',
298                        'from_fieldname'  => 't_status',
299                        'to_type'         => 'topic',
300                        'to_fieldname'    => 'post_status',
301                        'callback_method' => 'callback_topic_status'
302                );
303
304                /** Tags Section ******************************************************/
305
306                /**
307                 * AEF v1.0.9 Forums do not support topic tags out of the box
308                 */
309
310                /** Reply Section *****************************************************/
311
312                // Reply id (Stored in postmeta)
313                $this->field_map[] = array(
314                        'from_tablename'  => 'posts',
315                        'from_fieldname'  => 'pid',
316                        'to_type'         => 'reply',
317                        'to_fieldname'    => '_bbp_post_id'
318                );
319
320                // Reply parent forum id (If no parent, then 0, Stored in postmeta)
321                $this->field_map[] = array(
322                        'from_tablename'  => 'posts',
323                        'from_fieldname'  => 'post_fid',
324                        'to_type'         => 'reply',
325                        'to_fieldname'    => '_bbp_forum_id',
326                        'callback_method' => 'callback_topicid_to_forumid'
327                );
328
329                // Reply parent topic id (If no parent, then 0, Stored in postmeta)
330                $this->field_map[] = array(
331                        'from_tablename'  => 'posts',
332                        'from_fieldname'  => 'post_tid',
333                        'to_type'         => 'reply',
334                        'to_fieldname'    => '_bbp_topic_id',
335                        'callback_method' => 'callback_topicid'
336                );
337
338                // Reply author ip (Stored in postmeta)
339                $this->field_map[] = array(
340                        'from_tablename' => 'posts',
341                        'from_fieldname' => 'poster_ip',
342                        'to_type'        => 'reply',
343                        'to_fieldname'   => '_bbp_author_ip'
344                );
345
346                // Reply author.
347                $this->field_map[] = array(
348                        'from_tablename'  => 'posts',
349                        'from_fieldname'  => 'poster_id',
350                        'to_type'         => 'reply',
351                        'to_fieldname'    => 'post_author',
352                        'callback_method' => 'callback_userid'
353                );
354
355                // Reply title.
356                // Note: We join the 'topics' table because 'posts' table does not include reply title.
357                $this->field_map[] = array(
358                        'from_tablename'  => 'topics',
359                        'from_fieldname'  => 'topic',
360                        'join_tablename'  => 'posts',
361                        'join_type'       => 'INNER',
362                        'join_expression' => 'ON topics.tid = posts.post_tid WHERE topics.first_post_id != posts.pid',
363                        'to_type'         => 'reply',
364                        'to_fieldname'    => 'post_title',
365                        'callback_method' => 'callback_reply_title'
366                );
367
368                // Reply slug (Clean name to avoid conflicts)
369                // Note: We join the 'topics' table because 'posts' table does not include reply slug.
370                $this->field_map[] = array(
371                        'from_tablename'  => 'topics',
372                        'from_fieldname'  => 'topic',
373                        'join_tablename'  => 'posts',
374                        'join_type'       => 'INNER',
375                        'join_expression' => 'ON topics.tid = posts.post_tid WHERE topics.first_post_id != posts.pid',
376                        'to_type'         => 'reply',
377                        'to_fieldname'    => 'post_name',
378                        'callback_method' => 'callback_slug'
379                );
380
381                // Reply content.
382                $this->field_map[] = array(
383                        'from_tablename'  => 'posts',
384                        'from_fieldname'  => 'post',
385                        'to_type'         => 'reply',
386                        'to_fieldname'    => 'post_content',
387                        'callback_method' => 'callback_html'
388                );
389
390                // Reply parent topic id (If no parent, then 0)
391                $this->field_map[] = array(
392                        'from_tablename'  => 'posts',
393                        'from_fieldname'  => 'post_tid',
394                        'to_type'         => 'reply',
395                        'to_fieldname'    => 'post_parent',
396                        'callback_method' => 'callback_topicid'
397                );
398
399                // Reply dates.
400                $this->field_map[] = array(
401                        'from_tablename'  => 'posts',
402                        'from_fieldname'  => 'ptime',
403                        'to_type'         => 'reply',
404                        'to_fieldname'    => 'post_date',
405                        'callback_method' => 'callback_datetime'
406                );
407                $this->field_map[] = array(
408                        'from_tablename'  => 'posts',
409                        'from_fieldname'  => 'ptime',
410                        'to_type'         => 'reply',
411                        'to_fieldname'    => 'post_date_gmt',
412                        'callback_method' => 'callback_datetime'
413                );
414                $this->field_map[] = array(
415                        'from_tablename'  => 'posts',
416                        'from_fieldname'  => 'ptime',
417                        'to_type'         => 'reply',
418                        'to_fieldname'    => 'post_modified',
419                        'callback_method' => 'callback_datetime'
420                );
421                $this->field_map[] = array(
422                        'from_tablename'  => 'posts',
423                        'from_fieldname'  => 'ptime',
424                        'to_type'         => 'reply',
425                        'to_fieldname'    => 'post_modified_gmt',
426                        'callback_method' => 'callback_datetime'
427                );
428
429                /** User Section ******************************************************/
430
431                // Store old User id (Stored in usermeta)
432                $this->field_map[] = array(
433                        'from_tablename' => 'users',
434                        'from_fieldname' => 'id',
435                        'to_type'        => 'user',
436                        'to_fieldname'   => '_bbp_user_id'
437                );
438
439                // Store old User password (Stored in usermeta serialized with salt)
440                $this->field_map[] = array(
441                        'from_tablename'  => 'users',
442                        'from_fieldname'  => 'password',
443                        'to_type'         => 'user',
444                        'to_fieldname'    => '_bbp_password',
445                        'callback_method' => 'callback_savepass'
446                );
447
448                // Store old User Salt (This is only used for the SELECT row info for the above password save)
449                $this->field_map[] = array(
450                        'from_tablename' => 'users',
451                        'from_fieldname' => 'salt',
452                        'to_type'        => 'user',
453                        'to_fieldname'   => ''
454                );
455
456                // User password verify class (Stored in usermeta for verifying password)
457                $this->field_map[] = array(
458                        'to_type'      => 'users',
459                        'to_fieldname' => '_bbp_class',
460                        'default'      => 'AEF'
461                );
462
463                // User name.
464                $this->field_map[] = array(
465                        'from_tablename' => 'users',
466                        'from_fieldname' => 'username',
467                        'to_type'        => 'user',
468                        'to_fieldname'   => 'user_login'
469                );
470
471                // User nice name.
472                $this->field_map[] = array(
473                        'from_tablename' => 'users',
474                        'from_fieldname' => 'username',
475                        'to_type'        => 'user',
476                        'to_fieldname'   => 'user_nicename'
477                );
478
479                // User email.
480                $this->field_map[] = array(
481                        'from_tablename' => 'users',
482                        'from_fieldname' => 'email',
483                        'to_type'        => 'user',
484                        'to_fieldname'   => 'user_email'
485                );
486
487                // User homepage.
488                $this->field_map[] = array(
489                        'from_tablename' => 'users',
490                        'from_fieldname' => 'www',
491                        'to_type'        => 'user',
492                        'to_fieldname'   => 'user_url'
493                );
494
495                // User registered.
496                $this->field_map[] = array(
497                        'from_tablename'  => 'users',
498                        'from_fieldname'  => 'r_time',
499                        'to_type'         => 'user',
500                        'to_fieldname'    => 'user_registered',
501                        'callback_method' => 'callback_datetime'
502                );
503
504                // User AIM (Stored in usermeta)
505                $this->field_map[] = array(
506                        'from_tablename' => 'users',
507                        'from_fieldname' => 'aim',
508                        'to_type'        => 'user',
509                        'to_fieldname'   => 'aim'
510                );
511
512                // User Yahoo (Stored in usermeta)
513                $this->field_map[] = array(
514                        'from_tablename' => 'users',
515                        'from_fieldname' => 'yim',
516                        'to_type'        => 'user',
517                        'to_fieldname'   => 'yim'
518                );
519
520                // Store ICQ (Stored in usermeta)
521                $this->field_map[] = array(
522                        'from_tablename' => 'users',
523                        'from_fieldname' => 'icq',
524                        'to_type'        => 'user',
525                        'to_fieldname'   => '_bbp_aef_user_icq'
526                );
527
528                // Store MSN (Stored in usermeta)
529                $this->field_map[] = array(
530                        'from_tablename' => 'users',
531                        'from_fieldname' => 'msn',
532                        'to_type'        => 'user',
533                        'to_fieldname'   => '_bbp_aef_user_msn'
534                );
535
536                // Store Gmail (Stored in usermeta)
537                $this->field_map[] = array(
538                        'from_tablename' => 'users',
539                        'from_fieldname' => 'gmail',
540                        'to_type'        => 'user',
541                        'to_fieldname'   => '_bbp_aef_user_gmail'
542                );
543
544                // Store Signature (Stored in usermeta)
545                $this->field_map[] = array(
546                        'from_tablename' => 'users',
547                        'from_fieldname' => 'sig',
548                        'to_type'        => 'user',
549                        'to_fieldname'   => '_bbp_aef_user_sig',
550                        'callback_method' => 'callback_html'
551                );
552
553                // Store Location (Stored in usermeta)
554                $this->field_map[] = array(
555                        'from_tablename' => 'users',
556                        'from_fieldname' => 'location',
557                        'to_type'        => 'user',
558                        'to_fieldname'   => '_bbp_aef_user_location'
559                );
560
561                // Store PrivateText (Stored in usermeta)
562                $this->field_map[] = array(
563                        'from_tablename' => 'users',
564                        'from_fieldname' => 'users_text',
565                        'to_type'        => 'user',
566                        'to_fieldname'   => '_bbp_aef_user_private_text'
567                );
568
569        }
570
571        /**
572         * This method allows us to indicates what is or is not converted for each
573         * converter.
574         */
575        public function info()
576        {
577                return '';
578        }
579
580        /**
581         * This method is to save the salt and password together.  That
582         * way when we authenticate it we can get it out of the database
583         * as one value. Array values are auto sanitized by WordPress.
584         */
585        public function callback_savepass( $field, $row )
586        {
587                $pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
588                return $pass_array;
589        }
590
591        /**
592         * This method is to take the pass out of the database and compare
593         * to a pass the user has typed in.
594         */
595        public function authenticate_pass( $password, $serialized_pass )
596        {
597                $pass_array = unserialize( $serialized_pass );
598                return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) );
599        }
600
601        /**
602         * Translate the forum status from AEF v1.0.9 numeric's to WordPress's strings.
603         *
604         * @param int $status AEF v1.0.9 numeric forum status
605         * @return string WordPress safe
606         */
607        public function callback_forum_status( $status = 1 ) {
608                switch ( $status ) {
609                        case 0 :
610                                $status = 'closed';
611                                break;
612
613                        case 1 :
614                        default :
615                                $status = 'open';
616                                break;
617                }
618                return $status;
619        }
620
621        /**
622         * Translate the post status from AEF v1.0.9 numeric's to WordPress's strings.
623         *
624         * @param int $status AEF v1.0.9 numeric topic status
625         * @return string WordPress safe
626         */
627        public function callback_topic_status( $status = 1 ) {
628                switch ( $status ) {
629                        case 0 :
630                                $status = 'closed';
631                                break;
632
633                        case 1  :
634                        default :
635                                $status = 'publish';
636                                break;
637                }
638                return $status;
639        }
640
641        /**
642         * Verify the topic/reply count.
643         *
644         * @param int $count AEF v1.0.9 topic/reply counts
645         * @return string WordPress safe
646         */
647        public function callback_topic_reply_count( $count = 1 ) {
648                $count = absint( (int) $count - 1 );
649                return $count;
650        }
651
652        /**
653         * Set the reply title
654         *
655         * @param string $title AEF v1.0.9 topic title of this reply
656         * @return string Prefixed topic title, or empty string
657         */
658        public function callback_reply_title( $title = '' ) {
659                $title = !empty( $title ) ? __( 'Re: ', 'bbpress' ) . html_entity_decode( $title ) : '';
660                return $title;
661        }
662}