private function processAttachment($xml)
{
// Are we really working with a post?
if ($xml->children('wp', true)->post_type != 'attachment') {
return false;
}
// Set paths
$imagesPath = FRONTEND_FILES_PATH . '/userfiles/images/blog';
$imagesURL = FRONTEND_FILES_URL . '/userfiles/images/blog';
// Create directory if needed
if (!file_exists($imagesPath) || !is_dir($imagesPath)) {
$this->filesystem->mkdir($imagesPath);
}
$file = (string) $xml->children('wp', true)->attachment_url;
$guid = (string) $xml->guid;
$fileId = (string) $xml->children('wp', true)->post_id;
// Set filename
$destinationFile = $fileId . '_' . basename($file);
// Download the file
try {
$this->filesystem->dumpFile($imagesPath . '/' . $destinationFile, file_get_contents($file));
} catch (Exception $e) {
// Ignore
}
// Keep a log of downloaded files
$this->attachments[mb_strtolower($file)] = $imagesURL . '/' . $destinationFile;
$this->attachments[mb_strtolower($guid)] = $imagesURL . '/' . $destinationFile;
return true;
}