Changeset 3240

Show
Ignore:
Timestamp:
11/30/05 07:13:20 (3 years ago)
Author:
ryan
Message:

Textpattern importer changes from Aaron Brazell. fixes #1944

Files:

Legend:

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

    r3236 r3240  
    11<?php 
    2  
    3 /* 
    4 This Import Script is written by Aaron Brazell of Technosailor.com 
    5  
    6 It was developed using a large blog running Textpattern 4.0.2 and 
    7   successfully imported nearly 3000 records at a time.  Higher 
    8   scalability is uncertain. 
    9    
    10   BACKUP YOUR DATABASE PRIOR TO RUNNING THIS IMPORT SCRIPT 
    11 */ 
    12  
    13 // BEGIN EDITING 
    14  
    15 // $txpconfig options can be found in the Textpattern %textpattern%/config.php file 
    16 $txpcfg['db'] = 'textpattern'; 
    17 $txpcfg['user'] = 'root'; 
    18 $txpcfg['pass'] = ''; 
    19 $txpcfg['host'] = 'localhost'; 
    20 $txpcfg['table_prefix'] = ''; 
    21  
    22 // STOP EDITING 
    23  
    242/** 
    253    Add These Functions to make our lives easier 
     
    6139class Textpattern_Import { 
    6240 
    63     var $posts = array (); 
    64     var $file; 
    65  
    6641    function header()  
    6742    { 
    6843        echo '<div class="wrap">'; 
    6944        echo '<h2>'.__('Import Textpattern').'</h2>'; 
     45        echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.</p>'); 
    7046    } 
    7147 
     
    7753    function greet()  
    7854    { 
    79         global $txpcfg; 
    80          
    8155        _e('<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>'); 
    8256        _e('<p>Your Textpattern Configuration settings are as follows:</p>'); 
    83         _e('<ul><li><strong>Textpattern Database Name:</strong> '.$txpcfg['db'].'</li>'); 
    84         _e('<li><strong>Textpattern Database User:</strong> '.$txpcfg['user'].'</li>'); 
    85         _e('<li><strong>Textpattern Database Password:</strong> '.$txpcfg['pass'].'</li>'); 
    86         _e('<li><strong>Textpattern Database Host:</strong> '.$txpcfg['host'].'</li>'); 
    87         _e('</ul>'); 
    88         _e('<p>If this is incorrect, please modify settings in wp-admin/import/textpattern.php</p>'); 
    8957        _e('<form action="admin.php?import=textpattern&amp;step=1" method="post">'); 
     58        $this->db_form(); 
    9059        _e('<input type="submit" name="submit" value="Import Categories" />'); 
    9160        _e('</form>'); 
     
    9564    { 
    9665        //General Housekeeping 
    97         global $txpdb
     66        $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost'))
    9867        set_magic_quotes_runtime(0); 
    9968        $prefix = get_option('tpre'); 
     
    10877                                      FROM '.$prefix.'txp_link',  
    10978                                      ARRAY_A);                        
    110                                       echo'SELECT  
    111                                         id, 
    112                                         date, 
    113                                         category, 
    114                                         url, 
    115                                         linkname, 
    116                                         description 
    117                                       FROM '.$prefix.'txp_link'; 
    11879    } 
    11980     
    12081    function get_txp_cats()  
    12182    { 
    122          
    123         // General Housekeeping 
    124         global $txpdb
     83        global $wpdb; 
     84        // General Housekeeping 
     85        $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost'))
    12586        set_magic_quotes_runtime(0); 
    12687        $prefix = get_option('tpre'); 
     
    13697    } 
    13798     
     99    function get_txp_users() 
     100    { 
     101        global $wpdb; 
     102        // General Housekeeping 
     103        $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); 
     104        set_magic_quotes_runtime(0); 
     105        $prefix = get_option('tpre'); 
     106         
     107        // Get Users 
     108         
     109        return $txpdb->get_results('SELECT 
     110                                        user_id, 
     111                                        name, 
     112                                        RealName, 
     113                                        email, 
     114                                        privs 
     115                                    FROM '.$prefix.'txp_users', ARRAY_A); 
     116    } 
     117     
    138118    function get_txp_posts() 
    139119    { 
    140120        // General Housekeeping 
    141         global $txpdb
     121        $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost'))
    142122        set_magic_quotes_runtime(0); 
    143123        $prefix = get_option('tpre'); 
     
    157137                                        Keywords, 
    158138                                        url_title, 
    159                                         comments_count, 
    160                                         ADDDATE(Posted, "INTERVAL '.get_settings('gmt_offset').' HOURS") AS post_date_gmt, 
    161                                         ADDDATE(LastMod, "INTERVAL '.get_settings('gmt_offset').' HOURS") AS post_modified_gmt 
     139                                        comments_count 
    162140                                    FROM '.$prefix.'textpattern 
    163141                                    ', ARRAY_A); 
     
    166144    function get_txp_comments() 
    167145    { 
    168         // General Housekeeping 
    169         global $txpdb; 
     146        global $wpdb; 
     147        // General Housekeeping 
     148        $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); 
    170149        set_magic_quotes_runtime(0); 
    171150        $prefix = get_option('tpre'); 
     
    175154    } 
    176155     
    177     function get_txp_users() 
    178     { 
    179         // General Housekeeping 
    180         global $txpdb; 
    181         set_magic_quotes_runtime(0); 
    182         $prefix = get_option('tpre'); 
    183          
    184         // Get Users 
    185         $users = $txpdb->get_results('SELECT 
    186                                         user_id, 
    187                                         name, 
    188                                         RealName, 
    189                                         email, 
    190                                         privs 
    191                                     FROM '.$prefix.'txp_users', ARRAY_A); 
    192         return $users; 
    193     } 
    194156     
    195157    function links2wp($links='') 
     
    240202            return true; 
    241203        } 
    242         echo 'No Links to Import!'
     204        echo __('No Links to Import!')
    243205        return false; 
    244206    } 
     
    313275        }// End if(is_array($users) 
    314276         
    315         echo 'No Users to Import!'
     277        echo __('No Users to Import!')
    316278        return false; 
    317279         
     
    324286        $count = 0; 
    325287        $txpcat2wpcat = array(); 
    326          
    327288        // Do the Magic 
    328289        if(is_array($categories)) 
     
    355316            return true; 
    356317        } 
    357         echo 'No Categories to Import!'
     318        echo __('No Categories to Import!')
    358319        return false; 
    359320         
     
    505466            return true; 
    506467        } 
    507         echo 'No Comments to Import!'
     468        echo __('No Comments to Import!')
    508469        return false; 
    509470    } 
     
    578539        delete_option('txpcm2wpcm'); 
    579540        delete_option('txplinks2wplinks'); 
     541        delete_option('txpuser'); 
     542        delete_option('txppass'); 
     543        delete_option('txpname'); 
     544        delete_option('txphost'); 
    580545        $this->tips(); 
    581546    } 
     
    583548    function tips() 
    584549    { 
    585         echo'<p>Welcome to WordPress.  We hope (and expect!) that you will find this platform incredibly rewarding!  As a new WordPress user coming from Textpattern, there are some things that we would like to point out.  Hopefully, they will help your transition go as smoothly as possible.</p>'; 
    586         echo'<h3>Users</h3>'; 
    587         echo'<p>You have already setup WordPress and have been assigned an administrative login and password.  Forget it.  You didn\'t have that login in Textpattern, why should you have it here?  Instead we have taken care to import all of your users into our system.  Unfortunately there is one downside.  Because both WordPress and Textpattern uses a strong encryption hash with passwords, it is impossible to decrypt it and we are forced to assign temporary passwords to all your users.  <strong>Every user has the same username, but their passwords are reset to password123.</strong>  This includes you.  So <a href="/wp-login.php">Login</a> and change it.</p>'; 
    588         echo'<h3>Preserving Authors</h3>'; 
    589         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>'; 
    590         echo'<h3>Textile</h3>'; 
    591         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>'; 
    592         echo'<h3>WordPress Resources</h3>'; 
    593         echo'<p>Finally, there are numerous WordPress resources around the internet.  Some of them are:</p>'; 
    594         echo'<ul>'; 
    595         echo'<li><a href="http://www.wordpress.org">The official WordPress site</a></li>'; 
    596         echo'<li><a href="http://wordpress.org/support/">The WordPress support forums</li>'; 
    597         echo'<li><a href="http://codex.wordpress.org">The Codex (In other words, the WordPress Bible)</a></li>'; 
    598         echo'</ul>'; 
    599         echo'<p>That\'s it! What are you waiting for? Go <a href="/wp-login.php">login</a>!</p>'; 
     550        echo __('<p>Welcome to WordPress.  We hope (and expect!) that you will find this platform incredibly rewarding!  As a new WordPress user coming from Textpattern, there are some things that we would like to point out.  Hopefully, they will help your transition go as smoothly as possible.</p>'); 
     551        echo __('<h3>Users</h3>'); 
     552        echo __('<p>You have already setup WordPress and have been assigned an administrative login and password.  Forget it.  You didn\'t have that login in Textpattern, why should you have it here?  Instead we have taken care to import all of your users into our system.  Unfortunately there is one downside.  Because both WordPress and Textpattern uses a strong encryption hash with passwords, it is impossible to decrypt it and we are forced to assign temporary passwords to all your users.  <strong>Every user has the same username, but their passwords are reset to password123.</strong>  So <a href="/wp-login.php">Login</a> and change it.</p>'); 
     553        echo __('<h3>Preserving Authors</h3>'); 
     554        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>'); 
     555        echo __('<h3>Textile</h3>'); 
     556        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>'); 
     557        echo __('<h3>WordPress Resources</h3>'); 
     558        echo __('<p>Finally, there are numerous WordPress resources around the internet.  Some of them are:</p>'); 
     559        echo __('<ul>'); 
     560        echo __('<li><a href="http://www.wordpress.org">The official WordPress site</a></li>'); 
     561        echo __('<li><a href="http://wordpress.org/support/">The WordPress support forums</li>'); 
     562        echo __('<li><a href="http://codex.wordpress.org">The Codex (In other words, the WordPress Bible)</a></li>'); 
     563        echo __('</ul>'); 
     564        echo __('<p>That\'s it! What are you waiting for? Go <a href="/wp-login.php">login</a>!</p>'); 
     565    } 
     566     
     567    function db_form() 
     568    { 
     569        _e('<ul>'); 
     570        _e('<li><label for="dbuser">Textpattern Database User:</label> <input type="text" name="dbuser" /></li>'); 
     571        _e('<li><label for="dbpass">Textpattern Database Password:</label> <input type="password" name="dbpass" /></li>'); 
     572        _e('<li><label for="dbname">Textpattern Database Name:</label> <input type="text" name="dbname" /></li>'); 
     573        _e('<li><label for="dbhost">Textpattern Database Host:</label> <input type="text" name="dbhost" value="localhost" /></li>'); 
     574        _e('<li><label for="dbprefix">Textpattern Table prefix (if any)t:</label> <input type="text" name="dbprefix" /></li>'); 
     575        _e('</ul>');         
    600576    } 
    601577     
    602578    function dispatch()  
    603579    { 
    604         global $txpdb, $txpcfg; 
    605580 
    606581        if (empty ($_GET['step'])) 
     
    608583        else 
    609584            $step = (int) $_GET['step']; 
    610  
    611585        $this->header(); 
    612586         
    613         if ( $step > 0 ) { 
    614             add_option('tpre',$txpcfg['table_prefix']); 
    615             $txpdb = new wpdb($txpcfg['user'], $txpcfg['pass'], $txpcfg['db'], $txpcfg['host']); 
     587        if ( $step == 1 )  
     588        { 
     589            if(false !== get_option('txpuser')) {add_option('txpuser',$_POST['dbuser']); } 
     590            if(false !== get_option('txppass')) {add_option('txppass',$_POST['dbpass']); } 
     591            if(false !== get_option('txpname')) {add_option('txpname',$_POST['dbname']); } 
     592            if(false !== get_option('txphost')) {add_option('txphost',$_POST['dbhost']); } 
     593            if(false !== get_option('tpre')) { add_option('tpre', $tpre); } 
     594 
    616595        } 
    617596