Make WordPress Core


Ignore:
Timestamp:
05/24/2004 08:22:18 AM (21 years ago)
Author:
saxmatt
Message:

Giant commit, sorry mailing list people. Move all table names to new $wpdb versions. Works but the whole app needs thorough testing now.

File:
1 edited

Legend:

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

    r1292 r1355  
    7272
    7373function users_form($n) {
    74     global $wpdb, $tableusers, $testing;
    75     $users = $wpdb->get_results("SELECT * FROM $tableusers ORDER BY ID");
     74    global $wpdb, $testing;
     75    $users = $wpdb->get_results("SELECT * FROM $wpdb->users ORDER BY ID");
    7676    ?><select name="userselect[<?php echo $n; ?>]">
    7777    <option value="#NONE#">- Select -</option>
     
    148148    //function to check the authorname and do the mapping
    149149    function checkauthor($author) {
    150     global $wpdb, $tableusers, $mtnames, $newauthornames, $j;//mtnames is an array with the names in the mt import file
     150    global $wpdb, $mtnames, $newauthornames, $j;//mtnames is an array with the names in the mt import file
    151151    $md5pass = md5(changeme);
    152152    if (!(in_array($author, $mtnames))) { //a new mt author name is found
    153153        ++$j;
    154154        $mtnames[$j] = $author; //add that new mt author name to an array
    155         $user_id = $wpdb->get_var("SELECT ID FROM $tableusers WHERE user_login = '$newauthornames[$j]'"); //check if the new author name defined by the user is a pre-existing wp user
     155        $user_id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$newauthornames[$j]'"); //check if the new author name defined by the user is a pre-existing wp user
    156156        if (!$user_id) { //banging my head against the desk now.
    157157            if ($newauthornames[$j] == 'left_blank') { //check if the user does not want to change the authorname
    158                 $wpdb->query("INSERT INTO $tableusers (user_level, user_login, user_pass, user_nickname) VALUES ('1', '$author', '$md5pass', '$author')"); // if user does not want to change, insert the authorname $author
    159                 $user_id = $wpdb->get_var("SELECT ID FROM $tableusers WHERE user_login = '$author'");
     158                $wpdb->query("INSERT INTO $wpdb->users (user_level, user_login, user_pass, user_nickname) VALUES ('1', '$author', '$md5pass', '$author')"); // if user does not want to change, insert the authorname $author
     159                $user_id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$author'");
    160160                $newauthornames[$j] = $author; //now we have a name, in the place of left_blank.
    161161            } else {
    162             $wpdb->query("INSERT INTO $tableusers (user_level, user_login, user_pass, user_nickname) VALUES ('1', '$newauthornames[$j]', '$md5pass', '$newauthornames[$j]')"); //if not left_blank, insert the user specified name
    163             $user_id = $wpdb->get_var("SELECT ID FROM $tableusers WHERE user_login = '$newauthornames[$j]'");
     162            $wpdb->query("INSERT INTO $wpdb->users (user_level, user_login, user_pass, user_nickname) VALUES ('1', '$newauthornames[$j]', '$md5pass', '$newauthornames[$j]')"); //if not left_blank, insert the user specified name
     163            $user_id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$newauthornames[$j]'");
    164164            }
    165165        } else return $user_id; // return pre-existing wp username if it exists
    166166    } else {
    167167    $key = array_search($author, $mtnames); //find the array key for $author in the $mtnames array
    168     $user_id = $wpdb->get_var("SELECT ID FROM $tableusers WHERE user_login = '$newauthornames[$key]'");//use that key to get the value of the author's name from $newauthornames
     168    $user_id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$newauthornames[$key]'");//use that key to get the value of the author's name from $newauthornames
    169169    }
    170170    return $user_id;
     
    273273
    274274    // Let's check to see if it's in already
    275     if ($wpdb->get_var("SELECT ID FROM $tableposts WHERE post_title = '$post_title' AND post_date = '$post_date'")) {
     275    if ($wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$post_title' AND post_date = '$post_date'")) {
    276276        echo "Post already imported.";
    277277    } else {
    278278        $post_author = checkauthor($post_author);//just so that if a post already exists, new users are not created by checkauthor
    279         $wpdb->query("INSERT INTO $tableposts (
     279        $wpdb->query("INSERT INTO $wpdb->posts (
    280280            post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt,  post_status, comment_status, ping_status, post_name, post_modified, post_modified_gmt)
    281281            VALUES
    282282            ('$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_name','$post_date', '$post_date_gmt')");
    283         $post_id = $wpdb->get_var("SELECT ID FROM $tableposts WHERE post_title = '$post_title' AND post_date = '$post_date'");
     283        $post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$post_title' AND post_date = '$post_date'");
    284284        if (0 != count($post_categories)) {
    285285            foreach ($post_categories as $post_category) {
    286286            // See if the category exists yet
    287             $cat_id = $wpdb->get_var("SELECT cat_ID from $tablecategories WHERE cat_name = '$post_category'");
     287            $cat_id = $wpdb->get_var("SELECT cat_ID from $wpdb->categories WHERE cat_name = '$post_category'");
    288288            if (!$cat_id && '' != trim($post_category)) {
    289289                $cat_nicename = sanitize_title($post_category);
    290                 $wpdb->query("INSERT INTO $tablecategories (cat_name, category_nicename) VALUES ('$post_category', '$cat_nicename')");
    291                 $cat_id = $wpdb->get_var("SELECT cat_ID from $tablecategories WHERE cat_name = '$post_category'");
     290                $wpdb->query("INSERT INTO $wpdb->categories (cat_name, category_nicename) VALUES ('$post_category', '$cat_nicename')");
     291                $cat_id = $wpdb->get_var("SELECT cat_ID from $wpdb->categories WHERE cat_name = '$post_category'");
    292292            }
    293293            if ('' == trim($post_category)) $cat_id = 1;
    294294            // Double check it's not there already
    295             $exists = $wpdb->get_row("SELECT * FROM $tablepost2cat WHERE post_id = $post_id AND category_id = $cat_id");
     295            $exists = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post_id AND category_id = $cat_id");
    296296
    297297             if (!$exists) {
    298298                $wpdb->query("
    299                 INSERT INTO $tablepost2cat
     299                INSERT INTO $wpdb->post2cat
    300300                (post_id, category_id)
    301301                VALUES
     
    305305        } // end category loop
    306306        } else {
    307             $exists = $wpdb->get_row("SELECT * FROM $tablepost2cat WHERE post_id = $post_id AND category_id = 1");
    308             if (!$exists) $wpdb->query("INSERT INTO $tablepost2cat (post_id, category_id) VALUES ($post_id, 1) ");
     307            $exists = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post_id AND category_id = 1");
     308            if (!$exists) $wpdb->query("INSERT INTO $wpdb->post2cat (post_id, category_id) VALUES ($post_id, 1) ");
    309309        }
    310310        echo " Post imported successfully...";
     
    339339
    340340            // Check if it's already there
    341             if (!$wpdb->get_row("SELECT * FROM $tablecomments WHERE comment_date = '$comment_date' AND comment_content = '$comment_content'")) {
    342                 $wpdb->query("INSERT INTO $tablecomments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content, comment_approved)
     341            if (!$wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_date = '$comment_date' AND comment_content = '$comment_content'")) {
     342                $wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content, comment_approved)
    343343                VALUES
    344344                ($post_id, '$comment_author', '$comment_email', '$comment_url', '$comment_ip', '$comment_date', '$comment_content', '1')");
     
    384384     
    385385            // Check if it's already there
    386             if (!$wpdb->get_row("SELECT * FROM $tablecomments WHERE comment_date = '$comment_date' AND comment_content = '$comment_content'")) {
    387                 $wpdb->query("INSERT INTO $tablecomments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content, comment_approved)
     386            if (!$wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_date = '$comment_date' AND comment_content = '$comment_content'")) {
     387                $wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content, comment_approved)
    388388                VALUES
    389389                ($post_id, '$comment_author', '$comment_email', '$comment_url', '$comment_ip', '$comment_date', '$comment_content', '1')");
Note: See TracChangeset for help on using the changeset viewer.