X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/ff81ee6e8304a1982a3ec4f5b134764a29d502cf..refs/tags/wordpress-2.9:/wp-admin/import/greymatter.php
diff --git a/wp-admin/import/greymatter.php b/wp-admin/import/greymatter.php
index e69de29b..47c15d4b 100644
--- a/wp-admin/import/greymatter.php
+++ b/wp-admin/import/greymatter.php
@@ -0,0 +1,334 @@
+';
+ screen_icon();
+ echo '
'.__('Import GreyMatter').'
';
+ }
+
+ function footer() {
+ echo '';
+ }
+
+ function greet() {
+ $this->header();
+?>
+
+
+
+
+- If authors are found not to be in gm-authors.cgi, imports them at level 0.') ?>
+
+
+
+
+
+
+
+footer();
+ }
+
+
+
+ function gm2autobr($string) { // transforms GM's |*| into b2's
\n
+ $string = str_replace("|*|","
\n",$string);
+ return($string);
+ }
+
+ function import() {
+ global $wpdb;
+
+ $wpvarstoreset = array('gmpath', 'archivespath', 'lastentry');
+ for ($i=0; $iheader();
+?>
+
+
+escape($userdata[0]);
+ $pass1=$wpdb->escape($userdata[1]);
+ $user_nickname=$wpdb->escape($userdata[0]);
+ $user_email=$wpdb->escape($userdata[2]);
+ $user_url=$wpdb->escape($userdata[3]);
+ $user_joindate=$wpdb->escape($user_joindate);
+
+ $user_id = username_exists($user_login);
+ if ($user_id) {
+ printf('- '.__('user %s').''.__('Already exists').'
', "$user_login");
+ $this->gmnames[$userdata[0]] = $user_id;
+ continue;
+ }
+
+ $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"=>"1", "user_idmode"=>"nickname");
+ $user_id = wp_insert_user($user_info);
+ $this->gmnames[$userdata[0]] = $user_id;
+
+ printf('- '.__('user %s...').' '.__('Done').'
', "$user_login");
+ }
+
+?>
+
gm2autobr($entry[2]);
+ $postmorecontent=$this->gm2autobr($entry[3]);
+
+ $post_author=trim($wpdb->escape($postinfo[1]));
+
+ $post_title=$this->gm2autobr($postinfo[2]);
+ printf('- '.__('entry # %s : %s : by %s'), $entryfile, $post_title, $postinfo[1]);
+ $post_title=$wpdb->escape($post_title);
+
+ $postyear=$postinfo[6];
+ $postmonth=zeroise($postinfo[4],2);
+ $postday=zeroise($postinfo[5],2);
+ $posthour=zeroise($postinfo[7],2);
+ $postminute=zeroise($postinfo[8],2);
+ $postsecond=zeroise($postinfo[9],2);
+
+ if (($postinfo[10]=="PM") && ($posthour!="12"))
+ $posthour=$posthour+12;
+
+ $post_date="$postyear-$postmonth-$postday $posthour:$postminute:$postsecond";
+
+ $post_content=$postmaincontent;
+ if (strlen($postmorecontent)>3)
+ $post_content .= "
".$postmorecontent;
+ $post_content=$wpdb->escape($post_content);
+
+ $post_karma=$postinfo[12];
+
+ $post_status = 'publish'; //in greymatter, there are no drafts
+ $comment_status = 'open';
+ $ping_status = 'closed';
+
+ if ($post_ID = post_exists($post_title, '', $post_date)) {
+ echo ' ';
+ _e('(already exists)');
+ } else {
+ //just so that if a post already exists, new users are not created by checkauthor
+ // we'll check the author is registered, or if it's a deleted author
+ $user_id = username_exists($post_author);
+ if (!$user_id) { // if deleted from GM, we register the author as a level 0 user
+ $user_ip="127.0.0.1";
+ $user_domain="localhost";
+ $user_browser="server";
+ $user_joindate="1979-06-06 00:41:00";
+ $user_login=$wpdb->escape($post_author);
+ $pass1=$wpdb->escape("password");
+ $user_nickname=$wpdb->escape($post_author);
+ $user_email=$wpdb->escape("user@deleted.com");
+ $user_url=$wpdb->escape("");
+ $user_joindate=$wpdb->escape($user_joindate);
+
+ $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");
+ $user_id = wp_insert_user($user_info);
+ $this->gmnames[$postinfo[1]] = $user_id;
+
+ echo ': ';
+ printf(__('registered deleted user %s at level 0 '), "$user_login");
+ }
+
+ if (array_key_exists($postinfo[1], $this->gmnames)) {
+ $post_author = $this->gmnames[$postinfo[1]];
+ } else {
+ $post_author = $user_id;
+ }
+
+ $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');
+ $post_ID = wp_insert_post($postdata);
+ if ( is_wp_error( $post_ID ) )
+ return $post_ID;
+ }
+
+ $c=count($entry);
+ if ($c>4) {
+ $numAddedComments = 0;
+ $numComments = 0;
+ for ($j=4;$j<$c;$j++) {
+ $entry[$j]=$this->gm2autobr($entry[$j]);
+ $commentinfo=explode("|",$entry[$j]);
+ $comment_post_ID=$post_ID;
+ $comment_author=$wpdb->escape($commentinfo[0]);
+ $comment_author_email=$wpdb->escape($commentinfo[2]);
+ $comment_author_url=$wpdb->escape($commentinfo[3]);
+ $comment_author_IP=$wpdb->escape($commentinfo[1]);
+
+ $commentyear=$commentinfo[7];
+ $commentmonth=zeroise($commentinfo[5],2);
+ $commentday=zeroise($commentinfo[6],2);
+ $commenthour=zeroise($commentinfo[8],2);
+ $commentminute=zeroise($commentinfo[9],2);
+ $commentsecond=zeroise($commentinfo[10],2);
+ if (($commentinfo[11]=="PM") && ($commenthour!="12"))
+ $commenthour=$commenthour+12;
+ $comment_date="$commentyear-$commentmonth-$commentday $commenthour:$commentminute:$commentsecond";
+
+ $comment_content=$wpdb->escape($commentinfo[12]);
+
+ if (!comment_exists($comment_author, $comment_date)) {
+ $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_approved');
+ $commentdata = wp_filter_comment($commentdata);
+ wp_insert_comment($commentdata);
+ $numAddedComments++;
+ }
+ $numComments++;
+ }
+ if ($numAddedComments > 0) {
+ echo ': ';
+ printf( _n('imported %s comment', 'imported %s comments', $numAddedComments) , $numAddedComments);
+ }
+ $preExisting = $numComments - numAddedComments;
+ if ($preExisting > 0) {
+ echo ' ';
+ printf( _n( 'ignored %s pre-existing comment', 'ignored %s pre-existing comments', $preExisting ) , $preExisting);
+ }
+ }
+ echo '... '.__('Done').' ';
+ }
+ }
+ do_action('import_done', 'greymatter');
+ ?>
+
+
+
+footer();
+ return;
+ }
+
+ function dispatch() {
+ if (empty ($_GET['step']))
+ $step = 0;
+ else
+ $step = (int) $_GET['step'];
+
+ switch ($step) {
+ case 0 :
+ $this->greet();
+ break;
+ case 1:
+ check_admin_referer('import-greymatter');
+ $result = $this->import();
+ if ( is_wp_error( $result ) )
+ echo $result->get_error_message();
+ break;
+ }
+ }
+
+ function GM_Import() {
+ // Nothing.
+ }
+}
+
+$gm_import = new GM_Import();
+
+register_importer('greymatter', __('GreyMatter'), __('Import users, posts, and comments from a Greymatter blog.'), array ($gm_import, 'dispatch'));
+?>