private function processXML()
{
$reader = new \XMLReader();
$reader->open(FRONTEND_FILES_PATH . '/wordpress.xml');
// Loop through the document
while ($reader->read()) {
// Start tag for item?
if ($reader->name != 'item' && $reader->name != 'wp:author') {
continue;
}
// End tag?
if ($reader->nodeType == \XMLReader::END_ELEMENT) {
continue;
}
// Get the raw XML
$xmlString = $reader->readOuterXml();
// Read the XML as an SimpleXML-object
/* @var \SimpleXMLElement $xml */
$xml = @simplexml_load_string($xmlString);
// Skip element if it isn't a valid SimpleXML-object
if ($xml === false) {
continue;
}
// Is it really an item?
if (mb_substr($xmlString, 0, 5) == '<item') {
// What type of content are we dealing with?
switch ($xml->children('wp', true)->post_type) {
case 'post':
// Process as post
$this->processPost($xml);
break;
case 'attachment':
// Process as attachment
$this->processAttachment($xml);
break;
default:
// Don't do anything
break;
}
} elseif (mb_substr($xmlString, 0, 10) == '<wp:author') {
// Process the authors
$this->authors[(string) $xml->children('wp', true)->author_login] = array('id' => (string) $xml->children('wp', true)->author_id, 'login' => (string) $xml->children('wp', true)->author_login, 'email' => (string) $xml->children('wp', true)->author_email, 'display_name' => (string) $xml->children('wp', true)->author_display_name, 'first_name' => (string) $xml->children('wp', true)->author_first_name, 'last_name' => (string) $xml->children('wp', true)->author_last_name);
}
// End
if (!$reader->read()) {
break;
}
}
// close
$reader->close();
}