/** * Converts the image from the NGG format to the post format * defined by the ShoutEm Data Exchange Protocol: @link http://fiveminutes.jira.com/wiki/display/SE/Data+Exchange+Protocol */ private function convert_to_se_post($image, $params) { $user_data = get_userdata($image->author); $remaped_post['author'] = $user_data->display_name; $result = array('post_id' => $image->pid, 'published_at' => $image->imagedate, 'body' => $image->description, 'title' => $image->alttext, 'summary' => $image->description, 'commentable' => 'no', 'comments_count' => 0, 'likeable' => false, 'likes_count' => 0, 'author' => $user_data->display_name, 'link' => $image->imageURL, 'attachments' => array('images' => array(array('src' => $image->imageURL, 'id' => '', 'width' => $image->meta_data['width'], 'height' => $image->meta_data['height'], 'thumbnail_url' => $image->thumbURL)))); sanitize_attachments($result['attachments']); return $result; }
function sanitize_attachments(&$attachments) { if (!is_array($attachments)) { return; } foreach ($attachments as $key => &$attachment) { if (is_array($attachment)) { sanitize_attachments($attachment); } if (preg_match('/(.*_url)|(src)/', $key)) { $attachments[$key] = sanitize_the_url($attachments[$key]); } } }
private function get_post($post, $params) { $attachments = array('images' => array(), 'videos' => array(), 'audio' => array()); $this->attachments =& $attachments; $is_user_logged_in = isset($params['session_id']); $include_raw_post = isset($params['include_raw_post']); $is_reqistration_required = '1' == get_option('comment_registration'); $remaped_post = $this->array_remap_keys($post, array('ID' => 'post_id', 'post_date_gmt' => 'published_at', 'post_title' => 'title', 'post_excerpt' => 'summary', 'post_content' => 'body', 'comment_status' => 'commentable', 'comment_count' => 'comments_count')); $post_categories = wp_get_post_categories($remaped_post['post_id']); $categories = array(); $tags = array(); foreach ($post_categories as $category) { $cat = get_category($category); $categories[] = array('id' => $cat->cat_ID, 'name' => $cat->name); } $remaped_post['categories'] = $categories; //*** ACTION shoutem_get_post_start ***// //Integration with external plugins will usually hook to this action to //substitute shortcodes or generate appropriate attachments from the content. //For example: @see ShoutemNGGDao, @see ShoutemFlaGalleryDao. do_action('shoutem_get_post_start', array('wp_post' => $post, 'attachments_ref' => &$attachments)); $body = apply_filters('the_content', do_shortcode($remaped_post['body'])); if ($include_raw_post) { $remaped_post['raw_post'] = $body; } $striped_attachments = array(); $remaped_post['body'] = sanitize_html($body, $striped_attachments); $user_data = get_userdata($post->post_author); $remaped_post['author'] = $user_data->display_name; $remaped_post['likeable'] = 0; $remaped_post['likes_count'] = 0; $remaped_post['link'] = get_permalink($remaped_post['post_id']); $this->include_leading_image_in_attachments($attachments, $post->ID); $attachments['images'] = array_merge($attachments['images'], $striped_attachments['images']); $attachments['videos'] = array_merge($attachments['videos'], $striped_attachments['videos']); $attachments['audio'] = array_merge($attachments['audio'], $striped_attachments['audio']); sanitize_attachments($attachments); $remaped_post['attachments'] = $attachments; $remaped_post['image_url'] = ''; $images = $attachments['images']; if (count($images) > 0) { $remaped_post['image_url'] = $images[0]['src']; } $post_commentable = $remaped_post['commentable'] == 'open'; if (!$this->options['enable_wp_commentable']) { $remaped_post['commentable'] = 'no'; } else { if (array_key_exists('commentable', $params)) { $remaped_post['commentable'] = $params['commentable']; } else { $remaped_post['commentable'] = $this->get_commentable($post_commentable, $is_user_logged_in, $is_reqistration_required); } } if ($this->options['enable_fb_commentable']) { $remaped_post['fb_commentable'] = 'yes'; } if (!$remaped_post['summary']) { $remaped_post['summary'] = wp_trim_excerpt(apply_filters('the_excerpt', get_the_excerpt())); $remaped_post['summary'] = html_to_text($remaped_post['summary']); } $remaped_post['title'] = html_to_text($remaped_post['title']); $remaped_posts[] = $remaped_post; return $remaped_post; }