Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/import/textpattern.php

    r3424 r4349  
    88    {
    99    global $wpdb;
    10    
     10
    1111    $cat_id -= 0;   // force numeric
    1212    $name = $wpdb->get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"');
    13    
     13
    1414    return $name;
    1515    }
     
    5050        echo '</div>';
    5151    }
    52    
    53     function greet()
    54     {
     52
     53    function greet() {
     54        echo '<div class="narrow">';
    5555        echo '<p>'.__('Howdy! This importer allows you to extract posts from any Textpattern 4.0.2+ into your blog. This has not been tested on previous versions of Textpattern.  Mileage may vary.').'</p>';
    5656        echo '<p>'.__('Your Textpattern Configuration settings are as follows:').'</p>';
    5757        echo '<form action="admin.php?import=textpattern&amp;step=1" method="post">';
    5858        $this->db_form();
    59         echo '<input type="submit" name="submit" value="'.__('Import Categories').'" />';
     59        echo '<p class="submit"><input type="submit" name="submit" value="'.__('Import Categories').' &raquo;" /></p>';
    6060        echo '</form>';
     61        echo '</div>';
    6162    }
    6263
     
    6869        set_magic_quotes_runtime(0);
    6970        $prefix = get_option('tpre');
    70        
     71
    7172        // Get Categories
    7273        return $txpdb->get_results('SELECT
     
    7879                                     ARRAY_A);
    7980    }
    80    
     81
    8182    function get_txp_users()
    8283    {
     
    8687        set_magic_quotes_runtime(0);
    8788        $prefix = get_option('tpre');
    88        
     89
    8990        // Get Users
    90        
     91
    9192        return $txpdb->get_results('SELECT
    9293                                        user_id,
     
    9798                                    FROM '.$prefix.'txp_users', ARRAY_A);
    9899    }
    99    
     100
    100101    function get_txp_posts()
    101102    {
     
    104105        set_magic_quotes_runtime(0);
    105106        $prefix = get_option('tpre');
    106        
     107
    107108        // Get Posts
    108109        return $txpdb->get_results('SELECT
     
    123124                                    ', ARRAY_A);
    124125    }
    125    
     126
    126127    function get_txp_comments()
    127128    {
     
    131132        set_magic_quotes_runtime(0);
    132133        $prefix = get_option('tpre');
    133        
     134
    134135        // Get Comments
    135136        return $txpdb->get_results('SELECT * FROM '.$prefix.'txp_discuss', ARRAY_A);
    136137    }
    137    
     138
    138139        function get_txp_links()
    139140    {
     
    142143        set_magic_quotes_runtime(0);
    143144        $prefix = get_option('tpre');
    144        
     145
    145146        return $txpdb->get_results('SELECT
    146147                                        id,
     
    153154                                      ARRAY_A);                       
    154155    }
    155    
     156
    156157    function cat2wp($categories='')
    157158    {
     
    168169                $count++;
    169170                extract($category);
    170                
    171                
     171
     172
    172173                // Make Nice Variables
    173174                $name = $wpdb->escape($name);
    174175                $title = $wpdb->escape($title);
    175                
     176
    176177                if($cinfo = category_exists($name))
    177178                {
     
    184185                $txpcat2wpcat[$id] = $ret_id;
    185186            }
    186            
     187
    187188            // Store category translation for future use
    188189            add_option('txpcat2wpcat',$txpcat2wpcat);
     
    193194        return false;
    194195    }
    195    
     196
    196197    function users2wp($users='')
    197198    {
     
    200201        $count = 0;
    201202        $txpid2wpid = array();
    202        
     203
    203204        // Midnight Mojo
    204205        if(is_array($users))
     
    209210                $count++;
    210211                extract($user);
    211                
     212
    212213                // Make Nice Variables
    213214                $name = $wpdb->escape($name);
    214215                $RealName = $wpdb->escape($RealName);
    215                
     216
    216217                if($uinfo = get_userdatabylogin($name))
    217218                {
    218                    
     219
    219220                    $ret_id = wp_insert_user(array(
    220221                                'ID'            => $uinfo->ID,
     
    237238                }
    238239                $txpid2wpid[$user_id] = $ret_id;
    239                
     240
    240241                // Set Textpattern-to-WordPress permissions translation
    241242                $transperms = array(1 => '10', 2 => '9', 3 => '5', 4 => '4', 5 => '3', 6 => '2', 7 => '0');
    242                
     243
    243244                // Update Usermeta Data
    244245                $user = new WP_User($ret_id);
     
    250251                if('2'  == $transperms[$privs]) { $user->set_role('contributor'); }
    251252                if('0'  == $transperms[$privs]) { $user->set_role('subscriber'); }
    252                
     253
    253254                update_usermeta( $ret_id, 'wp_user_level', $transperms[$privs] );
    254255                update_usermeta( $ret_id, 'rich_editing', 'false');
    255256            }// End foreach($users as $user)
    256            
     257
    257258            // Store id translation array for future use
    258259            add_option('txpid2wpid',$txpid2wpid);
    259            
    260            
     260
     261
    261262            echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> users imported.'), $count).'<br /><br /></p>';
    262263            return true;
    263264        }// End if(is_array($users)
    264        
     265
    265266        echo __('No Users to Import!');
    266267        return false;
    267        
     268
    268269    }// End function user2wp()
    269    
     270
    270271    function posts2wp($posts='')
    271272    {
     
    284285                $count++;
    285286                extract($post);
    286                
     287
    287288                // Set Textpattern-to-WordPress status translation
    288289                $stattrans = array(1 => 'draft', 2 => 'private', 3 => 'draft', 4 => 'publish', 5 => 'publish');
    289                
     290
    290291                //Can we do this more efficiently?
    291292                $uinfo = ( get_userdatabylogin( $AuthorID ) ) ? get_userdatabylogin( $AuthorID ) : 1;
     
    296297                $Excerpt = $wpdb->escape($Excerpt);
    297298                $post_status = $stattrans[$Status];
    298                
     299
    299300                // Import Post data into WordPress
    300                
     301
    301302                if($pinfo = post_exists($Title,$Body))
    302303                {
     
    333334                }
    334335                $txpposts2wpposts[$ID] = $ret_id;
    335                
     336
    336337                // Make Post-to-Category associations
    337338                $cats = array();
     
    339340                if($cat2 = get_catbynicename($Category2)) { $cats[2] = $cat2; }
    340341
    341                 if(!empty($cats)) { wp_set_post_cats('', $ret_id, $cats); }
     342                if(!empty($cats)) { wp_set_post_categories($ret_id, $cats); }
    342343            }
    343344        }
    344345        // Store ID translation for later use
    345346        add_option('txpposts2wpposts',$txpposts2wpposts);
    346        
     347
    347348        echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> posts imported.'), $count).'<br /><br /></p>';
    348         return true;   
    349     }
    350    
     349        return true;
     350    }
     351
    351352    function comments2wp($comments='')
    352353    {
     
    356357        $txpcm2wpcm = array();
    357358        $postarr = get_option('txpposts2wpposts');
    358        
     359
    359360        // Magic Mojo
    360361        if(is_array($comments))
     
    365366                $count++;
    366367                extract($comment);
    367                
     368
    368369                // WordPressify Data
    369370                $comment_ID = ltrim($discussid, '0');
     
    374375                $web = $wpdb->escape($web);
    375376                $message = $wpdb->escape($message);
    376                
     377
    377378                if($cinfo = comment_exists($name, $posted))
    378379                {
     
    406407            }
    407408            // Store Comment ID translation for future use
    408             add_option('txpcm2wpcm', $txpcm2wpcm);         
    409            
     409            add_option('txpcm2wpcm', $txpcm2wpcm);
     410
    410411            // Associate newly formed categories with posts
    411412            get_comment_count($ret_id);
    412            
    413            
     413
     414
    414415            echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> comments imported.'), $count).'<br /><br /></p>';
    415416            return true;
     
    418419        return false;
    419420    }
    420    
     421
    421422    function links2wp($links='')
    422423    {
     
    424425        global $wpdb;
    425426        $count = 0;
    426        
     427
    427428        // Deal with the links
    428429        if(is_array($links))
     
    433434                $count++;
    434435                extract($link);
    435                
     436
    436437                // Make nice vars
    437438                $category = $wpdb->escape($category);
    438439                $linkname = $wpdb->escape($linkname);
    439440                $description = $wpdb->escape($description);
    440                
     441
    441442                if($linfo = link_exists($linkname))
    442443                {
     
    471472        return false;
    472473    }
    473        
     474
    474475    function import_categories()
    475     {   
    476         // Category Import 
     476    {
     477        // Category Import
    477478        $cats = $this->get_txp_cats();
    478479        $this->cat2wp($cats);
    479480        add_option('txp_cats', $cats);
    480        
    481        
    482            
     481
     482
     483
    483484        echo '<form action="admin.php?import=textpattern&amp;step=2" method="post">';
    484485        printf('<input type="submit" name="submit" value="%s" />', __('Import Users'));
     
    486487
    487488    }
    488    
     489
    489490    function import_users()
    490491    {
     
    492493        $users = $this->get_txp_users();
    493494        $this->users2wp($users);
    494        
     495
    495496        echo '<form action="admin.php?import=textpattern&amp;step=3" method="post">';
    496497        printf('<input type="submit" name="submit" value="%s" />', __('Import Posts'));
    497498        echo '</form>';
    498499    }
    499    
     500
    500501    function import_posts()
    501502    {
     
    503504        $posts = $this->get_txp_posts();
    504505        $this->posts2wp($posts);
    505        
     506
    506507        echo '<form action="admin.php?import=textpattern&amp;step=4" method="post">';
    507508        printf('<input type="submit" name="submit" value="%s" />', __('Import Comments'));
    508509        echo '</form>';
    509510    }
    510    
     511
    511512    function import_comments()
    512513    {
     
    514515        $comments = $this->get_txp_comments();
    515516        $this->comments2wp($comments);
    516        
     517
    517518        echo '<form action="admin.php?import=textpattern&amp;step=5" method="post">';
    518519        printf('<input type="submit" name="submit" value="%s" />', __('Import Links'));
    519520        echo '</form>';
    520521    }
    521    
     522
    522523    function import_links()
    523524    {
     
    526527        $this->links2wp($links);
    527528        add_option('txp_links', $links);
    528        
     529
    529530        echo '<form action="admin.php?import=textpattern&amp;step=6" method="post">';
    530531        printf('<input type="submit" name="submit" value="%s" />', __('Finish'));
    531532        echo '</form>';
    532533    }
    533    
     534
    534535    function cleanup_txpimport()
    535536    {
     
    547548        $this->tips();
    548549    }
    549    
     550
    550551    function tips()
    551552    {
     
    556557        echo '<p>'.__('Secondly, we have attempted to preserve post authors.  If you are the only author or contributor to your blog, then you are safe.  In most cases, we are successful in this preservation endeavor.  However, if we cannot ascertain the name of the writer due to discrepancies between database tables, we assign it to you, the administrative user.').'</p>';
    557558        echo '<h3>'.__('Textile').'</h3>';
    558         echo '<p>'.__('Also, since you\'re coming from Textpattern, you probably have been using Textile to format your comments and posts.  If this is the case, we recommend downloading and installing <a href="http://www.huddledmasses.org/2004/04/19/wordpress-plugin-textile-20/">Textile for WordPress</a>.  Trust me... You\'ll want it.').'</p>';
     559        echo '<p>'.__('Also, since you\'re coming from Textpattern, you probably have been using Textile to format your comments and posts.  If this is the case, we recommend downloading and installing <a href="http://www.huddledmasses.org/category/development/wordpress/textile/">Textile for WordPress</a>.  Trust me... You\'ll want it.').'</p>';
    559560        echo '<h3>'.__('WordPress Resources').'</h3>';
    560561        echo '<p>'.__('Finally, there are numerous WordPress resources around the internet.  Some of them are:').'</p>';
    561562        echo '<ul>';
    562563        echo '<li>'.__('<a href="http://www.wordpress.org">The official WordPress site</a>').'</li>';
    563         echo '<li>'.__('<a href="http://wordpress.org/support/">The WordPress support forums').'</li>';
     564        echo '<li>'.__('<a href="http://wordpress.org/support/">The WordPress support forums</a>').'</li>';
    564565        echo '<li>'.__('<a href="http://codex.wordpress.org">The Codex (In other words, the WordPress Bible)</a>').'</li>';
    565566        echo '</ul>';
    566567        echo '<p>'.sprintf(__('That\'s it! What are you waiting for? Go <a href="%1$s">login</a>!'), '/wp-login.php').'</p>';
    567568    }
    568    
     569
    569570    function db_form()
    570571    {
    571         echo '<ul>';
    572         printf('<li><label for="dbuser">%s</label> <input type="text" name="dbuser" /></li>', __('Textpattern Database User:'));
    573         printf('<li><label for="dbpass">%s</label> <input type="password" name="dbpass" /></li>', __('Textpattern Database Password:'));
    574         printf('<li><label for="dbname">%s</label> <input type="text" name="dbname" /></li>', __('Textpattern Database Name:'));
    575         printf('<li><label for="dbhost">%s</label> <input type="text" name="dbhost" value="localhost" /></li>', __('Textpattern Database Host:'));
    576         printf('<li><label for="dbprefix">%s</label> <input type="text" name="dbprefix" /></li>', __('Textpattern Table prefix (if any):'));
    577         echo '</ul>';
    578     }
    579    
     572        echo '<table class="editform">';
     573        printf('<tr><th scope="row"><label for="dbuser">%s</label></th><td><input type="text" name="dbuser" id="dbuser" /></td></tr>', __('Textpattern Database User:'));
     574        printf('<tr><th scope="row"><label for="dbpass">%s</label></th><td><input type="password" name="dbpass" id="dbpass" /></td></tr>', __('Textpattern Database Password:'));
     575        printf('<tr><th scope="row"><label for="dbname">%s</label></th><td><input type="text" id="dbname" name="dbname" /></td></tr>', __('Textpattern Database Name:'));
     576        printf('<tr><th scope="row"><label for="dbhost">%s</label></th><td><input type="text" id="dbhost" name="dbhost" value="localhost" /></td></tr>', __('Textpattern Database Host:'));
     577        printf('<tr><th scope="row"><label for="dbprefix">%s</label></th><td><input type="text" name="dbprefix" id="dbprefix"  /></td></tr>', __('Textpattern Table prefix (if any):'));
     578        echo '</table>';
     579    }
     580
    580581    function dispatch()
    581582    {
     
    586587            $step = (int) $_GET['step'];
    587588        $this->header();
    588        
     589
    589590        if ( $step > 0 )
    590591        {
     
    592593            {
    593594                if(get_option('txpuser'))
    594                     delete_option('txpuser');   
     595                    delete_option('txpuser');
    595596                add_option('txpuser',$_POST['dbuser']);
    596597            }
     
    598599            {
    599600                if(get_option('txppass'))
    600                     delete_option('txppass');   
     601                    delete_option('txppass');
    601602                add_option('txppass',$_POST['dbpass']);
    602603            }
    603            
     604
    604605            if($_POST['dbname'])
    605606            {
    606607                if(get_option('txpname'))
    607                     delete_option('txpname');   
     608                    delete_option('txpname');
    608609                add_option('txpname',$_POST['dbname']);
    609610            }
     
    619620                    delete_option('tpre');
    620621                add_option('tpre',$_POST['dbprefix']);
    621             }           
     622            }
    622623
    623624
     
    649650                break;
    650651        }
    651        
     652
    652653        $this->footer();
    653654    }
     
    655656    function Textpattern_Import()
    656657    {
    657         // Nothing. 
     658        // Nothing.
    658659    }
    659660}
    660661
    661662$txp_import = new Textpattern_Import();
    662 register_importer('textpattern', 'Textpattern', __('Import posts from a Textpattern Blog'), array ($txp_import, 'dispatch'));
     663register_importer('textpattern', __('Textpattern'), __('Import posts from a Textpattern Blog'), array ($txp_import, 'dispatch'));
    663664?>
Note: See TracChangeset for help on using the changeset viewer.