当前位置: 首页>>代码示例>>PHP>>正文


PHP Jetpack_PostImages::get_images方法代码示例

本文整理汇总了PHP中Jetpack_PostImages::get_images方法的典型用法代码示例。如果您正苦于以下问题:PHP Jetpack_PostImages::get_images方法的具体用法?PHP Jetpack_PostImages::get_images怎么用?PHP Jetpack_PostImages::get_images使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Jetpack_PostImages的用法示例。


在下文中一共展示了Jetpack_PostImages::get_images方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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 = '';
        // Grab obvious image if $post is an attachment page for an image
        if (is_attachment($post->ID) && 'image' == substr($post->post_mime_type, 0, 5)) {
            $image = wp_get_attachment_url($post->ID);
        }
        // Attempt to find something good for this post using our generalized PostImages code
        if (!$image && 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['src'] = $post_image['src'];
                    if (isset($post_image['src_width'], $post_image['src_height'])) {
                        $image['width'] = $post_image['src_width'];
                        $image['height'] = $post_image['src_height'];
                    }
                }
            }
        }
    } 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['src'] = 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['src'] = wp_specialchars_decode($matches[1], ENT_QUOTES);
                }
            }
        }
    }
    if (empty($image)) {
        $image = array();
    } else {
        if (!is_array($image)) {
            $image = array('src' => $image);
        }
    }
    // First fall back, blavatar
    if (empty($image) && function_exists('blavatar_domain')) {
        $blavatar_domain = blavatar_domain(site_url());
        if (blavatar_exists($blavatar_domain)) {
            $image['src'] = blavatar_url($blavatar_domain, 'img', $width, false, true);
            $image['width'] = $width;
            $image['height'] = $height;
        }
    }
    // Second fall back, Site Logo
    if (empty($image) && (function_exists('jetpack_has_site_logo') && jetpack_has_site_logo())) {
        $image['src'] = jetpack_get_site_logo('url');
        $image_dimensions = jetpack_get_site_logo_dimensions();
        if (!empty($image_dimensions)) {
            $image['width'] = $image_dimensions['width'];
            $image['height'] = $image_dimensions['height'];
        }
    }
    // Third fall back, Site Icon
    if (empty($image) && (function_exists('jetpack_has_site_icon') && jetpack_has_site_icon())) {
        $image['src'] = jetpack_site_icon_url(null, '512');
        $image['width'] = '512';
        $image['height'] = '512';
    }
    // Fourth fall back, Core Site Icon. Added in WP 4.3.
    if (empty($image) && (function_exists('has_site_icon') && has_site_icon())) {
        $image['src'] = get_site_icon_url(null, '512');
    }
    // Finally fall back, blank image
    if (empty($image)) {
        /**
         * Filter the default Open Graph Image tag, used when no Image can be found in a post.
         *
         * @since 3.0.0
         *
         * @param string $str Default Image URL.
         */
        $image['src'] = apply_filters('jetpack_open_graph_image_default', 'https://s0.wp.com/i/blank.jpg');
    }
    return $image;
}
开发者ID:originallurch,项目名称:elderfinlayson.com,代码行数:96,代码来源:functions.opengraph.php

示例2: jetpack_print_sitemap

/**
 * Print an XML sitemap conforming to the Sitemaps.org protocol.
 * Outputs an XML list of up to the latest 1000 posts.
 *
 * @module sitemaps
 *
 * @link http://sitemaps.org/protocol.php Sitemaps.org protocol.
 */
function jetpack_print_sitemap()
{
    global $wpdb, $post;
    $xml = get_transient('jetpack_sitemap');
    if ($xml) {
        header('Content-Type: ' . jetpack_sitemap_content_type(), true);
        echo $xml;
        die;
    }
    // Compatibility with PHP 5.3 and older
    if (!defined('ENT_XML1')) {
        define('ENT_XML1', 16);
    }
    /**
     * Filter the post types that will be included in sitemap.
     *
     * @module sitemaps
     *
     * @since 3.9.0
     *
     * @param array $post_types Array of post types.
     */
    $post_types = apply_filters('jetpack_sitemap_post_types', array('post', 'page'));
    $post_types_in = array();
    foreach ((array) $post_types as $post_type) {
        $post_types_in[] = $wpdb->prepare('%s', $post_type);
    }
    $post_types_in = join(",", $post_types_in);
    // use direct query instead because get_posts was acting too heavy for our needs
    //$posts = get_posts( array( 'numberposts'=>1000, 'post_type'=>$post_types, 'post_status'=>'published' ) );
    $posts = $wpdb->get_results("SELECT ID, post_type, post_modified_gmt, comment_count FROM {$wpdb->posts} WHERE post_status='publish' AND post_type IN ({$post_types_in}) ORDER BY post_modified_gmt DESC LIMIT 1000");
    if (empty($posts)) {
        status_header(404);
    }
    header('Content-Type: ' . jetpack_sitemap_content_type());
    $initstr = jetpack_sitemap_initstr(get_bloginfo('charset'));
    $tree = simplexml_load_string($initstr);
    // If we did not get a valid string, force UTF-8 and try again.
    if (false === $tree) {
        $initstr = jetpack_sitemap_initstr('UTF-8');
        $tree = simplexml_load_string($initstr);
    }
    unset($initstr);
    $latest_mod = '';
    foreach ($posts as $post) {
        setup_postdata($post);
        /**
         * Filter condition to allow skipping specific posts in 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_skip_post', false, $post)) {
            continue;
        }
        $post_latest_mod = null;
        $url = array('loc' => esc_url(get_permalink($post->ID)));
        // If this post is configured to be the site home, skip since it's added separately later
        if (untrailingslashit(get_permalink($post->ID)) == untrailingslashit(get_option('home'))) {
            continue;
        }
        // Mobile node specified in http://support.google.com/webmasters/bin/answer.py?hl=en&answer=34648
        $url['mobile:mobile'] = '';
        // Image node specified in http://support.google.com/webmasters/bin/answer.py?hl=en&answer=178636
        // These attachments were produced with batch SQL earlier in the script
        if (!post_password_required($post->ID)) {
            $media = array();
            $methods = array('from_thumbnail' => false, 'from_slideshow' => false, 'from_gallery' => false, 'from_attachment' => false, 'from_html' => false);
            foreach ($methods as $method => $value) {
                $methods[$method] = true;
                $images_collected = Jetpack_PostImages::get_images($post->ID, $methods);
                if (is_array($images_collected)) {
                    $media = array_merge($media, $images_collected);
                }
                $methods[$method] = false;
            }
            $images = array();
            foreach ($media as $item) {
                if (!isset($item['type']) || 'image' != $item['type']) {
                    continue;
                }
                $one_image = array();
                if (isset($item['src'])) {
                    $one_image['image:loc'] = esc_url($item['src']);
                    $one_image['image:title'] = sanitize_title_with_dashes($name = pathinfo($item['src'], PATHINFO_FILENAME));
                }
                $images[] = $one_image;
            }
//.........这里部分代码省略.........
开发者ID:kanei,项目名称:vantuch.cz,代码行数:101,代码来源:sitemaps.php

示例3: 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;
}
开发者ID:briancompton,项目名称:knightsplaza,代码行数:55,代码来源:functions.opengraph.php

示例4: 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;
}
开发者ID:dtekcth,项目名称:datateknologer.se,代码行数:68,代码来源:functions.opengraph.php


注:本文中的Jetpack_PostImages::get_images方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。