public static function get($post_id = NULL) { $URI_ = array(); if ($post_id != NULL) { $meta_ = get_post_meta($post_id, '_thumbnail_id'); if (@count($meta_)) { foreach ($meta_ as $attachment_id) { $post_ = get_post($attachment_id); if (FeedValidator::isValidMediaURL($post_->guid, 'image')) { array_push($URI_, array('name' => $post_->post_title, 'uri' => $post_->guid)); } } } $images_ =& get_children(array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image')); if (!empty($images_)) { foreach ($images_ as $attachment_id => $attachment) { array_push($URI_, array('uri' => wp_get_attachment_url($attachment_id), 'name' => wp_get_attachment_image($attachment_id, 'thumbnail'))); } } } foreach ($URI_ as $img_) { $duplicate = 0; foreach ($URI_ as $i => $img_control_) { if ($img_['uri'] == $img_control_['uri']) { $duplicate++; if ($duplicate > 1) { $URI_ = array_slice($URI_, $i, 1); } } } } //dd( $URI_ ); return $URI_; }
/** * Extract images URL from a blog HTML content. * * @access public * @param String HTML content that can content fom <img /> XHTML element * @return Array Return an array of the images URL founds. */ public static function getMediaURLfromHTML($text = NULL) { $media_ = array(); if (strlen(trim($text)) > 0) { $tt = preg_match_all('/<(source|iframe|embed|param|img)[^>]+src=[\'"]([^\'"]+)[\'"].*>/i', str_replace('><', '> <', FeedValidator::removeBreaklines($text, ' ')), $matches); if ($tt > 0 && count($matches[2]) > 0) { foreach ($matches[2] as $i => $value) { $sb1 = array(); $sb2 = array(); $sb3 = array(); $sb4 = array(); if (FeedValidator::isValidURL($value)) { $simple_tag = str_replace("'", "\"", strtolower(stripcslashes($matches[0][$i]))); $sb1 = explode('title="', $simple_tag); if (count($sb1) > 1) { $sb3 = explode('"', $sb1[1]); } $sb2 = explode('alt="', $simple_tag); if (count($sb2) > 1) { $sb4 = explode('"', $sb2[1]); } $media_type = FeedValidator::getMediaType($value); array_push($media_, array('uri' => $value, 'type' => $media_type, 'name' => isset($sb3[0]) ? $sb3[0] : (isset($sb4[0]) ? $sb4[0] : $media_type . " - " . $i))); } } } // Strip HTML content and analyzed individual world to find URL in the text. (CF: MediaWiki content). $text_split = explode(' ', FeedValidator::getOnlyText($text, self::CHARSET)); if (count($text_split) > 0) { foreach ($text_split as $value) { foreach (array('image', 'sound', 'video') as $media_type) { if (FeedValidator::isValidURL($value)) { if (FeedValidator::isValidMediaURL($value, $media_type)) { if (!in_array($value, $media_)) { array_push($media_, array('uri' => $value, 'type' => $media_type, 'name' => $media_type)); } } } } } } } return $media_; }