Make WordPress Core

Changeset 5406


Ignore:
Timestamp:
05/07/2007 04:10:20 PM (19 years ago)
Author:
ryan
Message:

Add nonces to importers

Location:
branches/2.0/wp-admin
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0/wp-admin/admin-functions.php

    r5121 r5406  
    18141814</script>
    18151815<form enctype="multipart/form-data" id="uploadForm" method="post" action="<?php echo attribute_escape($action) ?>">
     1816<?php wp_nonce_field('import-upload'); ?>
    18161817<label for="upload"><?php _e('File:'); ?></label><input type="file" id="upload" name="import" />
    18171818<input type="hidden" name="action" value="save" />
  • branches/2.0/wp-admin/import/dotclear.php

    r5391 r5406  
    11<?php
     2/*
     3 * DotClear import plugin
     4 * by Thomas Quinot - http://thomas.quinot.org/
     5 */
     6
    27/**
    38        Add These Functions to make our lives easier
     
    510if(!function_exists('get_catbynicename'))
    611{
    7         function get_catbynicename($category_nicename) 
     12        function get_catbynicename($category_nicename)
    813        {
    914        global $wpdb;
    10        
     15
    1116        $cat_id -= 0;   // force numeric
    1217        $name = $wpdb->get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"');
    13        
     18
    1419        return $name;
    1520        }
     
    5661//    This cries out for a C-implementation to be included in PHP core
    5762//
    58    function valid_1byte($char) {
    59        if(!is_int($char)) return false;
    60        return ($char & 0x80) == 0x00;
    61    }
    62  
    63    function valid_2byte($char) {
    64        if(!is_int($char)) return false;
    65        return ($char & 0xE0) == 0xC0;
    66    }
    67 
    68    function valid_3byte($char) {
    69        if(!is_int($char)) return false;
    70        return ($char & 0xF0) == 0xE0;
    71    }
    72 
    73    function valid_4byte($char) {
    74        if(!is_int($char)) return false;
    75        return ($char & 0xF8) == 0xF0;
    76    }
    77  
    78    function valid_nextbyte($char) {
    79        if(!is_int($char)) return false;
    80        return ($char & 0xC0) == 0x80;
    81    }
    82  
    83    function valid_utf8($string) {
    84        $len = strlen($string);
    85        $i = 0;   
    86        while( $i < $len ) {
    87            $char = ord(substr($string, $i++, 1));
    88            if(valid_1byte($char)) {    // continue
    89                continue;
    90            } else if(valid_2byte($char)) { // check 1 byte
    91                if(!valid_nextbyte(ord(substr($string, $i++, 1))))
    92                    return false;
    93            } else if(valid_3byte($char)) { // check 2 bytes
    94                if(!valid_nextbyte(ord(substr($string, $i++, 1))))
    95                    return false;
    96                if(!valid_nextbyte(ord(substr($string, $i++, 1))))
    97                    return false;
    98            } else if(valid_4byte($char)) { // check 3 bytes
    99                if(!valid_nextbyte(ord(substr($string, $i++, 1))))
    100                    return false;
    101                if(!valid_nextbyte(ord(substr($string, $i++, 1))))
    102                    return false;
    103                if(!valid_nextbyte(ord(substr($string, $i++, 1))))
    104                    return false;
    105            } // goto next char
    106        }
    107        return true; // done
    108    }
     63
     64function valid_1byte($char) {
     65        if(!is_int($char)) return false;
     66                return ($char & 0x80) == 0x00;
     67}
     68
     69function valid_2byte($char) {
     70        if(!is_int($char)) return false;
     71                return ($char & 0xE0) == 0xC0;
     72}
     73
     74function valid_3byte($char) {
     75        if(!is_int($char)) return false;
     76                return ($char & 0xF0) == 0xE0;
     77}
     78
     79function valid_4byte($char) {
     80        if(!is_int($char)) return false;
     81                return ($char & 0xF8) == 0xF0;
     82}
     83
     84function valid_nextbyte($char) {
     85        if(!is_int($char)) return false;
     86                return ($char & 0xC0) == 0x80;
     87}
     88
     89function valid_utf8($string) {
     90        $len = strlen($string);
     91        $i = 0;
     92        while( $i < $len ) {
     93                $char = ord(substr($string, $i++, 1));
     94                if(valid_1byte($char)) {    // continue
     95                        continue;
     96                } else if(valid_2byte($char)) { // check 1 byte
     97                        if(!valid_nextbyte(ord(substr($string, $i++, 1))))
     98                                return false;
     99                } else if(valid_3byte($char)) { // check 2 bytes
     100                        if(!valid_nextbyte(ord(substr($string, $i++, 1))))
     101                                return false;
     102                        if(!valid_nextbyte(ord(substr($string, $i++, 1))))
     103                                return false;
     104                } else if(valid_4byte($char)) { // check 3 bytes
     105                        if(!valid_nextbyte(ord(substr($string, $i++, 1))))
     106                                return false;
     107                        if(!valid_nextbyte(ord(substr($string, $i++, 1))))
     108                                return false;
     109                        if(!valid_nextbyte(ord(substr($string, $i++, 1))))
     110                                return false;
     111                } // goto next char
     112        }
     113        return true; // done
     114}
    109115
    110116function csc ($s) {
     
    128134        {
    129135                echo '<div class="wrap">';
    130                 echo '<h2>'.__('Import Dotclear').'</h2>';
     136                echo '<h2>'.__('Import DotClear').'</h2>';
    131137                echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'</p>';
    132138        }
     
    136142                echo '</div>';
    137143        }
    138        
     144
    139145        function greet()
    140146        {
    141                 echo '<p>'.__('Howdy! This importer allows you to extract posts from a Dotclear database into your blog.  Mileage may vary.').'</p>';
    142                 echo '<p>'.__('Your Dotclear Configuration settings are as follows:').'</p>';
     147                echo '<div class="narrow"><p>'.__('Howdy! This importer allows you to extract posts from a DotClear database into your blog.  Mileage may vary.').'</p>';
     148                echo '<p>'.__('Your DotClear Configuration settings are as follows:').'</p>';
    143149                echo '<form action="admin.php?import=dotclear&amp;step=1" method="post">';
     150                wp_nonce_field('import-dotclear');
    144151                $this->db_form();
    145                 echo '<input type="submit" name="submit" value="'.__('Import Categories').'" />';
    146                 echo '</form>';
    147         }
    148 
    149         function get_dc_cats() 
     152                echo '<p class="submit"><input type="submit" name="submit" value="'.attribute_escape(__('Import Categories &raquo;')).'" /></p>';
     153                echo '</form></div>';
     154        }
     155
     156        function get_dc_cats()
    150157        {
    151158                global $wpdb;
     
    153160                $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost'));
    154161                set_magic_quotes_runtime(0);
    155                 $prefix = get_option('tpre');
    156                
     162                $dbprefix = get_option('dcdbprefix');
     163
    157164                // Get Categories
    158                 return $dcdb->get_results('SELECT * FROM dc_categorie', ARRAY_A);
    159         }
    160        
     165                return $dcdb->get_results('SELECT * FROM '.$dbprefix.'categorie', ARRAY_A);
     166        }
     167
    161168        function get_dc_users()
    162169        {
     
    165172                $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost'));
    166173                set_magic_quotes_runtime(0);
    167                 $prefix = get_option('tpre');
    168                
     174                $dbprefix = get_option('dcdbprefix');
     175
    169176                // Get Users
    170                
    171                 return $dcdb->get_results('SELECT * FROM dc_user', ARRAY_A);
    172         }
    173        
     177
     178                return $dcdb->get_results('SELECT * FROM '.$dbprefix.'user', ARRAY_A);
     179        }
     180
    174181        function get_dc_posts()
    175182        {
     
    177184                $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost'));
    178185                set_magic_quotes_runtime(0);
    179                 $prefix = get_option('tpre');
    180                
     186                $dbprefix = get_option('dcdbprefix');
     187
    181188                // Get Posts
    182                 return $dcdb->get_results('SELECT dc_post.*, dc_categorie.cat_libelle_url AS post_cat_name
    183                                                 FROM dc_post INNER JOIN dc_categorie
    184                                                   ON dc_post.cat_id = dc_categorie.cat_id', ARRAY_A);
    185         }
    186        
     189                return $dcdb->get_results('SELECT '.$dbprefix.'post.*, '.$dbprefix.'categorie.cat_libelle_url AS post_cat_name
     190                                                FROM '.$dbprefix.'post INNER JOIN '.$dbprefix.'categorie
     191                                                ON '.$dbprefix.'post.cat_id = '.$dbprefix.'categorie.cat_id', ARRAY_A);
     192        }
     193
    187194        function get_dc_comments()
    188195        {
     
    191198                $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost'));
    192199                set_magic_quotes_runtime(0);
    193                 $prefix = get_option('tpre');
    194                
     200                $dbprefix = get_option('dcdbprefix');
     201
    195202                // Get Comments
    196                 return $dcdb->get_results('SELECT * FROM dc_comment', ARRAY_A);
    197         }
    198        
     203                return $dcdb->get_results('SELECT * FROM '.$dbprefix.'comment', ARRAY_A);
     204        }
     205
    199206        function get_dc_links()
    200207        {
     
    202209                $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost'));
    203210                set_magic_quotes_runtime(0);
    204                 $prefix = get_option('tpre');
    205 
    206                 return $dcdb->get_results('SELECT * FROM dc_link ORDER BY position', ARRAY_A);
    207         }
    208        
    209         function cat2wp($categories='') 
     211                $dbprefix = get_option('dcdbprefix');
     212
     213                return $dcdb->get_results('SELECT * FROM '.$dbprefix.'link ORDER BY position', ARRAY_A);
     214        }
     215
     216        function cat2wp($categories='')
    210217        {
    211218                // General Housekeeping
     
    217224                {
    218225                        echo '<p>'.__('Importing Categories...').'<br /><br /></p>';
    219                         foreach ($categories as $category) 
     226                        foreach ($categories as $category)
    220227                        {
    221228                                $count++;
    222229                                extract($category);
    223                                
     230
    224231                                // Make Nice Variables
    225232                                $name = $wpdb->escape($cat_libelle_url);
     
    237244                                $dccat2wpcat[$id] = $ret_id;
    238245                        }
    239                        
     246
    240247                        // Store category translation for future use
    241248                        add_option('dccat2wpcat',$dccat2wpcat);
     
    246253                return false;
    247254        }
    248        
     255
    249256        function users2wp($users='')
    250257        {
     
    253260                $count = 0;
    254261                $dcid2wpid = array();
    255                
     262
    256263                // Midnight Mojo
    257264                if(is_array($users))
     
    262269                                $count++;
    263270                                extract($user);
    264                                
     271
    265272                                // Make Nice Variables
    266273                                $name = $wpdb->escape(csc ($name));
    267274                                $RealName = $wpdb->escape(csc ($user_pseudo));
    268                                
     275
    269276                                if($uinfo = get_userdatabylogin($name))
    270277                                {
    271                                        
     278
    272279                                        $ret_id = wp_insert_user(array(
    273280                                                                'ID'            => $uinfo->ID,
     
    279286                                                                );
    280287                                }
    281                                 else 
     288                                else
    282289                                {
    283290                                        $ret_id = wp_insert_user(array(
     
    290297                                }
    291298                                $dcid2wpid[$user_id] = $ret_id;
    292                                
    293                                 // Set Dotclear-to-WordPress permissions translation
    294                                
     299
     300                                // Set DotClear-to-WordPress permissions translation
     301
    295302                                // Update Usermeta Data
    296303                                $user = new WP_User($ret_id);
     
    303310                                else if(2  <= $wp_perms) { $user->set_role('contributor'); }
    304311                                else                     { $user->set_role('subscriber'); }
    305                                
     312
    306313                                update_usermeta( $ret_id, 'wp_user_level', $wp_perms);
    307314                                update_usermeta( $ret_id, 'rich_editing', 'false');
     
    309316                                update_usermeta( $ret_id, 'last_name', csc ($user_nom));
    310317                        }// End foreach($users as $user)
    311                        
     318
    312319                        // Store id translation array for future use
    313320                        add_option('dcid2wpid',$dcid2wpid);
    314                        
    315                        
     321
     322
    316323                        echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> users imported.'), $count).'<br /><br /></p>';
    317324                        return true;
    318325                }// End if(is_array($users)
    319                
     326
    320327                echo __('No Users to Import!');
    321328                return false;
    322                
     329
    323330        }// End function user2wp()
    324        
     331
    325332        function posts2wp($posts='')
    326333        {
     
    339346                                $count++;
    340347                                extract($post);
    341                                
    342                                 // Set Dotclear-to-WordPress status translation
     348
     349                                // Set DotClear-to-WordPress status translation
    343350                                $stattrans = array(0 => 'draft', 1 => 'publish');
    344351                                $comment_status_map = array (0 => 'closed', 1 => 'open');
    345                                
     352
    346353                                //Can we do this more efficiently?
    347354                                $uinfo = ( get_userdatabylogin( $user_id ) ) ? get_userdatabylogin( $user_id ) : 1;
     
    350357                                $Title = $wpdb->escape(csc ($post_titre));
    351358                                $post_content = textconv ($post_content);
     359                                $post_excerpt = "";
    352360                                if ($post_chapo != "") {
    353361                                        $post_excerpt = textconv ($post_chapo);
     
    357365                                $post_content = $wpdb->escape ($post_content);
    358366                                $post_status = $stattrans[$post_pub];
    359                                
     367
    360368                                // Import Post data into WordPress
    361                                
     369
    362370                                if($pinfo = post_exists($Title,$post_content))
    363371                                {
     
    379387                                                        );
    380388                                }
    381                                 else 
     389                                else
    382390                                {
    383391                                        $ret_id = wp_insert_post(array(
     
    398406                                }
    399407                                $dcposts2wpposts[$post_id] = $ret_id;
    400                                
     408
    401409                                // Make Post-to-Category associations
    402410                                $cats = array();
     
    408416                // Store ID translation for later use
    409417                add_option('dcposts2wpposts',$dcposts2wpposts);
    410                
     418
    411419                echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> posts imported.'), $count).'<br /><br /></p>';
    412                 return true;   
    413         }
    414        
     420                return true;
     421        }
     422
    415423        function comments2wp($comments='')
    416424        {
     
    420428                $dccm2wpcm = array();
    421429                $postarr = get_option('dcposts2wpposts');
    422                
     430
    423431                // Magic Mojo
    424432                if(is_array($comments))
     
    429437                                $count++;
    430438                                extract($comment);
    431                                
     439
    432440                                // WordPressify Data
    433441                                $comment_ID = (int) ltrim($comment_id, '0');
     
    438446                                $web = "http://".$wpdb->escape($comment_site);
    439447                                $message = $wpdb->escape(textconv ($comment_content));
    440                                
     448
    441449                                if($cinfo = comment_exists($name, $comment_dt))
    442450                                {
     
    455463                                                        );
    456464                                }
    457                                 else 
     465                                else
    458466                                {
    459467                                        // Insert comments
     
    473481                        }
    474482                        // Store Comment ID translation for future use
    475                         add_option('dccm2wpcm', $dccm2wpcm);                   
    476                        
     483                        add_option('dccm2wpcm', $dccm2wpcm);
     484
    477485                        // Associate newly formed categories with posts
    478486                        get_comment_count($ret_id);
    479                        
    480                        
     487
     488
    481489                        echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> comments imported.'), $count).'<br /><br /></p>';
    482490                        return true;
     
    485493                return false;
    486494        }
    487        
     495
    488496        function links2wp($links='')
    489497        {
     
    491499                global $wpdb;
    492500                $count = 0;
    493                
     501
    494502                // Deal with the links
    495503                if(is_array($links))
     
    500508                                $count++;
    501509                                extract($link);
    502                                
     510
    503511                                if ($title != "") {
    504512                                        if ($cinfo = link_cat_exists (csc ($title))) {
     
    512520                                        $linkname = $wpdb->escape(csc ($label));
    513521                                        $description = $wpdb->escape(csc ($title));
    514                                
     522
    515523                                        if($linfo = link_exists($linkname)) {
    516524                                                $ret_id = wp_insert_link(array(
     
    541549                return false;
    542550        }
    543                
    544         function import_categories() 
    545         {       
    546                 // Category Import     
     551
     552        function import_categories()
     553        {
     554                // Category Import
    547555                $cats = $this->get_dc_cats();
    548556                $this->cat2wp($cats);
    549557                add_option('dc_cats', $cats);
    550                
    551                
    552                        
     558
     559
     560
    553561                echo '<form action="admin.php?import=dotclear&amp;step=2" method="post">';
    554                 printf('<input type="submit" name="submit" value="%s" />', __('Import Users'));
     562                wp_nonce_field('import-dotclear');
     563                printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Users')));
    555564                echo '</form>';
    556565
    557566        }
    558        
     567
    559568        function import_users()
    560569        {
    561570                // User Import
    562                 $users = $this->get_dc_users(); 
     571                $users = $this->get_dc_users();
    563572                $this->users2wp($users);
    564                
     573
    565574                echo '<form action="admin.php?import=dotclear&amp;step=3" method="post">';
    566                 printf('<input type="submit" name="submit" value="%s" />', __('Import Posts'));
     575                wp_nonce_field('import-dotclear');
     576                printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Posts')));
    567577                echo '</form>';
    568578        }
    569        
     579
    570580        function import_posts()
    571581        {
     
    573583                $posts = $this->get_dc_posts();
    574584                $this->posts2wp($posts);
    575                
     585
    576586                echo '<form action="admin.php?import=dotclear&amp;step=4" method="post">';
    577                 printf('<input type="submit" name="submit" value="%s" />', __('Import Comments'));
     587                wp_nonce_field('import-dotclear');
     588                printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Comments')));
    578589                echo '</form>';
    579590        }
    580        
     591
    581592        function import_comments()
    582593        {
     
    584595                $comments = $this->get_dc_comments();
    585596                $this->comments2wp($comments);
    586                
     597
    587598                echo '<form action="admin.php?import=dotclear&amp;step=5" method="post">';
    588                 printf('<input type="submit" name="submit" value="%s" />', __('Import Links'));
     599                wp_nonce_field('import-dotclear');
     600                printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Links')));
    589601                echo '</form>';
    590602        }
    591        
     603
    592604        function import_links()
    593605        {
     
    596608                $this->links2wp($links);
    597609                add_option('dc_links', $links);
    598                
     610
    599611                echo '<form action="admin.php?import=dotclear&amp;step=6" method="post">';
    600                 printf('<input type="submit" name="submit" value="%s" />', __('Finish'));
     612                wp_nonce_field('import-dotclear');
     613                printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Finish')));
    601614                echo '</form>';
    602615        }
    603        
     616
    604617        function cleanup_dcimport()
    605618        {
    606                 delete_option('tpre');
     619                delete_option('dcdbprefix');
    607620                delete_option('dc_cats');
    608621                delete_option('dcid2wpid');
     
    618631                $this->tips();
    619632        }
    620        
     633
    621634        function tips()
    622635        {
    623                 echo '<p>'.__('Welcome to WordPress.  We hope (and expect!) that you will find this platform incredibly rewarding!  As a new WordPress user coming from Dotclear, there are some things that we would like to point out.  Hopefully, they will help your transition go as smoothly as possible.').'</p>';
     636                echo '<p>'.__('Welcome to WordPress.  We hope (and expect!) that you will find this platform incredibly rewarding!  As a new WordPress user coming from DotClear, there are some things that we would like to point out.  Hopefully, they will help your transition go as smoothly as possible.').'</p>';
    624637                echo '<h3>'.__('Users').'</h3>';
    625                 echo '<p>'.sprintf(__('You have already setup WordPress and have been assigned an administrative login and password.  Forget it.  You didn\'t have that login in Dotclear, 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 Dotclear 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="%1$s">Login</a> and change it.'), '/wp-login.php').'</p>';
     638                echo '<p>'.sprintf(__('You have already setup WordPress and have been assigned an administrative login and password.  Forget it.  You didn\'t have that login in DotClear, 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 DotClear 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="%1$s">Login</a> and change it.'), '/wp-login.php').'</p>';
    626639                echo '<h3>'.__('Preserving Authors').'</h3>';
    627640                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>';
    628641                echo '<h3>'.__('Textile').'</h3>';
    629                 echo '<p>'.__('Also, since you\'re coming from Dotclear, 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>';
     642                echo '<p>'.__('Also, since you\'re coming from DotClear, 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>';
    630643                echo '<h3>'.__('WordPress Resources').'</h3>';
    631644                echo '<p>'.__('Finally, there are numerous WordPress resources around the internet.  Some of them are:').'</p>';
     
    637650                echo '<p>'.sprintf(__('That\'s it! What are you waiting for? Go <a href="%1$s">login</a>!'), '../wp-login.php').'</p>';
    638651        }
    639        
     652
    640653        function db_form()
    641654        {
    642                 echo '<ul>';
    643                 printf('<li><label for="dbuser">%s</label> <input type="text" name="dbuser" id="dbuser" /></li>', __('Dotclear Database User:'));
    644                 printf('<li><label for="dbpass">%s</label> <input type="password" name="dbpass" id="dbpass" /></li>', __('Dotclear Database Password:'));
    645                 printf('<li><label for="dbname">%s</label> <input type="text" name="dbname" id="dbname" /></li>', __('Dotclear Database Name:'));
    646                 printf('<li><label for="dbhost">%s</label> <input type="text" name="dbhost" id="dbhost" value="localhost" /></li>', __('Dotclear Database Host:'));
    647                 /* printf('<li><label for="dbprefix">%s</label> <input type="text" name="dbprefix" /></li>', __('Dotclear Table prefix (if any):')); */
    648                 printf('<li><label for="dccharset">%s</label> <input type="text" id="dccharset" name="dccharset" value="ISO-8859-15"/></li>', __('Originating character set:'));
    649                 echo '</ul>';
    650         }
    651        
    652         function dispatch() 
     655                echo '<table class="editform">';
     656                printf('<tr><th><label for="dbuser">%s</label></th><td><input type="text" name="dbuser" id="dbuser" /></td></tr>', __('DotClear Database User:'));
     657                printf('<tr><th><label for="dbpass">%s</label></th><td><input type="password" name="dbpass" id="dbpass" /></td></tr>', __('DotClear Database Password:'));
     658                printf('<tr><th><label for="dbname">%s</label></th><td><input type="text" name="dbname" id="dbname" /></td></tr>', __('DotClear Database Name:'));
     659                printf('<tr><th><label for="dbhost">%s</label></th><td><input type="text" name="dbhost" nameid="dbhost" value="localhost" /></td></tr>', __('DotClear Database Host:'));
     660                printf('<tr><th><label for="dbprefix">%s</label></th><td><input type="text" name="dbprefix" id="dbprefix" value="dc_"/></td></tr>', __('DotClear Table prefix:'));
     661                printf('<tr><th><label for="dccharset">%s</label></th><td><input type="text" name="dccharset" id="dccharset" value="ISO-8859-15"/></td></tr>', __('Originating character set:'));
     662                echo '</table>';
     663        }
     664
     665        function dispatch()
    653666        {
    654667
     
    658671                        $step = (int) $_GET['step'];
    659672                $this->header();
    660                
    661                 if ( $step > 0 ) 
     673
     674                if ( $step > 0 )
    662675                {
     676                        check_admin_referer('import-dotclear');
     677
    663678                        if($_POST['dbuser'])
    664679                        {
    665680                                if(get_option('dcuser'))
    666                                         delete_option('dcuser');       
    667                                 add_option('dcuser',$_POST['dbuser']);
     681                                        delete_option('dcuser');
     682                                add_option('dcuser', sanitize_user($_POST['dbuser'], true));
    668683                        }
    669684                        if($_POST['dbpass'])
    670685                        {
    671686                                if(get_option('dcpass'))
    672                                         delete_option('dcpass');       
    673                                 add_option('dcpass',$_POST['dbpass']);
    674                         }
    675                        
     687                                        delete_option('dcpass');
     688                                add_option('dcpass', sanitize_user($_POST['dbpass'], true));
     689                        }
     690
    676691                        if($_POST['dbname'])
    677692                        {
    678693                                if(get_option('dcname'))
    679                                         delete_option('dcname');       
    680                                 add_option('dcname',$_POST['dbname']);
     694                                        delete_option('dcname');
     695                                add_option('dcname', sanitize_user($_POST['dbname'], true));
    681696                        }
    682697                        if($_POST['dbhost'])
     
    684699                                if(get_option('dchost'))
    685700                                        delete_option('dchost');
    686                                 add_option('dchost',$_POST['dbhost']);
     701                                add_option('dchost', sanitize_user($_POST['dbhost'], true));
    687702                        }
    688703                        if($_POST['dccharset'])
     
    690705                                if(get_option('dccharset'))
    691706                                        delete_option('dccharset');
    692                                 add_option('dccharset',$_POST['dccharset']);
    693                         }                       
     707                                add_option('dccharset', sanitize_user($_POST['dccharset'], true));
     708                        }
    694709                        if($_POST['dbprefix'])
    695710                        {
    696                                 if(get_option('tpre'))
    697                                         delete_option('tpre');
    698                                 add_option('tpre',$_POST['dbprefix']);
    699                         }                       
     711                                if(get_option('dcdbprefix'))
     712                                        delete_option('dcdbprefix');
     713                                add_option('dcdbprefix', sanitize_user($_POST['dbprefix'], true));
     714                        }
    700715
    701716
    702717                }
    703718
    704                 switch ($step) 
     719                switch ($step)
    705720                {
    706721                        default:
     
    727742                                break;
    728743                }
    729                
     744
    730745                $this->footer();
    731746        }
    732747
    733         function Dotclear_Import() 
    734         {
    735                 // Nothing.     
     748        function Dotclear_Import()
     749        {
     750                // Nothing.
    736751        }
    737752}
    738753
    739754$dc_import = new Dotclear_Import();
    740 register_importer('dotclear', __('Dotclear'), __('Import posts from a Dotclear Blog'), array ($dc_import, 'dispatch'));
     755register_importer('dotclear', __('DotClear'), __('Import categories, users, posts, comments, and links from a DotClear blog'), array ($dc_import, 'dispatch'));
    741756?>
  • branches/2.0/wp-admin/import/greymatter.php

    r4239 r5406  
    77        function header() {
    88                echo '<div class="wrap">';
    9                 echo '<h2>'.__('Import Greymatter').'</h2>';
     9                echo '<h2>'.__('Import GreyMatter').'</h2>';
    1010        }
    1111
     
    3535<input type="hidden" name="import" value="greymatter" />
    3636<input type="hidden" name="step" value="1" />
     37<?php wp_nonce_field('import-greymatter'); ?>
    3738<h3><?php _e('Second step: GreyMatter details:') ?></h3>
    3839<p><table cellpadding="0">
     
    6768                return($string);
    6869        }
    69        
     70
    7071        function import() {
    7172                global $wpdb;
    72        
     73
    7374                $wpvarstoreset = array('gmpath', 'archivespath', 'lastentry');
    7475                for ($i=0; $i<count($wpvarstoreset); $i += 1) {
     
    8889
    8990                if (!chdir($archivespath))
    90                         die(sprintf(__("Wrong path, %s\ndoesn't exist\non the server"), $archivespath));
     91                        wp_die(__("Wrong path, the path to the GM entries does not exist on the server"));
    9192
    9293                if (!chdir($gmpath))
    93                         die(sprintf(__("Wrong path, %s\ndoesn't exist\non the server"), $gmpath));
    94                        
     94                        wp_die(__("Wrong path, the path to the GM files does not exist on the server"));
     95
     96                $lastentry = (int) $lastentry;
     97
    9598                $this->header();
    9699?>
     
    129132                $user_id = wp_insert_user($user_info);
    130133                $this->gmnames[$userdata[0]] = $user_id;
    131                
     134
    132135                printf('<li>'.__('user %s...').' <strong>'.__('Done').'</strong></li>', "<em>$user_login</em>");
    133136        }
     
    137140
    138141        chdir($archivespath);
    139        
     142
    140143        for($i = 0; $i <= $lastentry; $i = $i + 1) {
    141                
     144
    142145                $entryfile = "";
    143                
     146
    144147                if ($i<10000000) {
    145148                        $entryfile .= "0";
     
    195198                        $comment_status = 'open';
    196199                        $ping_status = 'closed';
    197                        
     200
    198201                        if ($post_ID = post_exists($post_title, '', $post_date)) {
    199202                                echo ' ';
     
    214217                                        $user_url=$wpdb->escape("");
    215218                                        $user_joindate=$wpdb->escape($user_joindate);
    216                                        
     219
    217220                                        $user_info = array("user_login"=>$user_login, "user_pass"=>$pass1, "user_nickname"=>$user_nickname, "user_email"=>$user_email, "user_url"=>$user_url, "user_ip"=>$user_ip, "user_domain"=>$user_domain, "user_browser"=>$user_browser, "dateYMDhour"=>$user_joindate, "user_level"=>0, "user_idmode"=>"nickname");
    218221                                        $user_id = wp_insert_user($user_info);
    219222                                        $this->gmnames[$postinfo[1]] = $user_id;
    220                                        
     223
    221224                                        echo ': ';
    222225                                        printf(__('registered deleted user %s at level 0 '), "<em>$user_login</em>");
    223226                                }
    224                        
     227
    225228                                if (array_key_exists($postinfo[1], $this->gmnames)) {
    226229                                        $post_author = $this->gmnames[$postinfo[1]];
     
    228231                                        $post_author = $user_id;
    229232                                }
    230                        
     233
    231234                                $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt');
    232235                                $post_ID = wp_insert_post($postdata);
     
    282285</ul><strong><?php _e('Done') ?></strong></li></ul>
    283286<p>&nbsp;</p>
    284 <p><?php _e('Completed Greymatter import!') ?></p>
     287<p><?php _e('Completed GreyMatter import!') ?></p>
    285288<?php
    286289        $this->footer();
     
    298301                                break;
    299302                        case 1:
     303                                check_admin_referer('import-greymatter');
    300304                                $this->import();
    301305                                break;
     
    304308
    305309        function GM_Import() {
    306                 // Nothing.     
     310                // Nothing.
    307311        }
    308312}
     
    310314$gm_import = new GM_Import();
    311315
    312 register_importer('greymatter', __('Greymatter'), __('Import posts and comments from your Greymatter blog'), array ($gm_import, 'dispatch'));
     316register_importer('greymatter', __('GreyMatter'), __('Import users, posts, and comments from a Greymatter blog'), array ($gm_import, 'dispatch'));
    313317?>
  • branches/2.0/wp-admin/import/livejournal.php

    r5099 r5406  
    154154                                break;
    155155                        case 1 :
     156                                check_admin_referer('import-upload');
    156157                                $this->import();
    157158                                break;
  • branches/2.0/wp-admin/import/mt.php

    r5099 r5406  
    146146                echo '<ol id="authors">';
    147147                echo '<form action="?import=mt&amp;step=2&amp;id=' . $this->id . '" method="post">';
     148                wp_nonce_field('import-mt');
    148149                $j = -1;
    149150                foreach ($authors as $author) {
     
    416417                                break;
    417418                        case 1 :
     419                                check_admin_referer('import-upload');
    418420                                $this->select_authors();
    419421                                break;
    420422                        case 2:
     423                                check_admin_referer('import-mt');
    421424                                $this->import();
    422425                                break;
  • branches/2.0/wp-admin/import/rss.php

    r4239 r5406  
    155155                                break;
    156156                        case 1 :
     157                                check_admin_referer('import-upload');
    157158                                $this->import();
    158159                                break;
  • branches/2.0/wp-admin/import/textpattern.php

    r4239 r5406  
    55if(!function_exists('get_catbynicename'))
    66{
    7         function get_catbynicename($category_nicename) 
     7        function get_catbynicename($category_nicename)
    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         {
    55                 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>';
     52
     53        function greet() {
     54                echo '<div class="narrow">';
     55                echo '<p>'.__('Howdy! This imports categories, users, posts, comments, and links from any Textpattern 4.0.2+ into this blog.').'</p>';
     56                echo '<p>'.__('This has not been tested on previous versions of Textpattern.  Mileage may vary.').'</p>';
    5657                echo '<p>'.__('Your Textpattern Configuration settings are as follows:').'</p>';
    5758                echo '<form action="admin.php?import=textpattern&amp;step=1" method="post">';
     59                wp_nonce_field('import-textpattern');
    5860                $this->db_form();
    59                 echo '<input type="submit" name="submit" value="'.__('Import Categories').'" />';
     61                echo '<p class="submit"><input type="submit" name="submit" value="'.attribute_escape(__('Import Categories &raquo;')).'" /></p>';
    6062                echo '</form>';
     63                echo '</div>';
    6164        }
    6265
     
    6871                set_magic_quotes_runtime(0);
    6972                $prefix = get_option('tpre');
    70                
     73
    7174                // Get Categories
    72                 return $txpdb->get_results('SELECT 
    73                                                                                 id,
    74                                                                                 name,
    75                                                                                 title
    76                                                                          FROM '.$prefix.'txp_category
    77                                                                          WHERE type = "article"',
    78                                                                          ARRAY_A);
    79         }
    80        
     75                return $txpdb->get_results('SELECT
     76                        id,
     77                        name,
     78                        title
     79                        FROM '.$prefix.'txp_category
     80                        WHERE type = "article"',
     81                        ARRAY_A);
     82        }
     83
    8184        function get_txp_users()
    8285        {
     
    8689                set_magic_quotes_runtime(0);
    8790                $prefix = get_option('tpre');
    88                
     91
    8992                // Get Users
    90                
     93
    9194                return $txpdb->get_results('SELECT
    92                                                                                 user_id,
    93                                                                                 name,
    94                                                                                 RealName,
    95                                                                                 email,
    96                                                                                 privs
    97                                                                         FROM '.$prefix.'txp_users', ARRAY_A);
    98         }
    99        
     95                        user_id,
     96                        name,
     97                        RealName,
     98                        email,
     99                        privs
     100                        FROM '.$prefix.'txp_users', ARRAY_A);
     101        }
     102
    100103        function get_txp_posts()
    101104        {
     
    104107                set_magic_quotes_runtime(0);
    105108                $prefix = get_option('tpre');
    106                
     109
    107110                // Get Posts
    108                 return $txpdb->get_results('SELECT 
    109                                                                                 ID,
    110                                                                                 Posted,
    111                                                                                 AuthorID,
    112                                                                                 LastMod,
    113                                                                                 Title,
    114                                                                                 Body,
    115                                                                                 Excerpt,
    116                                                                                 Category1,
    117                                                                                 Category2,
    118                                                                                 Status,
    119                                                                                 Keywords,
    120                                                                                 url_title,
    121                                                                                 comments_count
    122                                                                         FROM '.$prefix.'textpattern
    123                                                                         ', ARRAY_A);
    124         }
    125        
     111                return $txpdb->get_results('SELECT
     112                        ID,
     113                        Posted,
     114                        AuthorID,
     115                        LastMod,
     116                        Title,
     117                        Body,
     118                        Excerpt,
     119                        Category1,
     120                        Category2,
     121                        Status,
     122                        Keywords,
     123                        url_title,
     124                        comments_count
     125                        FROM '.$prefix.'textpattern
     126                        ', ARRAY_A);
     127        }
     128
    126129        function get_txp_comments()
    127130        {
     
    131134                set_magic_quotes_runtime(0);
    132135                $prefix = get_option('tpre');
    133                
     136
    134137                // Get Comments
    135138                return $txpdb->get_results('SELECT * FROM '.$prefix.'txp_discuss', ARRAY_A);
    136139        }
    137        
     140
    138141                function get_txp_links()
    139142        {
     
    142145                set_magic_quotes_runtime(0);
    143146                $prefix = get_option('tpre');
    144                
    145                 return $txpdb->get_results('SELECT 
    146                                                                                 id,
    147                                                                                 date,
    148                                                                                 category,
    149                                                                                 url,
    150                                                                                 linkname,
    151                                                                                 description
    152                                                                           FROM '.$prefix.'txp_link',
    153                                                                           ARRAY_A);                                               
    154         }
    155        
    156         function cat2wp($categories='') 
     147
     148                return $txpdb->get_results('SELECT
     149                        id,
     150                        date,
     151                        category,
     152                        url,
     153                        linkname,
     154                        description
     155                        FROM '.$prefix.'txp_link',
     156                        ARRAY_A);
     157        }
     158
     159        function cat2wp($categories='')
    157160        {
    158161                // General Housekeeping
     
    164167                {
    165168                        echo '<p>'.__('Importing Categories...').'<br /><br /></p>';
    166                         foreach ($categories as $category) 
     169                        foreach ($categories as $category)
    167170                        {
    168171                                $count++;
    169172                                extract($category);
    170                                
    171                                
     173
     174
    172175                                // Make Nice Variables
    173176                                $name = $wpdb->escape($name);
    174177                                $title = $wpdb->escape($title);
    175                                
     178
    176179                                if($cinfo = category_exists($name))
    177180                                {
     
    184187                                $txpcat2wpcat[$id] = $ret_id;
    185188                        }
    186                        
     189
    187190                        // Store category translation for future use
    188191                        add_option('txpcat2wpcat',$txpcat2wpcat);
     
    193196                return false;
    194197        }
    195        
     198
    196199        function users2wp($users='')
    197200        {
     
    200203                $count = 0;
    201204                $txpid2wpid = array();
    202                
     205
    203206                // Midnight Mojo
    204207                if(is_array($users))
     
    209212                                $count++;
    210213                                extract($user);
    211                                
     214
    212215                                // Make Nice Variables
    213216                                $name = $wpdb->escape($name);
    214217                                $RealName = $wpdb->escape($RealName);
    215                                
     218
    216219                                if($uinfo = get_userdatabylogin($name))
    217220                                {
    218                                        
     221
    219222                                        $ret_id = wp_insert_user(array(
    220223                                                                'ID'                    => $uinfo->ID,
     
    226229                                                                );
    227230                                }
    228                                 else 
     231                                else
    229232                                {
    230233                                        $ret_id = wp_insert_user(array(
     
    237240                                }
    238241                                $txpid2wpid[$user_id] = $ret_id;
    239                                
     242
    240243                                // Set Textpattern-to-WordPress permissions translation
    241244                                $transperms = array(1 => '10', 2 => '9', 3 => '5', 4 => '4', 5 => '3', 6 => '2', 7 => '0');
    242                                
     245
    243246                                // Update Usermeta Data
    244247                                $user = new WP_User($ret_id);
     
    250253                                if('2'  == $transperms[$privs]) { $user->set_role('contributor'); }
    251254                                if('0'  == $transperms[$privs]) { $user->set_role('subscriber'); }
    252                                
     255
    253256                                update_usermeta( $ret_id, 'wp_user_level', $transperms[$privs] );
    254257                                update_usermeta( $ret_id, 'rich_editing', 'false');
    255258                        }// End foreach($users as $user)
    256                        
     259
    257260                        // Store id translation array for future use
    258261                        add_option('txpid2wpid',$txpid2wpid);
    259                        
    260                        
     262
     263
    261264                        echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> users imported.'), $count).'<br /><br /></p>';
    262265                        return true;
    263266                }// End if(is_array($users)
    264                
     267
    265268                echo __('No Users to Import!');
    266269                return false;
    267                
     270
    268271        }// End function user2wp()
    269        
     272
    270273        function posts2wp($posts='')
    271274        {
     
    284287                                $count++;
    285288                                extract($post);
    286                                
     289
    287290                                // Set Textpattern-to-WordPress status translation
    288291                                $stattrans = array(1 => 'draft', 2 => 'private', 3 => 'draft', 4 => 'publish', 5 => 'publish');
    289                                
     292
    290293                                //Can we do this more efficiently?
    291294                                $uinfo = ( get_userdatabylogin( $AuthorID ) ) ? get_userdatabylogin( $AuthorID ) : 1;
     
    296299                                $Excerpt = $wpdb->escape($Excerpt);
    297300                                $post_status = $stattrans[$Status];
    298                                
     301
    299302                                // Import Post data into WordPress
    300                                
     303
    301304                                if($pinfo = post_exists($Title,$Body))
    302305                                {
    303306                                        $ret_id = wp_insert_post(array(
    304                                                         'ID'                            => $pinfo,
    305                                                         'post_date'                     => $Posted,
    306                                                         'post_date_gmt'         => $post_date_gmt,
    307                                                         'post_author'           => $authorid,
    308                                                         'post_modified'         => $LastMod,
    309                                                         'post_modified_gmt' => $post_modified_gmt,
    310                                                         'post_title'            => $Title,
    311                                                         'post_content'          => $Body,
    312                                                         'post_excerpt'          => $Excerpt,
    313                                                         'post_status'           => $post_status,
    314                                                         'post_name'                     => $url_title,
    315                                                         'comment_count'         => $comments_count)
    316                                                         );
    317                                 }
    318                                 else 
     307                                                'ID'                            => $pinfo,
     308                                                'post_date'                     => $Posted,
     309                                                'post_date_gmt'         => $post_date_gmt,
     310                                                'post_author'           => $authorid,
     311                                                'post_modified'         => $LastMod,
     312                                                'post_modified_gmt' => $post_modified_gmt,
     313                                                'post_title'            => $Title,
     314                                                'post_content'          => $Body,
     315                                                'post_excerpt'          => $Excerpt,
     316                                                'post_status'           => $post_status,
     317                                                'post_name'                     => $url_title,
     318                                                'comment_count'         => $comments_count)
     319                                                );
     320                                }
     321                                else
    319322                                {
    320323                                        $ret_id = wp_insert_post(array(
    321                                                         'post_date'                     => $Posted,
    322                                                         'post_date_gmt'         => $post_date_gmt,
    323                                                         'post_author'           => $authorid,
    324                                                         'post_modified'         => $LastMod,
    325                                                         'post_modified_gmt' => $post_modified_gmt,
    326                                                         'post_title'            => $Title,
    327                                                         'post_content'          => $Body,
    328                                                         'post_excerpt'          => $Excerpt,
    329                                                         'post_status'           => $post_status,
    330                                                         'post_name'                     => $url_title,
    331                                                         'comment_count'         => $comments_count)
    332                                                         );
     324                                                'post_date'                     => $Posted,
     325                                                'post_date_gmt'         => $post_date_gmt,
     326                                                'post_author'           => $authorid,
     327                                                'post_modified'         => $LastMod,
     328                                                'post_modified_gmt' => $post_modified_gmt,
     329                                                'post_title'            => $Title,
     330                                                'post_content'          => $Body,
     331                                                'post_excerpt'          => $Excerpt,
     332                                                'post_status'           => $post_status,
     333                                                'post_name'                     => $url_title,
     334                                                'comment_count'         => $comments_count)
     335                                                );
    333336                                }
    334337                                $txpposts2wpposts[$ID] = $ret_id;
    335                                
     338
    336339                                // Make Post-to-Category associations
    337340                                $cats = array();
     
    339342                                if($cat2 = get_catbynicename($Category2)) { $cats[2] = $cat2; }
    340343
    341                                 if(!empty($cats)) { wp_set_post_cats('', $ret_id, $cats); }
     344                                if(!empty($cats)) { wp_set_post_categories($ret_id, $cats); }
    342345                        }
    343346                }
    344347                // Store ID translation for later use
    345348                add_option('txpposts2wpposts',$txpposts2wpposts);
    346                
     349
    347350                echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> posts imported.'), $count).'<br /><br /></p>';
    348                 return true;   
    349         }
    350        
     351                return true;
     352        }
     353
    351354        function comments2wp($comments='')
    352355        {
     
    356359                $txpcm2wpcm = array();
    357360                $postarr = get_option('txpposts2wpposts');
    358                
     361
    359362                // Magic Mojo
    360363                if(is_array($comments))
     
    365368                                $count++;
    366369                                extract($comment);
    367                                
     370
    368371                                // WordPressify Data
    369372                                $comment_ID = ltrim($discussid, '0');
     
    374377                                $web = $wpdb->escape($web);
    375378                                $message = $wpdb->escape($message);
    376                                
     379
    377380                                if($cinfo = comment_exists($name, $posted))
    378381                                {
    379382                                        // Update comments
    380383                                        $ret_id = wp_update_comment(array(
    381                                                         'comment_ID'                    => $cinfo,
    382                                                         'comment_post_ID'               => $comment_post_ID,
    383                                                         'comment_author'                => $name,
    384                                                         'comment_author_email'  => $email,
    385                                                         'comment_author_url'    => $web,
    386                                                         'comment_date'                  => $posted,
    387                                                         'comment_content'               => $message,
    388                                                         'comment_approved'              => $comment_approved)
    389                                                         );
    390                                 }
    391                                 else 
     384                                                'comment_ID'                    => $cinfo,
     385                                                'comment_post_ID'               => $comment_post_ID,
     386                                                'comment_author'                => $name,
     387                                                'comment_author_email'  => $email,
     388                                                'comment_author_url'    => $web,
     389                                                'comment_date'                  => $posted,
     390                                                'comment_content'               => $message,
     391                                                'comment_approved'              => $comment_approved)
     392                                                );
     393                                }
     394                                else
    392395                                {
    393396                                        // Insert comments
    394397                                        $ret_id = wp_insert_comment(array(
    395                                                         'comment_post_ID'               => $comment_post_ID,
    396                                                         'comment_author'                => $name,
    397                                                         'comment_author_email'  => $email,
    398                                                         'comment_author_url'    => $web,
    399                                                         'comment_author_IP'             => $ip,
    400                                                         'comment_date'                  => $posted,
    401                                                         'comment_content'               => $message,
    402                                                         'comment_approved'              => $comment_approved)
    403                                                         );
     398                                                'comment_post_ID'               => $comment_post_ID,
     399                                                'comment_author'                => $name,
     400                                                'comment_author_email'  => $email,
     401                                                'comment_author_url'    => $web,
     402                                                'comment_author_IP'             => $ip,
     403                                                'comment_date'                  => $posted,
     404                                                'comment_content'               => $message,
     405                                                'comment_approved'              => $comment_approved)
     406                                                );
    404407                                }
    405408                                $txpcm2wpcm[$comment_ID] = $ret_id;
    406409                        }
    407410                        // Store Comment ID translation for future use
    408                         add_option('txpcm2wpcm', $txpcm2wpcm);                 
    409                        
     411                        add_option('txpcm2wpcm', $txpcm2wpcm);
     412
    410413                        // Associate newly formed categories with posts
    411414                        get_comment_count($ret_id);
    412                        
    413                        
     415
     416
    414417                        echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> comments imported.'), $count).'<br /><br /></p>';
    415418                        return true;
     
    418421                return false;
    419422        }
    420        
     423
    421424        function links2wp($links='')
    422425        {
     
    424427                global $wpdb;
    425428                $count = 0;
    426                
     429
    427430                // Deal with the links
    428431                if(is_array($links))
     
    433436                                $count++;
    434437                                extract($link);
    435                                
     438
    436439                                // Make nice vars
    437440                                $category = $wpdb->escape($category);
    438441                                $linkname = $wpdb->escape($linkname);
    439442                                $description = $wpdb->escape($description);
    440                                
     443
    441444                                if($linfo = link_exists($linkname))
    442445                                {
     
    450453                                                                );
    451454                                }
    452                                 else 
     455                                else
    453456                                {
    454457                                        $ret_id = wp_insert_link(array(
     
    471474                return false;
    472475        }
    473                
    474         function import_categories() 
    475         {       
    476                 // Category Import     
     476
     477        function import_categories()
     478        {
     479                // Category Import
    477480                $cats = $this->get_txp_cats();
    478481                $this->cat2wp($cats);
    479482                add_option('txp_cats', $cats);
    480                
    481                
    482                        
     483
     484
     485
    483486                echo '<form action="admin.php?import=textpattern&amp;step=2" method="post">';
    484                 printf('<input type="submit" name="submit" value="%s" />', __('Import Users'));
     487                wp_nonce_field('import-textpattern');
     488                printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Users')));
    485489                echo '</form>';
    486490
    487491        }
    488        
     492
    489493        function import_users()
    490494        {
    491495                // User Import
    492                 $users = $this->get_txp_users(); 
     496                $users = $this->get_txp_users();
    493497                $this->users2wp($users);
    494                
     498
    495499                echo '<form action="admin.php?import=textpattern&amp;step=3" method="post">';
    496                 printf('<input type="submit" name="submit" value="%s" />', __('Import Posts'));
     500                wp_nonce_field('import-textpattern');
     501                printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Posts')));
    497502                echo '</form>';
    498503        }
    499        
     504
    500505        function import_posts()
    501506        {
     
    503508                $posts = $this->get_txp_posts();
    504509                $this->posts2wp($posts);
    505                
     510
    506511                echo '<form action="admin.php?import=textpattern&amp;step=4" method="post">';
    507                 printf('<input type="submit" name="submit" value="%s" />', __('Import Comments'));
     512                wp_nonce_field('import-textpattern');
     513                printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Comments')));
    508514                echo '</form>';
    509515        }
    510        
     516
    511517        function import_comments()
    512518        {
     
    514520                $comments = $this->get_txp_comments();
    515521                $this->comments2wp($comments);
    516                
     522
    517523                echo '<form action="admin.php?import=textpattern&amp;step=5" method="post">';
    518                 printf('<input type="submit" name="submit" value="%s" />', __('Import Links'));
     524                wp_nonce_field('import-textpattern');
     525                printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Links')));
    519526                echo '</form>';
    520527        }
    521        
     528
    522529        function import_links()
    523530        {
     
    526533                $this->links2wp($links);
    527534                add_option('txp_links', $links);
    528                
     535
    529536                echo '<form action="admin.php?import=textpattern&amp;step=6" method="post">';
    530                 printf('<input type="submit" name="submit" value="%s" />', __('Finish'));
     537                wp_nonce_field('import-textpattern');
     538                printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Finish')));
    531539                echo '</form>';
    532540        }
    533        
     541
    534542        function cleanup_txpimport()
    535543        {
     
    547555                $this->tips();
    548556        }
    549        
     557
    550558        function tips()
    551559        {
     
    566574                echo '<p>'.sprintf(__('That\'s it! What are you waiting for? Go <a href="%1$s">login</a>!'), '/wp-login.php').'</p>';
    567575        }
    568        
     576
    569577        function db_form()
    570578        {
    571                 echo '<ul>';
    572                 printf('<li><label for="dbuser">%s</label> <input type="text" name="dbuser" id="dbuser" /></li>', __('Textpattern Database User:'));
    573                 printf('<li><label for="dbpass">%s</label> <input type="password" name="dbpass" id="dbpass" /></li>', __('Textpattern Database Password:'));
    574                 printf('<li><label for="dbname">%s</label> <input type="text" id="dbname" name="dbname" /></li>', __('Textpattern Database Name:'));
    575                 printf('<li><label for="dbhost">%s</label> <input type="text" id="dbhost" name="dbhost" value="localhost" /></li>', __('Textpattern Database Host:'));
    576                 printf('<li><label for="dbprefix">%s</label> <input type="text" name="dbprefix" id="dbprefix"  /></li>', __('Textpattern Table prefix (if any):'));
    577                 echo '</ul>';
    578         }
    579        
    580         function dispatch() 
     579                echo '<table class="editform">';
     580                printf('<tr><th scope="row"><label for="dbuser">%s</label></th><td><input type="text" name="dbuser" id="dbuser" /></td></tr>', __('Textpattern Database User:'));
     581                printf('<tr><th scope="row"><label for="dbpass">%s</label></th><td><input type="password" name="dbpass" id="dbpass" /></td></tr>', __('Textpattern Database Password:'));
     582                printf('<tr><th scope="row"><label for="dbname">%s</label></th><td><input type="text" id="dbname" name="dbname" /></td></tr>', __('Textpattern Database Name:'));
     583                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:'));
     584                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):'));
     585                echo '</table>';
     586        }
     587
     588        function dispatch()
    581589        {
    582590
     
    586594                        $step = (int) $_GET['step'];
    587595                $this->header();
    588                
    589                 if ( $step > 0 ) 
     596
     597                if ( $step > 0 )
    590598                {
     599                        check_admin_referer('import-textpattern');
     600
    591601                        if($_POST['dbuser'])
    592602                        {
    593603                                if(get_option('txpuser'))
    594                                         delete_option('txpuser');       
    595                                 add_option('txpuser',$_POST['dbuser']);
     604                                        delete_option('txpuser');
     605                                add_option('txpuser', sanitize_user($_POST['dbuser'], true));
    596606                        }
    597607                        if($_POST['dbpass'])
    598608                        {
    599609                                if(get_option('txppass'))
    600                                         delete_option('txppass');       
    601                                 add_option('txppass',$_POST['dbpass']);
    602                         }
    603                        
     610                                        delete_option('txppass');
     611                                add_option('txppass',  sanitize_user($_POST['dbpass'], true));
     612                        }
     613
    604614                        if($_POST['dbname'])
    605615                        {
    606616                                if(get_option('txpname'))
    607                                         delete_option('txpname');       
    608                                 add_option('txpname',$_POST['dbname']);
     617                                        delete_option('txpname');
     618                                add_option('txpname',  sanitize_user($_POST['dbname'], true));
    609619                        }
    610620                        if($_POST['dbhost'])
     
    612622                                if(get_option('txphost'))
    613623                                        delete_option('txphost');
    614                                 add_option('txphost',$_POST['dbhost']);
     624                                add_option('txphost',  sanitize_user($_POST['dbhost'], true));
    615625                        }
    616626                        if($_POST['dbprefix'])
     
    618628                                if(get_option('tpre'))
    619629                                        delete_option('tpre');
    620                                 add_option('tpre',$_POST['dbprefix']);
    621                         }                       
     630                                add_option('tpre',  sanitize_user($_POST['dbprefix']));
     631                        }
    622632
    623633
    624634                }
    625635
    626                 switch ($step) 
     636                switch ($step)
    627637                {
    628638                        default:
     
    649659                                break;
    650660                }
    651                
     661
    652662                $this->footer();
    653663        }
    654664
    655         function Textpattern_Import() 
    656         {
    657                 // Nothing.     
     665        function Textpattern_Import()
     666        {
     667                // Nothing.
    658668        }
    659669}
    660670
    661671$txp_import = new Textpattern_Import();
    662 register_importer('textpattern', __('Textpattern'), __('Import posts from a Textpattern Blog'), array ($txp_import, 'dispatch'));
     672register_importer('textpattern', __('Textpattern'), __('Import categories, users, posts, comments, and links from a Textpattern blog'), array ($txp_import, 'dispatch'));
    663673?>
Note: See TracChangeset for help on using the changeset viewer.