function parse($file)
{
$wxr_version = $in_post = false;
$fp = $this->fopen($file, 'r');
if ($fp) {
while (!$this->feof($fp)) {
$importline = rtrim($this->fgets($fp));
if (!$wxr_version && preg_match('|<wp:wxr_version>(\\d+\\.\\d+)</wp:wxr_version>|', $importline, $version)) {
$wxr_version = $version[1];
}
if (false !== strpos($importline, '<wp:base_site_url>')) {
preg_match('|<wp:base_site_url>(.*?)</wp:base_site_url>|is', $importline, $url);
$this->base_url = $url[1];
continue;
}
if (false !== strpos($importline, '<wp:category>')) {
preg_match('|<wp:category>(.*?)</wp:category>|is', $importline, $category);
$this->categories[] = $this->process_category($category[1]);
continue;
}
if (false !== strpos($importline, '<wp:tag>')) {
preg_match('|<wp:tag>(.*?)</wp:tag>|is', $importline, $tag);
$this->tags[] = $this->process_tag($tag[1]);
continue;
}
if (false !== strpos($importline, '<wp:term>')) {
preg_match('|<wp:term>(.*?)</wp:term>|is', $importline, $term);
$this->terms[] = $this->process_term($term[1]);
continue;
}
if (false !== strpos($importline, '<wp:author>')) {
preg_match('|<wp:author>(.*?)</wp:author>|is', $importline, $author);
$a = $this->process_author($author[1]);
$this->authors[$a['author_login']] = $a;
continue;
}
if (false !== strpos($importline, '<item>')) {
$post = '';
$in_post = true;
continue;
}
if (false !== strpos($importline, '</item>')) {
$in_post = false;
$this->posts[] = $this->process_post($post);
continue;
}
if ($in_post) {
$post .= $importline . "\n";
}
}
$this->fclose($fp);
}
if (!$wxr_version) {
return new WP_Error('WXR_parse_error', __('This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer'));
}
return array('authors' => $this->authors, 'posts' => $this->posts, 'categories' => $this->categories, 'tags' => $this->tags, 'terms' => $this->terms, 'base_url' => $this->base_url, 'version' => $wxr_version);
}