Example #1
0
 public function parsePostData($post)
 {
     if (is_object($post)) {
         $post = (array) $post;
     }
     $post['ID'] = (int) $post['ID'];
     $keyCache1 = Utils::hashKey(array(__CLASS__, __METHOD__, $post['ID']));
     $tmp = PepVN_Data::$cacheObject->get_cache($keyCache1);
     if (null !== $tmp) {
         return $tmp;
     }
     if (!isset($post['post_excerpt']) || !$post['post_excerpt']) {
         $post['post_excerpt'] = $post['post_content'];
     }
     $post['post_excerpt'] = Text::removeShortcode($post['post_excerpt'], ' ');
     $post['post_excerpt'] = strip_tags($post['post_excerpt']);
     $post['post_excerpt'] = Text::removeLine($post['post_excerpt'], ' ');
     $post['post_excerpt'] = Text::reduceLine($post['post_excerpt'], ' ');
     $post['post_excerpt'] = explode(' ', $post['post_excerpt'], 250);
     if (isset($post['post_excerpt'][251])) {
         $post['post_excerpt'][251] = '...';
     }
     $post['post_excerpt'] = implode(' ', $post['post_excerpt']);
     $post['postPermalink'] = $this->get_permalink($post['ID']);
     $post['postImages'] = array();
     preg_match_all('#<img[^>]+src=(\'|\\")([^\'\\"]+)\\1[^>]+\\/?>#is', $post['post_content'], $matched1);
     if (isset($matched1[2]) && $matched1[2]) {
         foreach ($matched1[2] as $key1 => $value1) {
             $post['postImages'][] = array('src' => $value1);
         }
     }
     $post['postThumbnailId'] = 0;
     $post['postThumbnailUrl'] = '';
     $post_thumbnail_id = $this->get_post_thumbnail_id($post['ID']);
     if ($post_thumbnail_id) {
         $post['postThumbnailId'] = $post_thumbnail_id;
         $post_thumbnail_url = $this->wp_get_attachment_url($post_thumbnail_id);
         if ($post_thumbnail_url) {
             $post['postThumbnailUrl'] = $post_thumbnail_url;
             $post['postImages'][] = array('src' => $post_thumbnail_url);
         }
     }
     $post['postThumbnailId'] = (int) $post['postThumbnailId'];
     $post['postThumbnailUrl'] = trim($post['postThumbnailUrl']);
     $post['postAttachments'] = array();
     $attachments = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_parent' => $post['ID']));
     if ($attachments) {
         foreach ($attachments as $key1 => $attachment) {
             unset($attachments[$key1]);
             $tmp = array('ID' => $attachment->ID, 'post_mime_type' => $attachment->post_mime_type, 'post_title' => $attachment->post_title);
             $tmp['attachment_url'] = $this->wp_get_attachment_url($attachment->ID);
             $tmp['metadata'] = wp_get_attachment_metadata($attachment->ID, true);
             $post['postAttachments'][$attachment->ID] = $tmp;
             unset($attachment, $tmp);
         }
     }
     $post['postContentRawText'] = $post['post_content'];
     $post['postContentRawText'] = strip_tags($post['postContentRawText']);
     $post['postContentRawText'] = Text::reduceLine($post['postContentRawText']);
     $post['postContentRawText'] = Text::reduceSpace($post['postContentRawText']);
     //unset($post['post_content']);
     PepVN_Data::$cacheObject->set_cache($keyCache1, $post);
     return $post;
 }