本文整理汇总了PHP中Jetpack_PostImages::from_html方法的典型用法代码示例。如果您正苦于以下问题:PHP Jetpack_PostImages::from_html方法的具体用法?PHP Jetpack_PostImages::from_html怎么用?PHP Jetpack_PostImages::from_html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jetpack_PostImages
的用法示例。
在下文中一共展示了Jetpack_PostImages::from_html方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_from_html_double_quotes
/**
* @author blobaugh
* @covers Jetpack_PostImages::from_html
* @since 2.7
*/
public function test_from_html_double_quotes()
{
$s = "<imgANYTHINGATALLHEREsrc='bob.jpg'MOREANYTHINGHERE/>";
$result = Jetpack_PostImages::from_html($s);
$this->assertInternalType('array', $result);
$this->assertFalse(empty($result));
}
示例2: get_images_from_html
/**
*
* @param string $html Some markup, possibly containing image tags
* @param array $images_already_extracted (just an array of image URLs without query strings, no special structure), used for de-duplication
* @return array Image URLs extracted from the HTML, stripped of query params and de-duped
*/
public static function get_images_from_html($html, $images_already_extracted)
{
$image_list = $images_already_extracted;
$from_html = Jetpack_PostImages::from_html($html);
if (!empty($from_html)) {
$srcs = wp_list_pluck($from_html, 'src');
foreach ($srcs as $image_url) {
if (($src = parse_url($image_url)) && isset($src['scheme'], $src['host'], $src['path'])) {
// Rebuild the URL without the query string
$queryless = $src['scheme'] . '://' . $src['host'] . $src['path'];
} elseif ($length = strpos($image_url, '?')) {
// If parse_url() didn't work, strip off theh query string the old fashioned way
$queryless = substr($image_url, 0, $length);
} else {
// Failing that, there was no spoon! Err ... query string!
$queryless = $image_url;
}
if (!in_array($queryless, $image_list)) {
$image_list[] = $queryless;
}
}
}
return $image_list;
}
示例3: spun_get_image
/**
* Get one image from a specified post in the following order:
* Featured Image, first attached image, first image from the_content HTML
* @param int $id, The post ID to check
* @param string $size, The image size to return, defaults to 'post-thumbnail'
* @return string $thumb, Thumbnail image with markup
*/
function spun_get_image($id, $size = 'home-post')
{
$thumb = '';
if ('' != get_the_post_thumbnail($id)) {
$thumb = get_the_post_thumbnail($id, $size, array('title' => esc_attr(strip_tags(get_the_title()))));
} else {
$args = array('post_type' => 'attachment', 'fields' => 'ids', 'numberposts' => 1, 'post_status' => null, 'post_mime_type' => 'image', 'post_parent' => $id);
$first_attachment = get_posts($args);
if ($first_attachment) {
/* Get the first image attachment */
foreach ($first_attachment as $attachment) {
$thumb = wp_get_attachment_image($attachment, $size, false, array('title' => esc_attr(strip_tags(get_the_title()))));
}
} elseif (class_exists('Jetpack_PostImages')) {
/* Get the first image directly from HTML content */
$getimage = new Jetpack_PostImages();
$image = $getimage->from_html($id);
if ($image) {
$thumb = '<img src="' . $image[0]['src'] . '" title="' . esc_attr(strip_tags(get_the_title())) . '" class="attachment-' . $size . ' wp-post-image" />';
}
}
}
return $thumb;
}
示例4: get_post_image
public function get_post_image($content)
{
$image = '';
if (class_exists('Jetpack_PostImages')) {
global $post;
$img = Jetpack_PostImages::from_html($post->ID);
if (!empty($img['src'])) {
return $img['src'];
}
}
if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
$thumb_id = get_post_thumbnail_id();
$thumb = wp_get_attachment_image_src($thumb_id, 'full');
// This shouldn't be necessary, since has_post_thumbnail() is true,
// but... see http://wordpress.org/support/topic/jetpack-youtube-embeds
if (!$thumb) {
return '';
}
$image = remove_query_arg(array('w', 'h'), $thumb[0]);
} else {
if (preg_match_all('/<img (.+?)>/', $content, $matches)) {
foreach ($matches[1] as $attrs) {
$media = $img = array();
foreach (wp_kses_hair($attrs, array('http', 'https')) as $attr) {
$img[$attr['name']] = $attr['value'];
}
if (!isset($img['src']) || 0 !== strpos($img['src'], 'http')) {
continue;
} else {
$image = htmlspecialchars_decode($img['src']);
break;
}
}
}
}
return $image;
}