~canonical-sysadmins/wordpress/3.9.x

« back to all changes in this revision

Viewing changes to wp-admin/import/wordpress.php

  • Committer: Chris Jones
  • Date: 2010-01-19 13:17:33 UTC
  • Revision ID: cmsj@tenshu.net-20100119131733-rf31jv9k1v0xzo2h
[CJ] Import wordpress 2.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
        var $author_ids = array ();
28
28
        var $tags = array ();
29
29
        var $categories = array ();
 
30
        var $terms = array ();
30
31
 
31
32
        var $j = -1;
32
33
        var $fetch_attachments = false;
122
123
                                        $this->tags[] = $tag[1];
123
124
                                        continue;
124
125
                                }
 
126
                                if ( false !== strpos($importline, '<wp:term>') ) {
 
127
                                        preg_match('|<wp:term>(.*?)</wp:term>|is', $importline, $term);
 
128
                                        $this->terms[] = $term[1];
 
129
                                        continue;
 
130
                                }
125
131
                                if ( false !== strpos($importline, '<item>') ) {
126
132
                                        $this->post = '';
127
133
                                        $doing_entry = true;
198
204
 
199
205
        function wp_authors_form() {
200
206
?>
201
 
<?php screen_icon(); ?>
202
207
<h2><?php _e('Assign Authors'); ?></h2>
203
208
<p><?php _e('To make it easier for you to edit and save the imported posts and drafts, you may want to change the name of the author of the posts. For example, you may want to import all the entries as <code>admin</code>s entries.'); ?></p>
204
209
<?php
210
215
                $authors = $this->get_wp_authors();
211
216
                echo '<form action="?import=wordpress&amp;step=2&amp;id=' . $this->id . '" method="post">';
212
217
                wp_nonce_field('import-wordpress');
213
 
                echo '<ol id="authors">';
 
218
?>
 
219
<ol id="authors">
 
220
<?php
214
221
                $j = -1;
215
222
                foreach ($authors as $author) {
216
223
                        ++ $j;
222
229
                if ( $this->allow_fetch_attachments() ) {
223
230
?>
224
231
</ol>
225
 
<?php screen_icon(); ?>
226
232
<h2><?php _e('Import Attachments'); ?></h2>
227
233
<p>
228
234
        <input type="checkbox" value="1" name="attachments" id="import-attachments" />
337
343
                        $tag_ID = wp_insert_term($tag_name, 'post_tag', $tagarr);
338
344
                }
339
345
        }
 
346
        
 
347
        function process_terms() {
 
348
                global $wpdb, $wp_taxonomies;
 
349
                
 
350
                $custom_taxonomies = $wp_taxonomies;
 
351
                // get rid of the standard taxonomies
 
352
                unset( $custom_taxonomies['category'] );
 
353
                unset( $custom_taxonomies['post_tag'] );
 
354
                unset( $custom_taxonomies['link_category'] );
 
355
                
 
356
                $custom_taxonomies = array_keys( $custom_taxonomies );
 
357
                $current_terms = (array) get_terms( $custom_taxonomies, 'get=all' );
 
358
                $taxonomies = array();
 
359
                foreach ( $current_terms as $term ) {
 
360
                        if ( isset( $_terms[$term->taxonomy] ) ) {
 
361
                                $taxonomies[$term->taxonomy] = array_merge( $taxonomies[$term->taxonomy], array($term->name) );
 
362
                        } else {
 
363
                                $taxonomies[$term->taxonomy] = array($term->name);
 
364
                        }
 
365
                }
 
366
 
 
367
                while ( $c = array_shift($this->terms) ) {
 
368
                        $term_name = trim($this->get_tag( $c, 'wp:term_name' ));
 
369
                        $term_taxonomy = trim($this->get_tag( $c, 'wp:term_taxonomy' ));
 
370
 
 
371
                        // If the term exists in the taxonomy we leave it alone
 
372
                        if ( isset($taxonomies[$term_taxonomy] ) && in_array( $term_name, $taxonomies[$term_taxonomy] ) )
 
373
                                continue;
 
374
 
 
375
                        $slug = $this->get_tag( $c, 'wp:term_slug' );
 
376
                        $description = $this->get_tag( $c, 'wp:term_description' );
 
377
 
 
378
                        $termarr = compact('slug', 'description');
 
379
 
 
380
                        $term_ID = wp_insert_term($term_name, $this->get_tag( $c, 'wp:term_taxonomy' ), $termarr);
 
381
                }
 
382
        }
340
383
 
341
384
        function process_author($post) {
342
385
                $author = $this->get_tag( $post, 'dc:creator' );
357
400
                echo '<h3>'.sprintf(__('All done.').' <a href="%s">'.__('Have fun!').'</a>', get_option('home')).'</h3>';
358
401
        }
359
402
 
 
403
        function _normalize_tag( $matches ) {
 
404
                return '<' . strtolower( $matches[1] );
 
405
        }
 
406
 
360
407
        function process_post($post) {
361
408
                global $wpdb;
362
409
 
378
425
                $menu_order     = $this->get_tag( $post, 'wp:menu_order' );
379
426
                $post_type      = $this->get_tag( $post, 'wp:post_type' );
380
427
                $post_password  = $this->get_tag( $post, 'wp:post_password' );
 
428
                $is_sticky              = $this->get_tag( $post, 'wp:is_sticky' );
381
429
                $guid           = $this->get_tag( $post, 'guid' );
382
430
                $post_author    = $this->get_tag( $post, 'dc:creator' );
383
431
 
384
432
                $post_excerpt = $this->get_tag( $post, 'excerpt:encoded' );
385
 
                $post_excerpt = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_excerpt);
 
433
                $post_excerpt = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_excerpt);
386
434
                $post_excerpt = str_replace('<br>', '<br />', $post_excerpt);
387
435
                $post_excerpt = str_replace('<hr>', '<hr />', $post_excerpt);
388
436
 
389
437
                $post_content = $this->get_tag( $post, 'content:encoded' );
390
 
                $post_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_content);
 
