Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r4349 r3424  
    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         echo '<div class="narrow">';
     52   
     53    function greet()
     54    {
    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 '<p class="submit"><input type="submit" name="submit" value="'.__('Import Categories').' &raquo;" /></p>';
     59        echo '<input type="submit" name="submit" value="'.__('Import Categories').'" />';
    6060        echo '</form>';
    61         echo '</div>';
    6261    }
    6362
     
    6968        set_magic_quotes_runtime(0);
    7069        $prefix = get_option('tpre');
    71 
     70       
    7271        // Get Categories
    7372        return $txpdb->get_results('SELECT
     
    7978                                     ARRAY_A);
    8079    }
    81 
     80   
    8281    function get_txp_users()
    8382    {
     
    8786        set_magic_quotes_runtime(0);
    8887        $prefix = get_option('tpre');
    89 
     88       
    9089        // Get Users
    91 
     90       
    9291        return $txpdb->get_results('SELECT
    9392                                        user_id,
     
    9897                                    FROM '.$prefix.'txp_users', ARRAY_A);
    9998    }
    100 
     99   
    101100    function get_txp_posts()
    102101    {
     
    105104        set_magic_quotes_runtime(0);
    106105        $prefix = get_option('tpre');
    107 
     106       
    108107        // Get Posts
    109108        return $txpdb->get_results('SELECT
     
    124123                                    ', ARRAY_A);
    125124    }
    126 
     125   
    127126    function get_txp_comments()
    128127    {
     
    132131        set_magic_quotes_runtime(0);
    133132        $prefix = get_option('tpre');
    134 
     133       
    135134        // Get Comments
    136135        return $txpdb->get_results('SELECT * FROM '.$prefix.'txp_discuss', ARRAY_A);
    137136    }
    138 
     137   
    139138        function get_txp_links()
    140139    {
     
    143142        set_magic_quotes_runtime(0);
    144143        $prefix = get_option('tpre');
    145 
     144       
    146145        return $txpdb->get_results('SELECT
    147146                                        id,
     
    154153                                      ARRAY_A);                       
    155154    }
    156 
     155   
    157156    function cat2wp($categories='')
    158157    {
     
    169168                $count++;
    170169                extract($category);
    171 
    172 
     170               
     171               
    173172                // Make Nice Variables
    174173                $name = $wpdb->escape($name);
    175174                $title = $wpdb->escape($title);
    176 
     175               
    177176                if($cinfo = category_exists($name))
    178177                {
     
    185184                $txpcat2wpcat[$id] = $ret_id;
    186185            }
    187 
     186           
    188187            // Store category translation for future use
    189188            add_option('txpcat2wpcat',$txpcat2wpcat);
     
    194193        return false;
    195194    }
    196 
     195   
    197196    function users2wp($users='')
    198197    {
     
    201200        $count = 0;
    202201        $txpid2wpid = array();
    203 
     202       
    204203        // Midnight Mojo
    205204        if(is_array($users))
     
    210209                $count++;
    211210                extract($user);
    212 
     211               
    213212                // Make Nice Variables
    214213                $name = $wpdb->escape($name);
    215214                $RealName = $wpdb->escape($RealName);
    216 
     215               
    217216                if($uinfo = get_userdatabylogin($name))
    218217                {
    219 
     218                   
    220219                    $ret_id = wp_insert_user(array(
    221220                                'ID'            => $uinfo->ID,
     
    238237                }
    239238                $txpid2wpid[$user_id] = $ret_id;
    240 
     239               
    241240                // Set Textpattern-to-WordPress permissions translation
    242241                $transperms = array(1 => '10', 2 => '9', 3 => '5', 4 => '4', 5 => '3', 6 => '2', 7 => '0');
    243 
     242               
    244243                // Update Usermeta Data
    245244                $user = new WP_User($ret_id);
     
    251250                if('2'  == $transperms[$privs]) { $user->set_role('contributor'); }
    252251                if('0'  == $transperms[$privs]) { $user->set_role('subscriber'); }
    253 
     252               
    254253                update_usermeta( $ret_id, 'wp_user_level', $transperms[$privs] );
    255254                update_usermeta( $ret_id, 'rich_editing', 'false');
    256255            }// End foreach($users as $user)
    257 
     256           
    258257            // Store id translation array for future use
    259258            add_option('txpid2wpid',$txpid2wpid);
    260 
    261 
     259           
     260           
    262261            echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> users imported.'), $count).'<br /><br /></p>';
    263262            return true;
    264263        }// End if(is_array($users)
    265 
     264       
    266265        echo __('No Users to Import!');
    267266        return false;
    268 
     267       
    269268    }// End function user2wp()
    270 
     269   
    271270    function posts2wp($posts='')
    272271    {
     
    285284                $count++;
    286285                extract($post);
    287 
     286               
    288287                // Set Textpattern-to-WordPress status translation
    289288                $stattrans = array(1 => 'draft', 2 => 'private', 3 => 'draft', 4 => 'publish', 5 => 'publish');
    290 
     289               
    291290                //Can we do this more efficiently?
    292291                $uinfo = ( get_userdatabylogin( $AuthorID ) ) ? get_userdatabylogin( $AuthorID ) : 1;
     
    297296                $Excerpt = $wpdb->escape($Excerpt);
    298297                $post_status = $stattrans[$Status];
    299 
     298               
    300299                // Import Post data into WordPress
    301 
     300               
    302301                if($pinfo = post_exists($Title,$Body))
    303302                {
     
    334333                }
    335334                $txpposts2wpposts[$ID] = $ret_id;
    336 
     335               
    337336                // Make Post-to-Category associations
    338337                $cats = array();
     
    340339                if($cat2 = get_catbynicename($Category2)) { $cats[2] = $cat2; }
    341340
    342                 if(!empty($cats)) { wp_set_post_categories($ret_id, $cats); }
     341                if(!empty($cats)) { wp_set_post_cats('', $ret_id, $cats); }
    343342            }
    344343        }
    345344        // Store ID translation for later use
    346345        add_option('txpposts2wpposts',$txpposts2wpposts);
    347 
     346       
    348347        echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> posts imported.'), $count).'<br /><br /></p>';
    349         return true;
    350     }
    351 
     348        return true;   
     349    }
     350   
    352351    function comments2wp($comments='')
    353352    {
     
    357356        $txpcm2wpcm = array();
    358357        $postarr = get_option('txpposts2wpposts');
    359 
     358       
    360359        // Magic Mojo
    361360        if(is_array($comments))
     
    366365                $count++;
    367366                extract($comment);
    368 
     367               
    369368                // WordPressify Data
    370369                $comment_ID = ltrim($discussid, '0');
     
    375374                $web = $wpdb->escape($web);
    376375                $message = $wpdb->escape($message);
    377 
     376               
    378377                if($cinfo = comment_exists($name, $posted))
    379378                {
     
    407406            }
    408407            // Store Comment ID translation for future use
    409             add_option('txpcm2wpcm', $txpcm2wpcm);
    410 
     408            add_option('txpcm2wpcm', $txpcm2wpcm);         
     409           
    411410            // Associate newly formed categories with posts
    412411            get_comment_count($ret_id);
    413 
    414 
     412           
     413           
    415414            echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> comments imported.'), $count).'<br /><br /></p>';
    416415            return true;
     
    419418        return false;
    420419    }
    421 
     420   
    422421    function links2wp($links='')
    423422    {
     
    425424        global $wpdb;
    426425        $count = 0;
    427 
     426       
    428427        // Deal with the links
    429428        if(is_array($links))
     
    434433                $count++;
    435434                extract($link);
    436 
     435               
    437436                // Make nice vars
    438437                $category = $wpdb->escape($category);
    439438                $linkname = $wpdb->escape($linkname);
    440439                $description = $wpdb->escape($description);
    441 
     440               
    442441                if($linfo = link_exists($linkname))
    443442                {
     
    472471        return false;
    473472    }
    474 
     473       
    475474    function import_categories()
    476     {
    477         // Category Import
     475    {   
     476        // Category Import 
    478477        $cats = $this->get_txp_cats();
    479478        $this->cat2wp($cats);
    480479        add_option('txp_cats', $cats);
    481 
    482 
    483 
     480       
     481       
     482           
    484483        echo '<form action="admin.php?import=textpattern&amp;step=2" method="post">';
    485484        printf('<input type="submit" name="submit" value="%s" />', __('Import Users'));
     
    487486
    488487    }
    489 
     488   
    490489    function import_users()
    491490    {
     
    493492        $users = $this->get_txp_users();
    494493        $this->users2wp($users);
    495 
     494       
    496495        echo '<form action="admin.php?import=textpattern&amp;step=3" method="post">';
    497496        printf('<input type="submit" name="submit" value="%s" />', __('Import Posts'));
    498497        echo '</form>';
    499498    }
    500 
     499   
    501500    function import_posts()
    502501    {
     
    504503        $posts = $this->get_txp_posts();
    505504        $this->posts2wp($posts);
    506 
     505       
    507506        echo '<form action="admin.php?import=textpattern&amp;step=4" method="post">';
    508507        printf('<input type="submit" name="submit" value="%s" />', __('Import Comments'));
    509508        echo '</form>';
    510509    }
    511 
     510   
    512511    function import_comments()
    513512    {
     
    515514        $comments = $this->get_txp_comments();
    516515        $this->comments2wp($comments);
    517 
     516       
    518517        echo '<form action="admin.php?import=textpattern&amp;step=5" method="post">';
    519518        printf('<input type="submit" name="submit" value="%s" />', __('Import Links'));
    520519        echo '</form>';
    521520    }
    522 
     521   
    523522    function import_links()
    524523    {
     
    527526        $this->links2wp($links);
    528527        add_option('txp_links', $links);
    529 
     528       
    530529        echo '<form action="admin.php?import=textpattern&amp;step=6" method="post">';
    531530        printf('<input type="submit" name="submit" value="%s" />', __('Finish'));
    532531        echo '</form>';
    533532    }
    534 
     533   
    535534    function cleanup_txpimport()
    536535    {
     
    548547        $this->tips();
    549548    }
    550 
     549   
    551550    function tips()
    552551    {
     
    557556        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>';
    558557        echo '<h3>'.__('Textile').'</h3>';
    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>';
     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>';
    560559        echo '<h3>'.__('WordPress Resources').'</h3>';
    561560        echo '<p>'.__('Finally, there are numerous WordPress resources around the internet.  Some of them are:').'</p>';
    562561        echo '<ul>';
    563562        echo '<li>'.__('<a href="http://www.wordpress.org">The official WordPress site</a>').'</li>';
    564         echo '<li>'.__('<a href="http://wordpress.org/support/">The WordPress support forums</a>').'</li>';
     563        echo '<li>'.__('<a href="http://wordpress.org/support/">The WordPress support forums').'</li>';
    565564        echo '<li>'.__('<a href="http://codex.wordpress.org">The Codex (In other words, the WordPress Bible)</a>').'</li>';
    566565        echo '</ul>';
    567566        echo '<p>'.sprintf(__('That\'s it! What are you waiting for? Go <a href="%1$s">login</a>!'), '/wp-login.php').'</p>';
    568567    }
    569 
     568   
    570569    function db_form()
    571570    {
    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 
     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   
    581580    function dispatch()
    582581    {
     
    587586            $step = (int) $_GET['step'];
    588587        $this->header();
    589 
     588       
    590589        if ( $step > 0 )
    591590        {
     
    593592            {
    594593                if(get_option('txpuser'))
    595                     delete_option('txpuser');
     594                    delete_option('txpuser');   
    596595                add_option('txpuser',$_POST['dbuser']);
    597596            }
     
    599598            {
    600599                if(get_option('txppass'))
    601                     delete_option('txppass');
     600                    delete_option('txppass');   
    602601                add_option('txppass',$_POST['dbpass']);
    603602            }
    604 
     603           
    605604            if($_POST['dbname'])
    606605            {
    607606                if(get_option('txpname'))
    608                     delete_option('txpname');
     607                    delete_option('txpname');   
    609608                add_option('txpname',$_POST['dbname']);
    610609            }
     
    620619                    delete_option('tpre');
    621620                add_option('tpre',$_POST['dbprefix']);
    622             }
     621            }           
    623622
    624623
     
    650649                break;
    651650        }
    652 
     651       
    653652        $this->footer();
    654653    }
     
    656655    function Textpattern_Import()
    657656    {
    658         // Nothing.
     657        // Nothing. 
    659658    }
    660659}
    661660
    662661$txp_import = new Textpattern_Import();
    663 register_importer('textpattern', __('Textpattern'), __('Import posts from a Textpattern Blog'), array ($txp_import, 'dispatch'));
     662register_importer('textpattern', 'Textpattern', __('Import posts from a Textpattern Blog'), array ($txp_import, 'dispatch'));
    664663?>
Note: See TracChangeset for help on using the changeset viewer.