Backend\Modules\Blog\Actions\ImportWordpress::processPost PHP Method

processPost() private method

Import a blog post
private processPost ( SimpleXMLElement $xml ) : boolean
$xml SimpleXMLElement
return boolean
    private function processPost($xml)
    {
        // Are we really working with a post?
        if ($xml->children('wp', true)->post_type != 'post') {
            return false;
        }
        // This is a deleted post, don't import
        if ($xml->children('wp', true)->status == 'trash') {
            return false;
        }
        // Mapping for wordpress status => fork status
        $statusses = array('draft' => 'draft', 'pending' => 'draft', 'private' => 'private', 'publish' => 'active', 'future' => 'publish');
        $commentStatusses = array('open' => 'Y', 'closed' => 'N');
        // Prepare item
        $item = array();
        $item['user_id'] = $this->handleUser((string) $xml->children('dc', true)->creator);
        $item['title'] = (string) $xml->title;
        $item['text'] = $this->handleUrls((string) $xml->children('content', true)->encoded, $this->frm->getField('filter')->getValue());
        $item['created_on'] = (string) $xml->children('wp', true)->post_date;
        $item['publish_on'] = (string) $xml->children('wp', true)->post_date;
        $item['edited_on'] = (string) $xml->children('wp', true)->post_date;
        $item['status'] = $statusses[(string) $xml->children('wp', true)->status];
        $item['allow_comments'] = $commentStatusses[(string) $xml->children('wp', true)->comment_status];
        // Some status corrections
        if ($item['status'] == 'draft') {
            $item['hidden'] = 'Y';
        } elseif ($item['status'] == 'private') {
            $item['status'] = 'publish';
            $item['hidden'] = 'Y';
        }
        // Prepare meta
        $meta = array();
        $meta['url'] = (string) $xml->children('wp', true)->post_name;
        // Prepare tags
        $tags = array();
        // Walk through wp categories
        foreach ($xml->category as $category) {
            /* @var \SimpleXMLElement $category */
            switch ($category->attributes()->domain) {
                case 'category':
                    $item['category_id'] = $this->handleCategory((string) $category);
                    break;
                case 'post_tag':
                    $tags[] = (string) $category;
                    break;
                default:
                    // Do nothing
                    break;
            }
        }
        // Prepare comments
        $comments = array();
        // Walk through wp comments
        foreach ($xml->children('wp', true)->comment as $comment) {
            /* @var \SimpleXMLElement $comment */
            $comments[] = array('author' => (string) $comment->children('wp', true)->comment_author, 'email' => (string) $comment->children('wp', true)->comment_author_email, 'text' => filter_var((string) $comment->children('wp', true)->comment_content, FILTER_SANITIZE_STRING), 'created_on' => (string) $comment->children('wp', true)->comment_date, 'status' => (string) $comment->children('wp', true)->comment_approved == '1' ? 'published' : 'moderation');
        }
        // Make the call
        Model::insertCompletePost($item, $meta, $tags, $comments);
        return true;
    }