Skip to:
Content

bbPress.org

Ticket #2179: Vanilla.php

File Vanilla.php, 14.5 KB (added by netweb, 12 years ago)

First pass for Vanilla.php

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