WordPress.org

Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    • Property svn:eol-style set to native
    r3424 r4424  
    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
     
    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    }
     
    128133    {
    129134        echo '<div class="wrap">';
    130         echo '<h2>'.__('Import Dotclear').'</h2>';
     135        echo '<h2>'.__('Import DotClear').'</h2>';
    131136        echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'</p>';
    132137    }
     
    136141        echo '</div>';
    137142    }
    138    
     143
    139144    function greet()
    140145    {
    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>';
     146        echo '<div class="narrow"><p>'.__('Howdy! This importer allows you to extract posts from a DotClear database into your blog.  Mileage may vary.').'</p>';
     147        echo '<p>'.__('Your DotClear Configuration settings are as follows:').'</p>';
    143148        echo '<form action="admin.php?import=dotclear&amp;step=1" method="post">';
    144149        $this->db_form();
    145         echo '<input type="submit" name="submit" value="'.__('Import Categories').'" />';
    146         echo '</form>';
     150        echo '<p class="submit"><input type="submit" name="submit" value="'.__('Import Categories').' &raquo;" /></p>';
     151        echo '</form></div>';
    147152    }
    148153
     
    153158        $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost'));
    154159        set_magic_quotes_runtime(0);
    155         $prefix = get_option('tpre');
    156        
     160        $dbprefix = get_option('dcdbprefix');
     161
    157162        // Get Categories
    158         return $dcdb->get_results('SELECT * FROM dc_categorie', ARRAY_A);
    159     }
    160    
     163        return $dcdb->get_results('SELECT * FROM '.$dbprefix.'categorie', ARRAY_A);
     164    }
     165
    161166    function get_dc_users()
    162167    {
     
    165170        $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost'));
    166171        set_magic_quotes_runtime(0);
    167         $prefix = get_option('tpre');
    168        
     172        $dbprefix = get_option('dcdbprefix');
     173
    169174        // Get Users
    170        
    171         return $dcdb->get_results('SELECT * FROM dc_user', ARRAY_A);
    172     }
    173    
     175
     176        return $dcdb->get_results('SELECT * FROM '.$dbprefix.'user', ARRAY_A);
     177    }
     178
    174179    function get_dc_posts()
    175180    {
     
    177182        $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost'));
    178183        set_magic_quotes_runtime(0);
    179         $prefix = get_option('tpre');
    180        
     184        $dbprefix = get_option('dcdbprefix');
     185
    181186        // 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    
     187        return $dcdb->get_results('SELECT '.$dbprefix.'post.*, '.$dbprefix.'categorie.cat_libelle_url AS post_cat_name
     188                        FROM '.$dbprefix.'post INNER JOIN '.$dbprefix.'categorie
     189                          ON '.$dbprefix.'post.cat_id = '.$dbprefix.'categorie.cat_id', ARRAY_A);
     190    }
     191
    187192    function get_dc_comments()
    188193    {
     
    191196        $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost'));
    192197        set_magic_quotes_runtime(0);
    193         $prefix = get_option('tpre');
    194        
     198        $dbprefix = get_option('dcdbprefix');
     199
    195200        // Get Comments
    196         return $dcdb->get_results('SELECT * FROM dc_comment', ARRAY_A);
    197     }
    198    
     201        return $dcdb->get_results('SELECT * FROM '.$dbprefix.'comment', ARRAY_A);
     202    }
     203
    199204    function get_dc_links()
    200205    {
     
    202207        $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost'));
    203208        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        $dbprefix = get_option('dcdbprefix');
     210
     211        return $dcdb->get_results('SELECT * FROM '.$dbprefix.'link ORDER BY position', ARRAY_A);
     212    }
     213
    209214    function cat2wp($categories='')
    210215    {
     
    221226                $count++;
    222227                extract($category);
    223                
     228
    224229                // Make Nice Variables
    225230                $name = $wpdb->escape($cat_libelle_url);
     
    237242                $dccat2wpcat[$id] = $ret_id;
    238243            }
    239            
     244
    240245            // Store category translation for future use
    241246            add_option('dccat2wpcat',$dccat2wpcat);
     
    246251        return false;
    247252    }
    248    
     253
    249254    function users2wp($users='')
    250255    {
     
    253258        $count = 0;
    254259        $dcid2wpid = array();
    255        
     260
    256261        // Midnight Mojo
    257262        if(is_array($users))
     
    262267                $count++;
    263268                extract($user);
    264                
     269
    265270                // Make Nice Variables
    266271                $name = $wpdb->escape(csc ($name));
    267272                $RealName = $wpdb->escape(csc ($user_pseudo));
    268                
     273
    269274                if($uinfo = get_userdatabylogin($name))
    270275                {
    271                    
     276
    272277                    $ret_id = wp_insert_user(array(
    273278                                'ID'        => $uinfo->ID,
     
    290295                }
    291296                $dcid2wpid[$user_id] = $ret_id;
    292                
     297
    293298                // Set Dotclear-to-WordPress permissions translation
    294                
     299
    295300                // Update Usermeta Data
    296301                $user = new WP_User($ret_id);
     
    303308                else if(2  <= $wp_perms) { $user->set_role('contributor'); }
    304309                else                     { $user->set_role('subscriber'); }
    305                
     310
    306311                update_usermeta( $ret_id, 'wp_user_level', $wp_perms);
    307312                update_usermeta( $ret_id, 'rich_editing', 'false');
     
    309314                update_usermeta( $ret_id, 'last_name', csc ($user_nom));
    310315            }// End foreach($users as $user)
    311            
     316
    312317            // Store id translation array for future use
    313318            add_option('dcid2wpid',$dcid2wpid);
    314            
    315            
     319
     320
    316321            echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> users imported.'), $count).'<br /><br /></p>';
    317322            return true;
    318323        }// End if(is_array($users)
    319        
     324
    320325        echo __('No Users to Import!');
    321326        return false;
    322        
     327
    323328    }// End function user2wp()
    324    
     329
    325330    function posts2wp($posts='')
    326331    {
     
    339344                $count++;
    340345                extract($post);
    341                
     346
    342347                // Set Dotclear-to-WordPress status translation
    343348                $stattrans = array(0 => 'draft', 1 => 'publish');
    344349                $comment_status_map = array (0 => 'closed', 1 => 'open');
    345                
     350
    346351                //Can we do this more efficiently?
    347352                $uinfo = ( get_userdatabylogin( $user_id ) ) ? get_userdatabylogin( $user_id ) : 1;
     
    350355                $Title = $wpdb->escape(csc ($post_titre));
    351356                $post_content = textconv ($post_content);
     357                $post_excerpt = "";
    352358                if ($post_chapo != "") {
    353359                    $post_excerpt = textconv ($post_chapo);
     
    357363                $post_content = $wpdb->escape ($post_content);
    358364                $post_status = $stattrans[$post_pub];
    359                
     365
    360366                // Import Post data into WordPress
    361                
     367
    362368                if($pinfo = post_exists($Title,$post_content))
    363369                {
     
    398404                }
    399405                $dcposts2wpposts[$post_id] = $ret_id;
    400                
     406
    401407                // Make Post-to-Category associations
    402408                $cats = array();
    403409                if($cat1 = get_catbynicename($post_cat_name)) { $cats[1] = $cat1; }
    404410
    405                 if(!empty($cats)) { wp_set_post_cats('', $ret_id, $cats); }
     411                if(!empty($cats)) { wp_set_post_categories($ret_id, $cats); }
    406412            }
    407413        }
    408414        // Store ID translation for later use
    409415        add_option('dcposts2wpposts',$dcposts2wpposts);
    410        
     416
    411417        echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> posts imported.'), $count).'<br /><br /></p>';
    412         return true;   
    413     }
    414    
     418        return true;
     419    }
     420
    415421    function comments2wp($comments='')
    416422    {
     
    420426        $dccm2wpcm = array();
    421427        $postarr = get_option('dcposts2wpposts');
    422        
     428
    423429        // Magic Mojo
    424430        if(is_array($comments))
     
    429435                $count++;
    430436                extract($comment);
    431                
     437
    432438                // WordPressify Data
    433439                $comment_ID = ltrim($comment_id, '0');
     
    438444                $web = "http://".$wpdb->escape($comment_site);
    439445                $message = $wpdb->escape(textconv ($comment_content));
    440                
     446
    441447                if($cinfo = comment_exists($name, $comment_dt))
    442448                {
     
    473479            }
    474480            // Store Comment ID translation for future use
    475             add_option('dccm2wpcm', $dccm2wpcm);           
    476            
     481            add_option('dccm2wpcm', $dccm2wpcm);
     482
    477483            // Associate newly formed categories with posts
    478484            get_comment_count($ret_id);
    479            
    480            
     485
     486
    481487            echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> comments imported.'), $count).'<br /><br /></p>';
    482488            return true;
     
    485491        return false;
    486492    }
    487    
     493
    488494    function links2wp($links='')
    489495    {
     
    491497        global $wpdb;
    492498        $count = 0;
    493        
     499
    494500        // Deal with the links
    495501        if(is_array($links))
     
    500506                $count++;
    501507                extract($link);
    502                
     508
    503509                if ($title != "") {
    504510                    if ($cinfo = link_cat_exists (csc ($title))) {
     
    512518                    $linkname = $wpdb->escape(csc ($label));
    513519                    $description = $wpdb->escape(csc ($title));
    514                
     520
    515521                    if($linfo = link_exists($linkname)) {
    516522                        $ret_id = wp_insert_link(array(
     
    541547        return false;
    542548    }
    543        
     549
    544550    function import_categories()
    545     {   
    546         // Category Import 
     551    {
     552        // Category Import
    547553        $cats = $this->get_dc_cats();
    548554        $this->cat2wp($cats);
    549555        add_option('dc_cats', $cats);
    550        
    551        
    552            
     556
     557
     558
    553559        echo '<form action="admin.php?import=dotclear&amp;step=2" method="post">';
    554560        printf('<input type="submit" name="submit" value="%s" />', __('Import Users'));
     
    556562
    557563    }
    558    
     564
    559565    function import_users()
    560566    {
     
    562568        $users = $this->get_dc_users();
    563569        $this->users2wp($users);
    564        
     570
    565571        echo '<form action="admin.php?import=dotclear&amp;step=3" method="post">';
    566572        printf('<input type="submit" name="submit" value="%s" />', __('Import Posts'));
    567573        echo '</form>';
    568574    }
    569    
     575
    570576    function import_posts()
    571577    {
     
    573579        $posts = $this->get_dc_posts();
    574580        $this->posts2wp($posts);
    575        
     581
    576582        echo '<form action="admin.php?import=dotclear&amp;step=4" method="post">';
    577583        printf('<input type="submit" name="submit" value="%s" />', __('Import Comments'));
    578584        echo '</form>';
    579585    }
    580    
     586
    581587    function import_comments()
    582588    {
     
    584590        $comments = $this->get_dc_comments();
    585591        $this->comments2wp($comments);
    586        
     592
    587593        echo '<form action="admin.php?import=dotclear&amp;step=5" method="post">';
    588594        printf('<input type="submit" name="submit" value="%s" />', __('Import Links'));
    589595        echo '</form>';
    590596    }
    591    
     597
    592598    function import_links()
    593599    {
     
    596602        $this->links2wp($links);
    597603        add_option('dc_links', $links);
    598        
     604
    599605        echo '<form action="admin.php?import=dotclear&amp;step=6" method="post">';
    600606        printf('<input type="submit" name="submit" value="%s" />', __('Finish'));
    601607        echo '</form>';
    602608    }
    603    
     609
    604610    function cleanup_dcimport()
    605611    {
    606         delete_option('tpre');
     612        delete_option('dcdbprefix');
    607613        delete_option('dc_cats');
    608614        delete_option('dcid2wpid');
     
    618624        $this->tips();
    619625    }
    620    
     626
    621627    function tips()
    622628    {
    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>';
     629        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>';
    624630        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>';
     631        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>';
    626632        echo '<h3>'.__('Preserving Authors').'</h3>';
    627633        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>';
    628634        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/2004/04/19/wordpress-plugin-textile-20/">Textile for WordPress</a>.  Trust me... You\'ll want it.').'</p>';
     635        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>';
    630636        echo '<h3>'.__('WordPress Resources').'</h3>';
    631637        echo '<p>'.__('Finally, there are numerous WordPress resources around the internet.  Some of them are:').'</p>';
    632638        echo '<ul>';
    633639        echo '<li>'.__('<a href="http://www.wordpress.org">The official WordPress site</a>').'</li>';
    634         echo '<li>'.__('<a href="http://wordpress.org/support/">The WordPress support forums').'</li>';
     640        echo '<li>'.__('<a href="http://wordpress.org/support/">The WordPress support forums</a>').'</li>';
    635641        echo '<li>'.__('<a href="http://codex.wordpress.org">The Codex (In other words, the WordPress Bible)</a>').'</li>';
    636642        echo '</ul>';
    637         echo '<p>'.sprintf(__('That\'s it! What are you waiting for? Go <a href="%1$s">login</a>!'), '/wp-login.php').'</p>';
    638     }
    639    
     643        echo '<p>'.sprintf(__('That\'s it! What are you waiting for? Go <a href="%1$s">login</a>!'), '../wp-login.php').'</p>';
     644    }
     645
    640646    function db_form()
    641647    {
    642         echo '<ul>';
    643         printf('<li><label for="dbuser">%s</label> <input type="text" name="dbuser" /></li>', __('Dotclear Database User:'));
    644         printf('<li><label for="dbpass">%s</label> <input type="password" name="dbpass" /></li>', __('Dotclear Database Password:'));
    645         printf('<li><label for="dbname">%s</label> <input type="text" name="dbname" /></li>', __('Dotclear Database Name:'));
    646         printf('<li><label for="dbhost">%s</label> <input type="text" name="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" name="dccharset" value="ISO-8859-15"/></li>', __('Originating character set:'));
    649         echo '</ul>';
    650     }
    651    
     648        echo '<table class="editform">';
     649        printf('<tr><th><label for="dbuser">%s</label></th><td><input type="text" name="dbuser" id="dbuser" /></td></tr>', __('Dotclear Database User:'));
     650        printf('<tr><th><label for="dbpass">%s</label></th><td><input type="password" name="dbpass" id="dbpass" /></td></tr>', __('DotClear Database Password:'));
     651        printf('<tr><th><label for="dbname">%s</label></th><td><input type="text" name="dbname" id="dbname" /></td></tr>', __('Dotclear Database Name:'));
     652        printf('<tr><th><label for="dbhost">%s</label></th><td><input type="text" name="dbhost" nameid="dbhost" value="localhost" /></td></tr>', __('DotClear Database Host:'));
     653        printf('<tr><th><label for="dbprefix">%s</label></th><td><input type="text" name="dbprefix" id="dbprefix" value="dc_"/></td></tr>', __('DotClear Table prefix:'));
     654        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:'));
     655        echo '</table>';
     656    }
     657
    652658    function dispatch()
    653659    {
     
    658664            $step = (int) $_GET['step'];
    659665        $this->header();
    660        
     666
    661667        if ( $step > 0 )
    662668        {
     
    664670            {
    665671                if(get_option('dcuser'))
    666                     delete_option('dcuser');   
     672                    delete_option('dcuser');
    667673                add_option('dcuser',$_POST['dbuser']);
    668674            }
     
    670676            {
    671677                if(get_option('dcpass'))
    672                     delete_option('dcpass');   
     678                    delete_option('dcpass');
    673679                add_option('dcpass',$_POST['dbpass']);
    674680            }
    675            
     681
    676682            if($_POST['dbname'])
    677683            {
    678684                if(get_option('dcname'))
    679                     delete_option('dcname');   
     685                    delete_option('dcname');
    680686                add_option('dcname',$_POST['dbname']);
    681687            }
     
    691697                    delete_option('dccharset');
    692698                add_option('dccharset',$_POST['dccharset']);
    693             }           
     699            }
    694700            if($_POST['dbprefix'])
    695701            {
    696                 if(get_option('tpre'))
    697                     delete_option('tpre');
    698                 add_option('tpre',$_POST['dbprefix']);
    699             }           
     702                if(get_option('dcdbprefix'))
     703                    delete_option('dcdbprefix');
     704                add_option('dcdbprefix',$_POST['dbprefix']);
     705            }
    700706
    701707
     
    727733                break;
    728734        }
    729        
     735
    730736        $this->footer();
    731737    }
     
    733739    function Dotclear_Import()
    734740    {
    735         // Nothing. 
     741        // Nothing.
    736742    }
    737743}
    738744
    739745$dc_import = new Dotclear_Import();
    740 register_importer('dotclear', 'Dotclear', __('Import posts from a Dotclear Blog'), array ($dc_import, 'dispatch'));
     746register_importer('dotclear', __('DotClear'), __('Import posts from a DotClear Blog'), array ($dc_import, 'dispatch'));
    741747?>
Note: See TracChangeset for help on using the changeset viewer.