438
                $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content);
391
439
                $post_content = str_replace('<br>', '<br />', $post_content);
392
440
                $post_content = str_replace('<hr>', '<hr />', $post_content);
393
441
 
448
496
                        else {
449
497
                                printf(__('Importing post <em>%s</em>...'), stripslashes($post_title));
450
498
                                $comment_post_ID = $post_id = wp_insert_post($postdata);
 
499
                                if ( $post_id && $is_sticky == 1 )
 
500
                                        stick_post( $post_id );
 
501
 
451
502
                        }
452
503
 
453
504
                        if ( is_wp_error( $post_id ) )
508
559
                preg_match_all('|<wp:comment>(.*?)</wp:comment>|is', $post, $comments);
509
560
                $comments = $comments[1];
510
561
                $num_comments = 0;
511
 
                if ( $comments) { foreach ($comments as $comment) {
512
 
                        $comment_author       = $this->get_tag( $comment, 'wp:comment_author');
513
 
                        $comment_author_email = $this->get_tag( $comment, 'wp:comment_author_email');
514
 
                        $comment_author_IP    = $this->get_tag( $comment, 'wp:comment_author_IP');
515
 
                        $comment_author_url   = $this->get_tag( $comment, 'wp:comment_author_url');
516
 
                        $comment_date         = $this->get_tag( $comment, 'wp:comment_date');
517
 
                        $comment_date_gmt     = $this->get_tag( $comment, 'wp:comment_date_gmt');
518
 
                        $comment_content      = $this->get_tag( $comment, 'wp:comment_content');
519
 
                        $comment_approved     = $this->get_tag( $comment, 'wp:comment_approved');
520
 
                        $comment_type         = $this->get_tag( $comment, 'wp:comment_type');
521
 
                        $comment_parent       = $this->get_tag( $comment, 'wp:comment_parent');
522
 
 
523
 
                        // if this is a new post we can skip the comment_exists() check
524
 
                        if ( !$post_exists || !comment_exists($comment_author, $comment_date) ) {
525
 
                                $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_approved', 'comment_type', 'comment_parent');
526
 
                                wp_insert_comment($commentdata);
527
 
                                $num_comments++;
528
 
                        }
529
 
                } }
 
562
                $inserted_comments = array();
 
563
                if ( $comments) { 
 
564
                        foreach ($comments as $comment) {
 
565
                                $comment_id     = $this->get_tag( $comment, 'wp:comment_id');
 
566
                                $newcomments[$comment_id]['comment_post_ID']      = $comment_post_ID;
 
567
                                $newcomments[$comment_id]['comment_author']       = $this->get_tag( $comment, 'wp:comment_author');
 
568
                                $newcomments[$comment_id]['comment_author_email'] = $this->get_tag( $comment, 'wp:comment_author_email');
 
569
                                $newcomments[$comment_id]['comment_author_IP']    = $this->get_tag( $comment, 'wp:comment_author_IP');
 
570
                                $newcomments[$comment_id]['comment_author_url']   = $this->get_tag( $comment, 'wp:comment_author_url');
 
571
                                $newcomments[$comment_id]['comment_date']         = $this->get_tag( $comment, 'wp:comment_date');
 
572
                                $newcomments[$comment_id]['comment_date_gmt']     = $this->get_tag( $comment, 'wp:comment_date_gmt');
 
573
                                $newcomments[$comment_id]['comment_content']      = $this->get_tag( $comment, 'wp:comment_content');
 
574
                                $newcomments[$comment_id]['comment_approved']     = $this->get_tag( $comment, 'wp:comment_approved');
 
575
                                $newcomments[$comment_id]['comment_type']         = $this->get_tag( $comment, 'wp:comment_type');
 
576
                                $newcomments[$comment_id]['comment_parent']       = $this->get_tag( $comment, 'wp:comment_parent');
 
577
                        }
 
578
                        // Sort by comment ID, to make sure comment parents exist (if there at all)
 
579
                        ksort($newcomments);
 
580
                        foreach ($newcomments as $key => $comment) {
 
581
                                // if this is a new post we can skip the comment_exists() check
 
582
                                if ( !$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date']) ) {
 
583
                                        if (isset($inserted_comments[$comment['comment_parent']]))
 
584
                                                $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
 
585
                                        $comment = wp_filter_comment($comment);
 
586
                                        $inserted_comments[$key] = wp_insert_comment($comment);
 
587
                                        $num_comments++;
 
588
                                }
 
589
                        }
 
590
                }
530
591
 
531
592
                if ( $num_comments )
532
593
                        printf(' '._n('(%s comment)', '(%s comments)', $num_comments), $num_comments);
740
801
                $this->get_entries();
741
802
                $this->process_categories();
742
803
                $this->process_tags();
 
804
                $this->process_terms();
743
805
                $result = $this->process_posts();
744
806
                wp_suspend_cache_invalidation(false);
745
807
                $this->backfill_parents();