Skip to:
Content

bbPress.org

Ticket #2402: Kunena1.php

File Kunena1.php, 17.4 KB (added by netweb, 11 years ago)

Kunena v1.x Importer

Line 
1<?php
2
3/**
4 * Implementation of Kunena v1.x Forums for Joomla Forum converter.
5 *
6 * @since bbPress (r5057)
7 * @link Codex Docs http://codex.bbpress.org/import-forums/kunena/
8 */
9class Kunena1 extends BBP_Converter_Base {
10
11        /**
12         * Main Constructor
13         *
14         * @uses Kunena1::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' => 'kunena_categories',
31                'from_fieldname' => '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' => 'kunena_categories',
39                'from_fieldname' => 'parent',
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' => 'kunena_categories',
47                        'from_fieldname' => 'numTopics',
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' => 'kunena_categories',
55                        'from_fieldname' => 'numPosts',
56                        'to_type'        => 'forum',
57                        'to_fieldname'   => '_bbp_reply_count'
58                );
59
60                // Forum total topic count (Includes unpublished topics, Stored in postmeta)
61                $this->field_map[] = array(
62                        'from_tablename'  => 'kunena_categories',
63                        'from_fieldname'  => 'numTopics',
64                        'to_type'         => 'forum',
65                        'to_fieldname'    => '_bbp_total_topic_count'
66                );
67
68                // Forum total reply count (Includes unpublished replies, Stored in postmeta)
69                $this->field_map[] = array(
70                        'from_tablename'  => 'kunena_categories',
71                        'from_fieldname'  => 'numPosts',
72                        'to_type'         => 'forum',
73                        'to_fieldname'    => '_bbp_total_reply_count'
74                );
75
76        // Forum title.
77        $this->field_map[] = array(
78                'from_tablename' => 'kunena_categories',
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'  => 'kunena_categories',
87                'from_fieldname'  => 'name',
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'  => 'kunena_categories',
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' => 'kunena_categories',
105                'from_fieldname' => 'ordering',
106                'to_type'        => 'forum',
107                'to_fieldname'   => 'menu_order'
108                );
109
110                // Forum type (Category = 0 or Forum = >0, Stored in postmeta)
111                $this->field_map[] = array(
112                        'from_tablename'  => 'kunena_categories',
113                        'from_fieldname'  => 'parent',
114                        'to_type'         => 'forum',
115                        'to_fieldname'    => '_bbp_forum_type',
116                        'callback_method' => 'callback_forum_type'
117                );
118
119                // Forum status (Open = 0 or Closed = 1, Stored in postmeta)
120                $this->field_map[] = array(
121                        'from_tablename'  => 'kunena_categories',
122                        'from_fieldname'  => 'locked',
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' => 'kunena_messages',
155                        'from_fieldname' => 'thread',
156                        'to_type'        => 'topic',
157                        'to_fieldname'   => '_bbp_topic_id'
158                );
159
160                // Topic parent forum id (If no parent, then 0. Stored in postmeta)
161                $this->field_map[] = array(
162                        'from_tablename'  => 'kunena_messages',
163                        'from_fieldname'  => 'catid',
164                        'to_type'         => 'topic',
165                        'to_fieldname'    => '_bbp_forum_id',
166                        'callback_method' => 'callback_forumid'
167                );
168
169                // Topic author.
170                $this->field_map[] = array(
171                        'from_tablename'  => 'kunena_messages',
172                        'from_fieldname'  => 'userid',
173                        'to_type'         => 'topic',
174                        'to_fieldname'    => 'post_author',
175                        'callback_method' => 'callback_userid'
176                );
177
178                // Topic Author ip (Stored in postmeta)
179                $this->field_map[] = array(
180                        'from_tablename'  => 'kunena_messages',
181                        'from_fieldname'  => 'ip',
182                        'to_type'         => 'topic',
183                        'to_fieldname'    => '_bbp_author_ip'
184                );
185
186                // Topic content.
187                // Note: We join the 'kunena_messages_text' table because 'kunena_messages' table does not include topic content.
188                $this->field_map[] = array(
189                        'from_tablename'  => 'kunena_messages_text',
190                        'from_fieldname'  => 'message',
191                        'join_tablename'  => 'kunena_messages',
192                        'join_type'       => 'INNER',
193                        'join_expression' => 'ON kunena_messages_text.mesid = kunena_messages.id WHERE kunena_messages.parent = 0',
194                        'to_type'         => 'topic',
195                        'to_fieldname'    => 'post_content',
196                        'callback_method' => 'callback_html'
197                );
198
199                // Topic title.
200                $this->field_map[] = array(
201                        'from_tablename' => 'kunena_messages',
202                        'from_fieldname' => 'subject',
203                        'to_type'        => 'topic',
204                        'to_fieldname'   => 'post_title'
205                );
206
207                // Topic slug (Clean name to avoid conflicts)
208                $this->field_map[] = array(
209                        'from_tablename'  => 'kunena_messages',
210                        'from_fieldname'  => 'subject',
211                        'to_type'         => 'topic',
212                        'to_fieldname'    => 'post_name',
213                        'callback_method' => 'callback_slug'
214                );
215
216                // Topic parent forum id (If no parent, then 0)
217                $this->field_map[] = array(
218                        'from_tablename'  => 'kunena_messages',
219                        'from_fieldname'  => 'catid',
220                        'to_type'         => 'topic',
221                        'to_fieldname'    => 'post_parent',
222                        'callback_method' => 'callback_forumid'
223                );
224
225                // Topic dates.
226                $this->field_map[] = array(
227                        'from_tablename'  => 'kunena_messages',
228                        'from_fieldname'  => 'time',
229                        'to_type'         => 'topic',
230                        'to_fieldname'    => 'post_date',
231                        'callback_method' => 'callback_datetime'
232                );
233                $this->field_map[] = array(
234                        'from_tablename'  => 'kunena_messages',
235                        'from_fieldname'  => 'time',
236                        'to_type'         => 'topic',
237                        'to_fieldname'    => 'post_date_gmt',
238                        'callback_method' => 'callback_datetime'
239                );
240                $this->field_map[] = array(
241                        'from_tablename'  => 'kunena_messages',
242                        'from_fieldname'  => 'time',
243                        'to_type'         => 'topic',
244                        'to_fieldname'    => 'post_modified',
245                        'callback_method' => 'callback_datetime'
246                );
247                $this->field_map[] = array(
248                        'from_tablename'  => 'kunena_messages',
249                        'from_fieldname'  => 'time',
250                        'to_type'         => 'topic',
251                        'to_fieldname'    => 'post_modified_gmt',
252                        'callback_method' => 'callback_datetime'
253                );
254                $this->field_map[] = array(
255                        'from_tablename'  => 'kunena_messages',
256                        'from_fieldname'  => 'time',
257                        'to_type'         => 'topic',
258                        'to_fieldname'    => '_bbp_last_active_time',
259                        'callback_method' => 'callback_datetime'
260                );
261
262                // Topic status (Open or Closed, Kunena v3.x 0=open & 1=closed)
263                $this->field_map[] = array(
264                        'from_tablename'  => 'kunena_messages',
265                        'from_fieldname'  => 'locked',
266                        'to_type'         => 'topic',
267                        'to_fieldname'    => 'post_status',
268                        'callback_method' => 'callback_topic_status'
269                );
270
271        /** Tags Section ******************************************************/
272
273                /**
274                 * Kunena v1.x Forums do not support topic tags out of the box
275                 */
276
277        /** Reply Section *****************************************************/
278
279        // Reply id (Stored in postmeta)
280        $this->field_map[] = array(
281                'from_tablename' => 'kunena_messages',
282                'from_fieldname' => 'id',
283                'to_type'        => 'reply',
284                'to_fieldname'   => '_bbp_post_id'
285                );
286
287        // Reply parent forum id (If no parent, then 0. Stored in postmeta)
288        $this->field_map[] = array(
289                'from_tablename'  => 'kunena_messages',
290                'from_fieldname'  => 'catid',
291                'to_type'         => 'reply',
292                'to_fieldname'    => '_bbp_forum_id',
293                'callback_method' => 'callback_topicid_to_forumid'
294                );
295
296        // Reply parent topic id (If no parent, then 0. Stored in postmeta)
297        $this->field_map[] = array(
298                'from_tablename'  => 'kunena_messages',
299                'from_fieldname'  => 'thread',
300                'to_type'         => 'reply',
301                'to_fieldname'    => '_bbp_topic_id',
302                'callback_method' => 'callback_topicid'
303                );
304
305        // Reply author ip (Stored in postmeta)
306        $this->field_map[] = array(
307                'from_tablename' => 'kunena_messages',
308                'from_fieldname' => 'ip',
309                'to_type'        => 'reply',
310                'to_fieldname'   => '_bbp_author_ip'
311                );
312
313        // Reply author.
314        $this->field_map[] = array(
315                'from_tablename'  => 'kunena_messages',
316                'from_fieldname'  => 'userid',
317                'to_type'         => 'reply',
318                'to_fieldname'    => 'post_author',
319                'callback_method' => 'callback_userid'
320                );
321
322        // Reply title.
323        $this->field_map[] = array(
324                'from_tablename' => 'kunena_messages',
325                'from_fieldname' => 'subject',
326                'to_type'        => 'reply',
327                'to_fieldname'   => 'post_title',
328                'callback_method' => 'callback_reply_title'
329                );
330
331        // Reply slug (Clean name to avoid conflicts)
332        $this->field_map[] = array(
333                'from_tablename'  => 'kunena_messages',
334                'from_fieldname'  => 'subject',
335                'to_type'         => 'reply',
336                'to_fieldname'    => 'post_name',
337                'callback_method' => 'callback_slug'
338                );
339
340        // Reply content.
341        // Note: We join the 'kunena_messages_text' table because 'kunena_messages' table does not include reply content.
342        $this->field_map[] = array(
343                'from_tablename'  => 'kunena_messages_text',
344                'from_fieldname'  => 'message',
345                'join_tablename'  => 'kunena_messages',
346                'join_type'       => 'INNER',
347                'join_expression' => 'ON kunena_messages.id = kunena_messages_text.mesid WHERE kunena_messages.parent != 0',
348                'to_type'         => 'reply',
349                'to_fieldname'    => 'post_content',
350                'callback_method' => 'callback_html'
351                );
352
353        // Reply parent topic id (If no parent, then 0)
354        $this->field_map[] = array(
355                'from_tablename'  => 'kunena_messages',
356                'from_fieldname'  => 'thread',
357                'to_type'         => 'reply',
358                'to_fieldname'    => 'post_parent',
359                'callback_method' => 'callback_topicid'
360                );
361
362        // Reply dates.
363        $this->field_map[] = array(
364                'from_tablename'  => 'kunena_messages',
365                'from_fieldname'  => 'time',
366                'to_type'         => 'reply',
367                'to_fieldname'    => 'post_date',
368                'callback_method' => 'callback_datetime'
369                );
370        $this->field_map[] = array(
371                'from_tablename'  => 'kunena_messages',
372                'from_fieldname'  => 'time',
373                'to_type'         => 'reply',
374                'to_fieldname'    => 'post_date_gmt',
375                'callback_method' => 'callback_datetime'
376                );
377        $this->field_map[] = array(
378                'from_tablename'  => 'kunena_messages',
379                'from_fieldname'  => 'time',
380                'to_type'         => 'reply',
381                'to_fieldname'    => 'post_modified',
382                'callback_method' => 'callback_datetime'
383                );
384        $this->field_map[] = array(
385                'from_tablename'  => 'kunena_messages',
386                'from_fieldname'  => 'time',
387                'to_type'         => 'reply',
388                'to_fieldname'    => 'post_modified_gmt',
389                'callback_method' => 'callback_datetime'
390                );
391
392        /** User Section ******************************************************/
393
394        //Note: We are importing the Joomla User details and the Kunena v3.x user profile details.
395
396        // Store old User id (Stored in usermeta)
397        $this->field_map[] = array(
398                'from_tablename' => 'users',
399                'from_fieldname' => 'id',
400                'to_type'        => 'user',
401                'to_fieldname'   => '_bbp_user_id'
402                );
403
404        // Store old User password (Stored in usermeta serialized with salt)
405        $this->field_map[] = array(
406                'from_tablename'  => 'users',
407                'from_fieldname'  => 'password',
408                'to_type'         => 'user',
409                'to_fieldname'    => '_bbp_password',
410                'callback_method' => 'callback_savepass'
411                );
412
413        // Store old User Salt (This is only used for the SELECT row info for the above password save)
414//        $this->field_map[] = array(
415//              'from_tablename' => 'user',
416//              'from_fieldname' => 'salt',
417//              'to_type'        => 'user',
418//              'to_fieldname'   => ''
419//              );
420
421        // User password verify class (Stored in usermeta for verifying password)
422//        $this->field_map[] = array(
423//              'to_type'      => 'user',
424//              'to_fieldname' => '_bbp_class',
425//              'default'      => 'Kunena1'
426//              );
427
428        // User name.
429        $this->field_map[] = array(
430                'from_tablename' => 'users',
431                'from_fieldname' => 'username',
432                'to_type'        => 'user',
433                'to_fieldname'   => 'user_login'
434                );
435
436        // User email.
437        $this->field_map[] = array(
438                'from_tablename' => 'users',
439                'from_fieldname' => 'email',
440                'to_type'        => 'user',
441                'to_fieldname'   => 'user_email'
442                );
443
444        // User homepage.
445        /**
446        $this->field_map[] = array(
447                'from_tablename' => 'users',
448                'from_fieldname' => 'homepage',
449                'to_type'        => 'user',
450                'to_fieldname'   => 'user_url'
451                );
452         *
453         */
454
455        // User registered.
456        $this->field_map[] = array(
457                'from_tablename'  => 'users',
458                'from_fieldname'  => 'registerDate',
459                'to_type'         => 'user',
460                'to_fieldname'    => 'user_registered',
461                'callback_method' => 'callback_datetime'
462                );
463
464        // User aim.
465        /**
466        $this->field_map[] = array(
467                'from_tablename' => 'user',
468                'from_fieldname' => 'aim',
469                'to_type'        => 'user',
470                'to_fieldname'   => 'aim'
471                );
472         *
473         */
474        /**
475        // User yahoo.
476        $this->field_map[] = array(
477                'from_tablename' => 'user',
478                'from_fieldname' => 'yahoo',
479                'to_type'        => 'user',
480                'to_fieldname'   => 'yim'
481                );
482         *
483         */
484    }
485
486    /**
487     * This method allows us to indicates what is or is not converted for each
488     * converter.
489     */
490    public function info() {
491        return '';
492    }
493
494    /**
495     * This method is to save the salt and password together.  That
496     * way when we authenticate it we can get it out of the database
497     * as one value. Array values are auto sanitized by WordPress.
498     */
499    public function callback_savepass($field, $row) {
500        $pass_array = array('hash' => $field, 'salt' => $row['salt']);
501        return $pass_array;
502    }
503
504    /**
505     * This method is to take the pass out of the database and compare
506     * to a pass the user has typed in.
507     */
508    public function authenticate_pass($password, $serialized_pass) {
509        $pass_array = unserialize($serialized_pass);
510        return ( $pass_array['hash'] == md5(md5($password) . $pass_array['salt']) );
511    }
512
513        /**
514         * Translate the forum type from Kunena v1.x numeric's to WordPress's strings.
515         *
516         * @param int $status Kunena v1.x numeric forum type
517         * @return string WordPress safe
518         */
519        public function callback_forum_type( $status = 0 ) {
520                if ( $status == 0 ) {
521                        $status = 'category';
522                } else {
523                        $status = 'forum';
524                }
525                return $status;
526        }
527
528        /**
529         * Translate the forum status from Kunena v1.x numeric's to WordPress's strings.
530         *
531         * @param int $status Kunena v1.x numeric forum status
532         * @return string WordPress safe
533         */
534        public function callback_forum_status( $status = 0 ) {
535                switch ( $status ) {
536                        case 1 :
537                                $status = 'closed';
538                                break;
539
540                        case 0  :
541                        default :
542                                $status = 'open';
543                                break;
544                }
545                return $status;
546        }
547
548        /**
549         * Translate the post status from Kunena v1.x numeric's to WordPress's strings.
550         *
551         * @param int $status Kunena v1.x numeric topic status
552         * @return string WordPress safe
553         */
554        public function callback_topic_status( $status = 0 ) {
555                switch ( $status ) {
556                        case 1 :
557                                $status = 'closed';
558                                break;
559
560                        case 0  :
561                        default :
562                                $status = 'publish';
563                                break;
564                }
565                return $status;
566        }
567
568        /**
569         * Set the reply title
570         *
571         * @param string $title Kunena v1.x topic title of this reply
572         * @return string Prefixed topic title, or empty string
573         */
574        public function callback_reply_title( $title = '' ) {
575                $title = !empty( $title ) ? __( 'Re: ', 'bbpress' ) . html_entity_decode( $title ) : '';
576                return $title;
577        }
578}