Ticket #1944: textpattern.diff

File textpattern.diff, 11.9 KB (added by technosailor, 6 years ago)

Wide ranging issues addressed

  • textpattern.php

     
    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 
    264**/ 
     
    6038**/ 
    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 
    7248        function footer()  
     
    7652         
    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>'); 
    9261        } 
     
    9463        function get_txp_links() 
    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'); 
    10069                 
     
    10776                                                                                description 
    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                  
     83                global $wpdb; 
    12384                // General Housekeeping 
    124                 global $txpdb; 
     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'); 
    12788                 
     
    13596                                                                         ARRAY_A); 
    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'); 
    144124                 
     
    165145         
    166146        function get_txp_comments() 
    167147        { 
     148                global $wpdb; 
    168149                // General Housekeeping 
    169                 global $txpdb; 
     150                $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); 
    170151                set_magic_quotes_runtime(0); 
    171152                $prefix = get_option('tpre'); 
    172153                 
     
    174155                return $txpdb->get_results('SELECT * FROM '.$prefix.'txp_discuss', ARRAY_A); 
    175156        } 
    176157         
    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         } 
    194158         
    195159        function links2wp($links='') 
    196160        { 
     
    239203                        echo __('<p>Done! <strong>'.$count.'</strong> Links imported.<br /><br /></p>'); 
    240204                        return true; 
    241205                } 
    242                 echo 'No Links to Import!'; 
     206                echo __('No Links to Import!'); 
    243207                return false; 
    244208        } 
    245209         
     
    312276                        return true; 
    313277                }// End if(is_array($users) 
    314278                 
    315                 echo 'No Users to Import!'; 
     279                echo __('No Users to Import!'); 
    316280                return false; 
    317281                 
    318282        }// End function user2wp() 
     
    323287                global $wpdb; 
    324288                $count = 0; 
    325289                $txpcat2wpcat = array(); 
    326                  
    327290                // Do the Magic 
    328291                if(is_array($categories)) 
    329292                { 
     
    354317                        echo __('<p>Done! <strong>'.$count.'</strong> categories imported.<br /><br /></p>'); 
    355318                        return true; 
    356319                } 
    357                 echo 'No Categories to Import!'; 
     320                echo __('No Categories to Import!'); 
    358321                return false; 
    359322                 
    360323        } 
     
    504467                        echo __('<p>Done! <strong>'.$count.'</strong> comments imported.<br /><br /></p>'); 
    505468                        return true; 
    506469                } 
    507                 echo 'No Comments to Import!'; 
     470                echo __('No Comments to Import!'); 
    508471                return false; 
    509472        } 
    510473                 
     
    577540                delete_option('txpposts2wpposts'); 
    578541                delete_option('txpcm2wpcm'); 
    579542                delete_option('txplinks2wplinks'); 
     543                delete_option('txpuser'); 
     544                delete_option('txppass'); 
     545                delete_option('txpname'); 
     546                delete_option('txphost'); 
    580547                $this->tips(); 
    581548        } 
    582549         
    583550        function tips() 
    584551        { 
    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>'; 
     552                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>'); 
     553                echo __('<h3>Users</h3>'); 
     554                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>'); 
     555                echo __('<h3>Preserving Authors</h3>'); 
     556                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>'); 
     557                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 __('<h3>WordPress Resources</h3>'); 
     560                echo __('<p>Finally, there are numerous WordPress resources around the internet.  Some of them are:</p>'); 
     561                echo __('<ul>'); 
     562                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://codex.wordpress.org">The Codex (In other words, the WordPress Bible)</a></li>'); 
     565                echo __('</ul>'); 
     566                echo __('<p>That\'s it! What are you waiting for? Go <a href="/wp-login.php">login</a>!</p>'); 
    600567        } 
    601568         
     569        function db_form() 
     570        { 
     571                _e('<ul>'); 
     572                _e('<li><label for="dbuser">Textpattern Database User:</label> <input type="text" name="dbuser" /></li>'); 
     573                _e('<li><label for="dbpass">Textpattern Database Password:</label> <input type="password" name="dbpass" /></li>'); 
     574                _e('<li><label for="dbname">Textpattern Database Name:</label> <input type="text" name="dbname" /></li>'); 
     575                _e('<li><label for="dbhost">Textpattern Database Host:</label> <input type="text" name="dbhost" value="localhost" /></li>'); 
     576                _e('<li><label for="dbprefix">Textpattern Table prefix (if any)t:</label> <input type="text" name="dbprefix" /></li>'); 
     577                _e('</ul>');             
     578        } 
     579         
    602580        function dispatch()  
    603581        { 
    604                 global $txpdb, $txpcfg; 
    605582 
    606583                if (empty ($_GET['step'])) 
    607584                        $step = 0; 
    608585                else 
    609586                        $step = (int) $_GET['step']; 
    610  
    611587                $this->header(); 
    612588                 
    613                 if ( $step > 0 ) { 
    614                         add_option('tpre',$txpcfg['table_prefix']); 
    615                         $txpdb = new wpdb($txpcfg['user'], $txpcfg['pass'], $txpcfg['db'], $txpcfg['host']); 
     589                if ( $step == 1 )  
     590                { 
     591                        if(false !== get_option('txpuser')) {add_option('txpuser',$_POST['dbuser']); } 
     592                        if(false !== get_option('txppass')) {add_option('txppass',$_POST['dbpass']); } 
     593                        if(false !== get_option('txpname')) {add_option('txpname',$_POST['dbname']); } 
     594                        if(false !== get_option('txphost')) {add_option('txphost',$_POST['dbhost']); } 
     595                        if(false !== get_option('tpre')) { add_option('tpre', $tpre); } 
     596 
    616597                } 
    617598 
    618599                switch ($step)  
     
    652633 
    653634$txp_import = new Textpattern_Import(); 
    654635register_importer('textpattern', 'Textpattern', __('Import posts from a Textpattern Blog'), array ($txp_import, 'dispatch')); 
    655 ?> 
     636?> 
     637 No newline at end of file