function _processWPXMLAttachment($wpPostId, $content, $attachments, $authorId) { require_once EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'connectors.php'; foreach ($attachments as $attachment) { $link = $attachment['link']; $attachementURL = $attachment['attachment_url']; if (EasyImageHelper::isImage($attachementURL)) { $filname = EasyImageHelper::getFileName($attachementURL); $extension = EasyImageHelper::getFileExtension($attachementURL); $folder = JPATH_ROOT . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'blogs' . DIRECTORY_SEPARATOR . $wpPostId; if (!JFolder::exists($folder)) { JFolder::create($folder); } // new image location $newFile = $folder . DIRECTORY_SEPARATOR . $filname; $connector = EB::connector(); $connector->addUrl($attachementURL); $connector->execute(); $imageraw = $connector->getResult($attachementURL); if ($imageraw) { if (JFile::write($newFile, $imageraw)) { //replace the string in the content. $absImagePath = rtrim(JURI::root(), '/') . '/images/blogs/' . $wpPostId . '/' . $filname; $content = str_ireplace('href="' . $link . '"', 'href="' . $absImagePath . '"', $content); $pattern = '/src=[\\"\']?([^\\"\']?.*(png|jpg|jpeg|gif))[\\"\']?/i'; $content = preg_replace($pattern, 'src="' . $absImagePath . '"', $content); } } // if( file_put_contents( $newFile, file_get_contents($attachementURL) ) !== false ) // { // //replace the string in the content. // $absImagePath = rtrim( JURI::root(), '/' ) . '/images/blogs/' . $wpPostId . '/' . $filname; // $content = JString::str_ireplace( 'href="' . $link . '"' , 'href="' . $absImagePath . '"' , $content ); // // $pattern = '/src=[\"\']?([^\"\']?.*(png|jpg|jpeg|gif))[\"\']?/i'; // $content = preg_replace( $pattern , 'src="'.$absImagePath.'"' , $content ); // } } } return $content; }