예제 #1
0
 /**
  * do import for posts
  * @param $post
  * @return array
  */
 public function process_post($post)
 {
     $post_id = $this->get_tag($post, 'wp:post_id');
     $post_title = $this->get_tag($post, 'title');
     $post_date = $this->get_tag($post, 'wp:post_date');
     $post_date_gmt = $this->get_tag($post, 'wp:post_date_gmt');
     $comment_status = $this->get_tag($post, 'wp:comment_status');
     $ping_status = $this->get_tag($post, 'wp:ping_status');
     $status = $this->get_tag($post, 'wp:status');
     $post_name = $this->get_tag($post, 'wp:post_name');
     $post_parent = $this->get_tag($post, 'wp:post_parent');
     $menu_order = $this->get_tag($post, 'wp:menu_order');
     $post_type = $this->get_tag($post, 'wp:post_type');
     $post_password = $this->get_tag($post, 'wp:post_password');
     $is_sticky = $this->get_tag($post, 'wp:is_sticky');
     $guid = $this->get_tag($post, 'guid');
     $post_author = $this->get_tag($post, 'dc:creator');
     $post_excerpt = $this->get_tag($post, 'excerpt:encoded');
     $post_excerpt = preg_replace_callback('|<(/?[A-Z]+)|', array(&$this, '_normalize_tag'), $post_excerpt);
     $post_excerpt = str_replace('<br>', '<br />', $post_excerpt);
     $post_excerpt = str_replace('<hr>', '<hr />', $post_excerpt);
     $post_content = $this->get_tag($post, 'content:encoded');
     $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array(&$this, '_normalize_tag'), $post_content);
     $post_content = str_replace('<br>', '<br />', $post_content);
     $post_content = str_replace('<hr>', '<hr />', $post_content);
     $post_content = $this->parser->pre_shortcode_tags($post_content);
     $postdata = compact('post_id', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt', 'post_title', 'status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent', 'menu_order', 'post_type', 'post_password', 'is_sticky');
     $attachment_url = $this->get_tag($post, 'wp:attachment_url');
     if ($attachment_url) {
         $postdata['attachment_url'] = $attachment_url;
     }
     //hw attachment
     preg_match_all('|<hw:attachment>(.+?)</hw:attachment>|is', $post, $attachments);
     $attachments = $attachments[1];
     if ($attachments) {
         foreach ($attachments as $p) {
             $hw_attachment_url = $this->get_tag($p, 'hw:url');
             if ($hw_attachment_url) {
                 if (!HW_URL::valid_url($hw_attachment_url)) {
                     $postdata['attachment_url'] = $this->parser->data('import_path') . $hw_attachment_url;
                 } else {
                     $postdata['attachment_url'] = $hw_attachment_url;
                 }
                 //found new attachment in post
                 if ($post_type !== 'attachment') {
                     $_postdata = hwArray::cloneArray($postdata);
                     $_postdata['post_content'] = HW_String::limit($_postdata['post_content'], 50);
                     $_postdata['post_excerpt'] = HW_String::limit($_postdata['post_excerpt'], 50);
                     $_postdata['post_type'] = 'attachment';
                     $_postdata['_id'] = $this->get_tag($p, 'hw:_id');
                     $_postdata['thumbnail'] = $this->get_tag($p, 'hw:thumbnail');
                     if ($_postdata['thumbnail']) {
                         $_postdata['hw_thumbnail_id'] = $this->get_tag($p, 'hw:_id');
                     }
                     $this->posts[] = $_postdata;
                 }
                 /*else {
                       $postdata['thumbnail'] = $this->get_tag($p, 'hw:thumbnail');
                       if($postdata['thumbnail']) $postdata['hw_thumbnail_id'] = $this->get_tag($p, 'hw:_id');
                   }*/
             }
         }
     }
     preg_match_all('|<category domain="([^"]+?)" nicename="([^"]+?)">(.+?)</category>|is', $post, $terms, PREG_SET_ORDER);
     foreach ($terms as $t) {
         $post_terms[] = array('slug' => $t[2], 'domain' => $t[1], 'name' => str_replace(array('<![CDATA[', ']]>'), '', $t[3]));
     }
     if (!empty($post_terms)) {
         $postdata['terms'] = $post_terms;
     }
     preg_match_all('|<wp:comment>(.+?)</wp:comment>|is', $post, $comments);
     $comments = $comments[1];
     if ($comments) {
         foreach ($comments as $comment) {
             preg_match_all('|<wp:commentmeta>(.+?)</wp:commentmeta>|is', $comment, $commentmeta);
             $commentmeta = $commentmeta[1];
             $c_meta = array();
             foreach ($commentmeta as $m) {
                 $c_meta[] = array('key' => $this->get_tag($m, 'wp:meta_key'), 'value' => $this->get_tag($m, 'wp:meta_value'));
             }
             $post_comments[] = array('comment_id' => $this->get_tag($comment, 'wp:comment_id'), 'comment_author' => $this->get_tag($comment, 'wp:comment_author'), 'comment_author_email' => $this->get_tag($comment, 'wp:comment_author_email'), 'comment_author_IP' => $this->get_tag($comment, 'wp:comment_author_IP'), 'comment_author_url' => $this->get_tag($comment, 'wp:comment_author_url'), 'comment_date' => $this->get_tag($comment, 'wp:comment_date'), 'comment_date_gmt' => $this->get_tag($comment, 'wp:comment_date_gmt'), 'comment_content' => $this->get_tag($comment, 'wp:comment_content'), 'comment_approved' => $this->get_tag($comment, 'wp:comment_approved'), 'comment_type' => $this->get_tag($comment, 'wp:comment_type'), 'comment_parent' => $this->get_tag($comment, 'wp:comment_parent'), 'comment_user_id' => $this->get_tag($comment, 'wp:comment_user_id'), 'commentmeta' => $c_meta);
         }
     }
     if (!empty($post_comments)) {
         $postdata['comments'] = $post_comments;
     }
     preg_match_all('|<wp:postmeta>(.+?)</wp:postmeta>|is', $post, $postmeta);
     $postmeta = $postmeta[1];
     if ($postmeta) {
         foreach ($postmeta as $p) {
             $post_postmeta[] = array('key' => $this->get_tag($p, 'wp:meta_key'), 'value' => $this->get_tag($p, 'wp:meta_value', true));
         }
     }
     if (!empty($post_postmeta)) {
         $postdata['postmeta'] = $post_postmeta;
     }
     return $postdata;
 }