case 'DATE': $post_date = strtotime($value); $post_date = date('Y-m-d H:i:s', $post_date); $post_date_gmt = get_gmt_from_date("$post_date"); break; default: // echo "\n$key: $value"; break; } // end switch } // End foreach // Let's check to see if it's in already if ($wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$post_title' AND post_date = '$post_date'")) { echo "Post already imported."; } else { $post_author = checkauthor($post_author);//just so that if a post already exists, new users are not created by checkauthor $wpdb->query("INSERT INTO $wpdb->posts ( 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) VALUES ('$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')"); $post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$post_title' AND post_date = '$post_date'"); if (0 != count($post_categories)) { foreach ($post_categories as $post_category) { // See if the category exists yet $cat_id = $wpdb->get_var("SELECT cat_ID from $wpdb->categories WHERE cat_name = '$post_category'"); if (!$cat_id && '' != trim($post_category)) { $cat_nicename = sanitize_title($post_category); $wpdb->query("INSERT INTO $wpdb->categories (cat_name, category_nicename) VALUES ('$post_category', '$cat_nicename')"); $cat_id = $wpdb->get_var("SELECT cat_ID from $wpdb->categories WHERE cat_name = '$post_category'"); } if ('' == trim($post_category)) $cat_id = 1;
$post_date = strtotime($value); $post_date = date('Y-m-d H:i:s', $post_date); $post_date_gmt = get_gmt_from_date("{$post_date}"); break; default: // echo "\n$key: $value"; break; } // end switch } // End foreach // Let's check to see if it's in already if ($wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_title = '{$post_title}' AND post_date = '{$post_date}'")) { echo "Post already imported."; } else { $post_author = checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor $wpdb->query("INSERT INTO {$wpdb->posts} (\r\n\t\t\tpost_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)\r\n\t\t\tVALUES \r\n\t\t\t('{$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}')"); $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_title = '{$post_title}' AND post_date = '{$post_date}'"); if (0 != count($post_categories)) { foreach ($post_categories as $post_category) { // See if the category exists yet $cat_id = $wpdb->get_var("SELECT cat_ID from {$wpdb->categories} WHERE cat_name = '{$post_category}'"); if (!$cat_id && '' != trim($post_category)) { $cat_nicename = sanitize_title($post_category); $wpdb->query("INSERT INTO {$wpdb->categories} (cat_name, category_nicename) VALUES ('{$post_category}', '{$cat_nicename}')"); $cat_id = $wpdb->get_var("SELECT cat_ID from {$wpdb->categories} WHERE cat_name = '{$post_category}'"); } if ('' == trim($post_category)) { $cat_id = 1; }
preg_match("|-----\nBODY:(.*)|s", $post, $body); $body = trim($body[1]); $post_content = addslashes($body . $extended); $post = preg_replace("|(-----\nBODY:.*)|s", '', $post); // Grab the metadata from what's left $metadata = explode("\n", $post); foreach ($metadata as $line) { preg_match("/^(.*?):(.*)/", $line, $token); $key = trim($token[1]); $value = trim($token[2]); // Now we decide what it is and what to do with it switch ($key) { case '': break; case 'AUTHOR': $post_author = checkauthor($value); break; case 'TITLE': $post_title = addslashes($value); echo '<i>' . stripslashes($post_title) . '</i>... '; $post_name = sanitize_title($post_title); break; case 'STATUS': // "publish" and "draft" enumeration items match up; no change required $post_status = $value; if (empty($post_status)) { $post_status = 'publish'; } break; case 'ALLOW COMMENTS': $post_allow_comments = $value;