本文整理汇总了PHP中Jetpack_PostImages类的典型用法代码示例。如果您正苦于以下问题:PHP Jetpack_PostImages类的具体用法?PHP Jetpack_PostImages怎么用?PHP Jetpack_PostImages使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Jetpack_PostImages类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_from_attachment_is_correct_array
/**
* @author scotchfield
* @covers Jetpack_PostImages::from_attachment
* @since 3.2
*/
public function test_from_attachment_is_correct_array()
{
$img_name = 'image.jpg';
$img_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $img_name;
$img_html = '<img src="' . $img_url . '"/>';
$img_dimensions = array('width' => 250, 'height' => 250);
$post_id = $this->factory->post->create(array('post_content' => $img_html));
$attachment_id = $this->factory->attachment->create_object($img_name, $post_id, array('post_mime_type' => 'image/jpeg', 'post_type' => 'attachment'));
wp_update_attachment_metadata($attachment_id, $img_dimensions);
$images = Jetpack_PostImages::from_attachment($post_id);
$this->assertEquals(count($images), 1);
$this->assertEquals($images[0]['src'], $img_url);
}
示例2: colorposts_get_post_image
/**
* Get an image from a post
*
* @uses Jetpack_PostImages::get_image( $post_id ) to get the source of an image in a post, apply_filters()
*
* @since 1.0
*
* @return string $the_image the image source
*/
function colorposts_get_post_image()
{
$post_id = get_the_ID();
if (class_exists('Jetpack_PostImages')) {
$the_image = Jetpack_PostImages::get_image($post_id);
if (!empty($the_image['src'])) {
$the_image = $the_image['src'];
} else {
$the_image = apply_filters('jetpack_open_graph_image_default', "http://wordpress.com/i/blank.jpg");
}
}
$the_image = apply_filters('colorposts_image_output', $the_image);
return esc_url($the_image);
}
示例3: wpcom_amp_add_image_to_metadata
function wpcom_amp_add_image_to_metadata($metadata, $post)
{
if (!class_exists('Jetpack_PostImages')) {
return wpcom_amp_add_fallback_image_to_metadata($metadata);
}
$image = Jetpack_PostImages::get_image($post->ID, array('fallback_to_avatars' => true, 'avatar_size' => 200, 'from_thumbnail' => false, 'from_attachment' => false));
if (empty($image)) {
return wpcom_amp_add_fallback_image_to_metadata($metadata);
}
if (!isset($image['src_width'])) {
$dimensions = wpcom_amp_getimagesize($image['src']);
if ($dimensions) {
$image['src_width'] = $dimensions[0];
$image['src_height'] = $dimensions[1];
}
}
$metadata['image'] = array('@type' => 'ImageObject', 'url' => $image['src'], 'width' => $image['src_width'], 'height' => $image['src_height']);
return $metadata;
}
示例4: 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;
}
示例5: widget
function widget($args, $instance)
{
$title = isset($instance['title']) ? $instance['title'] : false;
if (false === $title) {
$title = $this->default_title;
}
$title = apply_filters('widget_title', $title);
$count = isset($instance['count']) ? (int) $instance['count'] : false;
if ($count < 1 || 20 < $count) {
$count = 10;
}
if (isset($instance['display']) && in_array($instance['display'], array('grid', 'list', 'text'))) {
$display = $instance['display'];
} else {
$display = 'text';
}
if ('text' != $display) {
$get_image_options = array('fallback_to_avatars' => true, 'gravatar_default' => apply_filters('jetpack_static_url', is_ssl() ? 'https' : 'http' . '://en.wordpress.com/i/logo/white-gray-80.png'));
if ('grid' == $display) {
if ($count % 2 != 0) {
$count++;
}
$get_image_options['avatar_size'] = 200;
} else {
$get_image_options['avatar_size'] = 40;
}
$get_image_options = apply_filters('jetpack_top_posts_widget_image_options', $get_image_options);
}
$posts = $this->get_by_views($count);
if (!$posts) {
$posts = $this->get_fallback_posts();
}
echo $args['before_widget'];
if (!empty($title)) {
echo $args['before_title'] . $title . $args['after_title'];
}
if (!$posts) {
if (current_user_can('edit_theme_options')) {
echo '<p>' . sprintf(__('There are no posts to display. <a href="%s">Want more traffic?</a>', 'jetpack'), 'http://en.support.wordpress.com/getting-more-site-traffic/') . '</p>';
}
echo $args['after_widget'];
return;
}
switch ($display) {
case 'list':
case 'grid':
wp_enqueue_style('widget-grid-and-list');
foreach ($posts as &$post) {
$image = Jetpack_PostImages::get_image($post['post_id']);
$post['image'] = $image['src'];
if ('blavatar' != $image['from'] && 'gravatar' != $image['from']) {
$size = (int) $get_image_options['avatar_size'];
$post['image'] = jetpack_photon_url($post['image'], array('resize' => "{$size},{$size}"));
}
}
unset($post);
if ('grid' == $display) {
echo "<div class='widgets-grid-layout no-grav'>\n";
foreach ($posts as $post) {
?>
<div class="widget-grid-view-image">
<a href="<?php
echo esc_url($post['permalink']);
?>
" title="<?php
echo esc_attr(wp_kses($post['title'], array()));
?>
" class="bump-view" data-bump-view="tp"><img src="<?php
echo esc_url($post['image']);
?>
" /></a>
</div>
<?php
}
echo "</div>\n";
} else {
echo "<ul class='widgets-list-layout no-grav'>\n";
foreach ($posts as $post) {
?>
<li>
<img src="<?php
echo esc_url($post['image']);
?>
" class='widgets-list-layout-blavatar' />
<div class="widgets-list-layout-links"><a href="<?php
echo esc_url($post['permalink']);
?>
" class="bump-view" data-bump-view="tp"><?php
echo esc_html(wp_kses($post['title'], array()));
?>
</a></div>
</li>
<?php
}
echo "</ul>\n";
}
break;
default:
echo '<ul>';
//.........这里部分代码省略.........
示例6: twitter_cards_tags
static function twitter_cards_tags($og_tags)
{
global $post;
if (post_password_required()) {
return $og_tags;
}
if (apply_filters('jetpack_disable_twitter_cards', false)) {
return $og_tags;
}
/*
* These tags apply to any page (home, archives, etc)
*/
$site_tag = apply_filters('jetpack_twitter_cards_site_tag', self::site_tag());
$og_tags['twitter:site'] = self::sanitize_twitter_user($site_tag);
if (!is_singular() || !empty($og_tags['twitter:card'])) {
return $og_tags;
}
/*
* The following tags only apply to single pages.
*/
$card_type = 'summary';
// Try to give priority to featured images
if (class_exists('Jetpack_PostImages')) {
$featured = Jetpack_PostImages::from_thumbnail($post->ID, 240, 240);
if (!empty($featured) && count($featured) > 0) {
if ((int) $featured[0]['src_width'] >= 280 && (int) $featured[0]['src_height'] >= 150) {
$card_type = 'summary_large_image';
$og_tags['twitter:image:src'] = add_query_arg('w', 640, $featured[0]['src']);
} else {
$og_tags['twitter:image'] = add_query_arg('w', 240, $featured[0]['src']);
}
}
}
// Only proceed with media analysis if a featured image has not superseded it already.
if (empty($og_tags['twitter:image']) && empty($og_tags['twitter:image:src'])) {
if (!class_exists('Jetpack_Media_Summary') && defined('IS_WPCOM') && IS_WPCOM) {
include WP_CONTENT_DIR . '/lib/class.wpcom-media-summary.php';
}
// Test again, class should already be auto-loaded in Jetpack.
// If not, skip extra media analysis and stick with a summary card
if (class_exists('Jetpack_Media_Summary')) {
$extract = Jetpack_Media_Summary::get($post->ID);
if ('gallery' == $extract['type']) {
list($og_tags, $card_type) = self::twitter_cards_define_type_based_on_image_count($og_tags, $extract);
} else {
if ('video' == $extract['type']) {
// Leave as summary, but with large pict of poster frame (we know those comply to Twitter's size requirements)
$card_type = 'summary_large_image';
$og_tags['twitter:image:src'] = add_query_arg('w', 640, $extract['image']);
} else {
list($og_tags, $card_type) = self::twitter_cards_define_type_based_on_image_count($og_tags, $extract);
}
}
}
}
$og_tags['twitter:card'] = $card_type;
// If we have information on the author/creator, then include that as well
if (!empty($post) && !empty($post->post_author)) {
$handle = apply_filters('jetpack_sharing_twitter_via', '', $post->ID);
if (!empty($handle) && 'wordpressdotcom' != $handle && 'jetpack' != $handle) {
$og_tags['twitter:creator'] = self::sanitize_twitter_user($handle);
}
}
// Make sure we have a description for Twitter, their validator isn't happy without some content (single space not valid).
if (!isset($og_tags['og:description']) || '' == trim($og_tags['og:description']) || __('Visit the post for more.', 'jetpack') == $og_tags['og:description']) {
// empty( trim( $og_tags['og:description'] ) ) isn't valid php
$has_creator = !empty($og_tags['twitter:creator']) && '@wordpressdotcom' != $og_tags['twitter:creator'] ? true : false;
if ('photo' == $card_type) {
$og_tags['twitter:description'] = $has_creator ? sprintf(__('Photo post by %s.', 'jetpack'), $og_tags['twitter:creator']) : __('Photo post.', 'jetpack');
} else {
if (!empty($extract) && 'video' == $extract['type']) {
// use $extract['type'] since $card_type is 'summary' for video posts
$og_tags['twitter:description'] = $has_creator ? sprintf(__('Video post by %s.', 'jetpack'), $og_tags['twitter:creator']) : __('Video post.', 'jetpack');
} else {
if ('gallery' == $card_type) {
$og_tags['twitter:description'] = $has_creator ? sprintf(__('Gallery post by %s.', 'jetpack'), $og_tags['twitter:creator']) : __('Gallery post.', 'jetpack');
} else {
$og_tags['twitter:description'] = $has_creator ? sprintf(__('Post by %s.', 'jetpack'), $og_tags['twitter:creator']) : __('Visit the post for more.', 'jetpack');
}
}
}
}
return $og_tags;
}
示例7: jetpack_print_news_sitemap
//.........这里部分代码省略.........
$post_types_in[] = $wpdb->prepare('%s', $post_type);
}
$post_types_in_string = implode(', ', $post_types_in);
/**
* Filter limit of entries to include in news sitemap.
*
* @module sitemaps
*
* @since 3.9.0
*
* @param int $count Number of entries to include in news sitemap.
*/
$limit = apply_filters('jetpack_sitemap_news_sitemap_count', 1000);
$cur_datetime = current_time('mysql', true);
$query = $wpdb->prepare("\n\t\tSELECT p.ID, p.post_title, p.post_type, p.post_date, p.post_name, p.post_date_gmt, GROUP_CONCAT(t.name SEPARATOR ', ') AS keywords\n\t\tFROM\n\t\t\t{$wpdb->posts} AS p LEFT JOIN {$wpdb->term_relationships} AS r ON p.ID = r.object_id\n\t\t\tLEFT JOIN {$wpdb->term_taxonomy} AS tt ON r.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'post_tag'\n\t\t\tLEFT JOIN {$wpdb->terms} AS t ON tt.term_id = t.term_id\n\t\tWHERE\n\t\t\tpost_status='publish' AND post_type IN ( {$post_types_in_string} ) AND post_date_gmt > (%s - INTERVAL 2 DAY)\n\t\tGROUP BY p.ID\n\t\tORDER BY p.post_date_gmt DESC LIMIT %d", $cur_datetime, $limit);
// URL to XSLT
$xsl = get_option('permalink_structure') ? home_url('news-sitemap.xsl') : home_url('/?jetpack-news-sitemap-xsl=true');
// Unless it's zh-cn for Simplified Chinese or zh-tw for Traditional Chinese,
// trim national variety so an ISO 639 language code as required by Google.
$language_code = strtolower(get_locale());
if (in_array($language_code, array('zh_tw', 'zh_cn'))) {
$language_code = str_replace('_', '-', $language_code);
} else {
$language_code = preg_replace('/(_.*)$/i', '', $language_code);
}
header('Content-Type: application/xml');
ob_start();
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<?xml-stylesheet type="text/xsl" href="' . esc_url($xsl) . '"?>' . "\n";
echo '<!-- generator="jetpack-' . JETPACK__VERSION . '" -->' . "\n";
?>
<!-- generator="jetpack" -->
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
>
<?php
$posts = $wpdb->get_results($query);
foreach ($posts as $post) {
setup_postdata($post);
/**
* Filter condition to allow skipping specific posts in news sitemap.
*
* @module sitemaps
*
* @since 3.9.0
*
* @param bool $skip Current boolean. False by default, so no post is skipped.
* @param WP_POST $post Current post object.
*/
if (apply_filters('jetpack_sitemap_news_skip_post', false, $post)) {
continue;
}
$GLOBALS['post'] = $post;
$url = array();
$url['loc'] = get_permalink($post->ID);
$news = array();
$news['news:publication']['news:name'] = get_bloginfo_rss('name');
$news['news:publication']['news:language'] = $language_code;
$news['news:publication_date'] = jetpack_w3cdate_from_mysql($post->post_date_gmt);
$news['news:title'] = get_the_title_rss();
if ($post->keywords) {
$news['news:keywords'] = html_entity_decode(ent2ncr($post->keywords), ENT_HTML5);
}
$url['news:news'] = $news;
// Add image to sitemap
$post_thumbnail = Jetpack_PostImages::get_image($post->ID);
if (isset($post_thumbnail['src'])) {
$url['image:image'] = array('image:loc' => esc_url($post_thumbnail['src']));
}
/**
* Filter associative array with data to build <url> node and its descendants for current post in news sitemap.
*
* @module sitemaps
*
* @since 3.9.0
*
* @param array $url Data to build parent and children nodes for current post.
* @param int $post_id Current post ID.
*/
$url = apply_filters('jetpack_sitemap_news_sitemap_item', $url, $post);
if (empty($url)) {
continue;
}
jetpack_print_sitemap_item($url);
}
wp_reset_postdata();
?>
</urlset>
<?php
$xml = ob_get_contents();
ob_end_clean();
if (!empty($xml)) {
set_transient('jetpack_news_sitemap', $xml, DAY_IN_SECONDS);
echo $xml;
}
die;
}
示例8: jetpack_og_get_image
function jetpack_og_get_image($width = 200, $height = 200, $max_images = 4)
{
// Facebook requires thumbnails to be a minimum of 200x200
$image = '';
if (is_singular() && !is_home() && !is_front_page()) {
global $post;
$image = '';
// Attempt to find something good for this post using our generalized PostImages code
if (class_exists('Jetpack_PostImages')) {
$post_images = Jetpack_PostImages::get_images($post->ID, array('width' => $width, 'height' => $height));
if ($post_images && !is_wp_error($post_images)) {
$image = array();
foreach ((array) $post_images as $post_image) {
$image[] = $post_image['src'];
}
}
}
} else {
if (is_author()) {
$author = get_queried_object();
if (function_exists('get_avatar_url')) {
$avatar = get_avatar_url($author->user_email, $width);
if (!empty($avatar)) {
if (is_array($avatar)) {
$image = $avatar[0];
} else {
$image = $avatar;
}
}
} else {
$has_filter = has_filter('pre_option_show_avatars', '__return_true');
if (!$has_filter) {
add_filter('pre_option_show_avatars', '__return_true');
}
$avatar = get_avatar($author->user_email, $width);
if (!$has_filter) {
remove_filter('pre_option_show_avatars', '__return_true');
}
if (!empty($avatar) && !is_wp_error($avatar)) {
if (preg_match('/src=["\']([^"\']+)["\']/', $avatar, $matches)) {
}
$image = wp_specialchars_decode($matches[1], ENT_QUOTES);
}
}
}
}
// Fallback to Blavatar if available
if (function_exists('blavatar_domain')) {
$blavatar_domain = blavatar_domain(site_url());
if (empty($image) && blavatar_exists($blavatar_domain)) {
$image = blavatar_url($blavatar_domain, 'img', $width);
}
}
return $image;
}
示例9: 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;
}
示例10: enhanced_og_has_featured_image
function enhanced_og_has_featured_image($post_id)
{
$featured = Jetpack_PostImages::from_thumbnail($post_id, 200, 200);
if (!empty($featured) && count($featured) > 0) {
return true;
}
return false;
}
示例11: jetpack_og_get_image
function jetpack_og_get_image($width = 200, $height = 200, $max_images = 4)
{
// Facebook requires thumbnails to be a minimum of 200x200
$image = '';
if (is_singular() && !is_home()) {
global $post;
$image = '';
// Attempt to find something good for this post using our generalized PostImages code
if (class_exists('Jetpack_PostImages')) {
$post_images = Jetpack_PostImages::get_images($post->ID, array('width' => $width, 'height' => $height));
if ($post_images && !is_wp_error($post_images)) {
$image = array();
foreach ((array) $post_images as $post_image) {
$image[] = $post_image['src'];
}
}
}
} else {
if (is_author()) {
$author = get_queried_object();
if (function_exists('get_avatar_url')) {
// Prefer the core function get_avatar_url() if available, WP 4.2+
$image = get_avatar_url($author->user_email, array('size' => $width));
} else {
$has_filter = has_filter('pre_option_show_avatars', '__return_true');
if (!$has_filter) {
add_filter('pre_option_show_avatars', '__return_true');
}
$avatar = get_avatar($author->user_email, $width);
if (!$has_filter) {
remove_filter('pre_option_show_avatars', '__return_true');
}
if (!empty($avatar) && !is_wp_error($avatar)) {
if (preg_match('/src=["\']([^"\']+)["\']/', $avatar, $matches)) {
}
$image = wp_specialchars_decode($matches[1], ENT_QUOTES);
}
}
}
}
if (empty($image)) {
$image = array();
} else {
if (!is_array($image)) {
$image = array($image);
}
}
// First fall back, blavatar
if (empty($image) && function_exists('blavatar_domain')) {
$blavatar_domain = blavatar_domain(site_url());
if (blavatar_exists($blavatar_domain)) {
$image[] = blavatar_url($blavatar_domain, 'img', $width);
}
}
// Second fall back, Site Logo
if (empty($image) && (function_exists('jetpack_has_site_logo') && jetpack_has_site_logo())) {
$image[] = jetpack_get_site_logo('url');
}
// Third fall back, Site Icon
if (empty($image) && (function_exists('jetpack_has_site_icon') && jetpack_has_site_icon())) {
$image[] = jetpack_site_icon_url(null, '512');
}
// Fourth fall back, blank image
if (empty($image)) {
$image[] = apply_filters('jetpack_open_graph_image_default', 'https://s0.wp.com/i/blank.jpg');
}
return $image;
}
示例12: get_image_url
/**
* Retrieve the image URL for a post.
*
* @since 3.1.0
*
* @see Cedaro_Theme_PostMedia::get_image()
* @todo Refactor to remove dependence on Cedaro_Theme_PostMedia::get_image()
*
* @param int|WP_Post $post Optional. Post ID or object. Defaults to the current post.
* @param string|array $size Optional. The size of the image to return. Defaults to large.
* @return string Image URL.
*/
public function get_image_url($post = 0, $size = 'large')
{
$post = get_post($post);
$url = $this->get_image_url_from_cache($post, $size);
if (null !== $url) {
return apply_filters($this->theme->prefix . '_post_image_url', $url, $post);
}
// Check for a featured image first.
if (has_post_thumbnail($post->ID)) {
$data = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $size);
$url = $data[0];
} elseif (class_exists('Jetpack_PostImages') && ($data = Jetpack_PostImages::get_image($post->ID))) {
$url = $data['src'];
} elseif (!class_exists('Jetpack_PostImages')) {
// Check the post content for an image.
$html = $this->get_image_in_content($post->post_content);
if (!empty($html) && preg_match('/src=[\'"]([^\'"]+)/', $html, $matches)) {
$url = $matches[1];
} else {
// Check the post's attachments.
$images = get_posts(array('post_type' => 'attachment', 'post_parent' => $post->ID, 'post_mime_type' => 'image', 'posts_per_page' => 1, 'fields' => 'ids', 'orderby' => 'menu_order', 'order' => 'asc'));
if (count($images)) {
$data = wp_get_attachment_image_src($images[0], $size);
$url = $data[0];
}
}
}
$this->cache_image_url($post, $size, $url);
return apply_filters($this->theme->prefix . '_post_image_url', $url, $post);
}
示例13: 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;
}
示例14: get_image
public function get_image($post)
{
if (class_exists('Jetpack_PostImages')) {
$image = Jetpack_PostImages::get_image($post->ID, array('fallback_to_avatars' => true));
if (!empty($image)) {
return $image['src'];
}
}
/**
* Filters the default image used by the Pinterest Pin It share button.
*
* @module sharedaddy
*
* @since 3.6.0
*
* @param string $url Default image URL.
*/
return apply_filters('jetpack_sharing_pinterest_default_image', 'https://s0.wp.com/i/blank.jpg');
}
示例15: get_post_image
public function get_post_image($content)
{
$image = '';
if (class_exists('Jetpack_PostImages')) {
// Use the full stack of methods to find an image, except for HTML, which can cause loops
$img = Jetpack_PostImages::get_image($content->ID);
if (!empty($img['src'])) {
return $img['src'];
}
}
// If we have to fall back to the following, we only do a few basic image checks
$content = $content->post_content;
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;
}