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


PHP WP_oEmbed::get_provider方法代码示例

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


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

示例1: get_data

 public function get_data($url = '', $args = '')
 {
     if ($url) {
         $this->url = $url;
     }
     if (!$this->url) {
         return false;
     }
     //if it was already fetched
     if ($this->data) {
         return $this->data;
     }
     $provider = self::$oembed->get_provider($this->url, $args);
     if (!$provider) {
         return false;
     }
     $data = self::$oembed->fetch($provider, $this->url, $args);
     if (!$data) {
         return false;
     }
     $this->data = $data;
     return $this->data;
 }
开发者ID:markc,项目名称:mediapress,代码行数:23,代码来源:class-mpp-oembed.php

示例2: instant_articles_embed_oembed_html

/**
 * Filter the oembed results to see if we should do some extra handling
 *
 * @since 0.1
 * @param string $html     The original HTML returned from the external oembed provider.
 * @param string $url      The URL found in the content.
 * @param mixed  $attr     An array with extra attributes.
 * @param int    $post_id  The post ID.
 * @return string The potentially filtered HTML.
 */
function instant_articles_embed_oembed_html($html, $url, $attr, $post_id)
{
    if (!class_exists('WP_oEmbed')) {
        include_once ABSPATH . WPINC . '/class-oembed.php';
    }
    // Instead of checking all possible URL variants, use the provider list from WP_oEmbed.
    $wp_oembed = new WP_oEmbed();
    $provider_url = $wp_oembed->get_provider($url);
    $provider_name = false;
    if (false !== strpos($provider_url, 'instagram.com')) {
        $provider_name = 'instagram';
    } elseif (false !== strpos($provider_url, 'twitter.com')) {
        $provider_name = 'twitter';
    } elseif (false !== strpos($provider_url, 'youtube.com')) {
        $provider_name = 'youtube';
    } elseif (false !== strpos($provider_url, 'vine.co')) {
        $provider_name = 'vine';
    }
    $provider_name = apply_filters('instant_articles_social_embed_type', $provider_name, $url);
    if ($provider_name) {
        $html = instant_articles_embed_get_html($provider_name, $html, $url, $attr, $post_id);
    }
    return $html;
}
开发者ID:ActiveWebsite,项目名称:BoojPressPlugins,代码行数:34,代码来源:embeds.php

示例3: uncode_admin_get_oembed

function uncode_admin_get_oembed()
{
    $code = $mime = '';
    $width = 1;
    $height = 1;
    $urlEnterd = isset($_REQUEST['urlOembed']) ? urldecode($_REQUEST['urlOembed']) : die;
    $onlycode = isset($_REQUEST['onlycode']) ? $_REQUEST['onlycode'] : false;
    $urlEnterd = str_replace('https://instagram.com', 'http://instagram.com', $urlEnterd);
    $WP_oembed = new WP_oEmbed();
    $raw_provider = parse_url($WP_oembed->get_provider($urlEnterd));
    if (isset($raw_provider['host'])) {
        $host = $raw_provider['host'];
        $strip = array("www.", "api.", "embed.");
        $bare_host = str_replace($strip, "", $host);
        $bare_host = explode('.', $bare_host);
        $mime = 'oembed/' . $bare_host[0];
        $code = wp_oembed_get($urlEnterd);
        preg_match_all('/(width|height)=("[^"]*")/i', $code, $img_attr);
        if (isset($img_attr[2][0])) {
            $width = preg_replace('/\\D/', '', $img_attr[2][0]);
        }
        if (isset($img_attr[2][1])) {
            $height = preg_replace('/\\D/', '', $img_attr[2][1]);
        }
        if ($bare_host[0] === 'youtube') {
            $parts = parse_url($urlEnterd);
            if (isset($parts['query'])) {
                parse_str($parts['query'], $query);
                $idvideo = $query['v'];
            } else {
                $idvideo = $parts['path'];
                $idvideo = str_replace('/', '', $idvideo);
            }
            $data = wp_remote_fopen("https://www.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails&id=" . $idvideo . "&key=AIzaSyA9PEtdNGSwzuM8QtaDbZvkcSlkh_UG2HI");
            $json = json_decode($data);
            $code = '<img src="' . $json->items[0]->snippet->thumbnails->default->url . '" />';
        } else {
            if ($bare_host[0] === 'vimeo') {
                $urlEnterd = preg_replace('/#.*/', '', $urlEnterd);
                $vimeo = unserialize(wp_remote_fopen("http://vimeo.com/api/v2/video/" . basename(strtok($urlEnterd, '?')) . ".php"));
                $code = '<img src="' . $vimeo[0]['thumbnail_large'] . '" />';
            } else {
                if ($bare_host[0] === 'flickr') {
                    $code = preg_replace('/<\\/?a[^>]*>/', '', $code);
                }
            }
        }
    } else {
        if (preg_match('/(\\.jpg|\\.jpeg|\\.png|\\.bmp)$/i', $urlEnterd) || preg_match('/(\\.jpg?|\\.jpeg?|\\.png?|\\.bmp?)/i', $urlEnterd) || strpos($urlEnterd, 'imgix') !== false) {
            $code = '<img src="' . $urlEnterd . '" />';
            $mime = 'image/url';
            if ($onlycode == 'false') {
                if ($getsize = @getimagesize($urlEnterd)) {
                    if (isset($getsize[0])) {
                        $width = $getsize[0];
                    }
                    if (isset($getsize[1])) {
                        $height = $getsize[1];
                    }
                } else {
                    $width = 'indefinit';
                    $height = 'indefinit';
                }
            }
        } else {
            if (strpos(strtolower($urlEnterd), '<iframe') !== false) {
                $mime = 'oembed/iframe';
                preg_match_all('/(width|height)=("[^"]*")/i', $urlEnterd, $iframe_size);
                if (isset($iframe_size[2][0])) {
                    preg_match("|\\d+|", $iframe_size[2][0], $width);
                    $width = $width[0];
                }
                if (isset($iframe_size[2][1])) {
                    preg_match("|\\d+|", $iframe_size[2][1], $height);
                    $height = $height[0];
                }
            } else {
                if (strpos(strtolower($urlEnterd), '<svg') !== false) {
                    $mime = 'oembed/svg';
                    preg_match_all('/(width|height)=("[^"]*")/i', $urlEnterd, $svg_size);
                    if (isset($svg_size[2][0])) {
                        preg_match("|\\d+|", $svg_size[2][0], $width);
                        $width = $width[0];
                    }
                    if (isset($svg_size[2][1])) {
                        preg_match("|\\d+|", $svg_size[2][1], $height);
                        $height = $height[0];
                    }
                } else {
                    $mime = 'oembed/html';
                }
            }
            $code = esc_html($urlEnterd);
        }
    }
    if ($code == '' && $urlEnterd != '') {
        $code = 'null';
    }
    echo json_encode(array('code' => $code, 'mime' => $mime, 'width' => $width, 'height' => $height));
    die;
//.........这里部分代码省略.........
开发者ID:b0123498765,项目名称:fithealthyandwealthy,代码行数:101,代码来源:admin.php

示例4: audiotheme_video_sideload_thumbnail

/**
 * Import a video thumbnail from an oEmbed endpoint into the media library.
 *
 * @todo Considering doing video URL comparison rather than oembed thumbnail
 *       comparison?
 *
 * @since 1.8.0
 *
 * @param int $post_id Video post ID.
 * @param string $url Video URL.
 */
function audiotheme_video_sideload_thumbnail($post_id, $url)
{
    require_once ABSPATH . WPINC . '/class-oembed.php';
    $oembed = new \WP_oEmbed();
    $provider = $oembed->get_provider($url);
    if (!$provider || false === ($data = $oembed->fetch($provider, $url)) || !isset($data->thumbnail_url)) {
        return;
    }
    $current_thumb_id = get_post_thumbnail_id($post_id);
    $oembed_thumb_id = get_post_meta($post_id, '_audiotheme_oembed_thumbnail_id', true);
    $oembed_thumb_url = get_post_meta($post_id, '_audiotheme_oembed_thumbnail_url', true);
    // Re-use the existing oEmbed data instead of making another copy of the thumbnail.
    if ($data->thumbnail_url == $oembed_thumb_url && (!$current_thumb_id || $current_thumb_id != $oembed_thumb_id)) {
        set_post_thumbnail($post_id, $oembed_thumb_id);
    } elseif (!$current_thumb_id || $data->thumbnail_url != $oembed_thumb_url) {
        $attachment_id = audiotheme_video_sideload_image($data->thumbnail_url, $post_id);
        if (!empty($attachment_id) && !is_wp_error($attachment_id)) {
            set_post_thumbnail($post_id, $attachment_id);
            // Store the oEmbed thumb data so the same image isn't copied on repeated requests.
            update_post_meta($post_id, '_audiotheme_oembed_thumbnail_id', $attachment_id);
            update_post_meta($post_id, '_audiotheme_oembed_thumbnail_url', $data->thumbnail_url);
        }
    }
}
开发者ID:sewmyheadon,项目名称:audiotheme,代码行数:35,代码来源:videos.php


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