用于使用oembed检索页面信息的PHP库

v1.0.2 2020-06-01 05:40 UTC

This package is auto-updated.

Last update: 2024-09-29 05:29:46 UTC


README

关于

magnetolv1/oembed包基于mpratt/Embera,帮助您在Laravel中使用oEmbed。

什么是oEmbed?

oEmbed是一种格式,它允许其他网站的URL内嵌表达内容。当用户输入资源链接时,网站可以直接解析资源(如图片和视频)而不需要用户手动解析。

功能

  • 为注册的提供商提供oEmbed值。(提供商
  • 可以注册特定的提供商以供使用。
  • 可以使用缓存。

安装

通过composer安装依赖包。

composer require magnetolv1/oembed

配置

发布MagnetoLv1/oembed的配置值

php artisan vendor:publish --provider="MagnetoLv1\Oembed\OembedServiceProvider"

config/oembed.php中修改现有设置。

<?php
return [
    /*
     * 캐시 설정
     */
    'cache' => [
        /*
         * 캐시 저장소 설정
         * null이면 기본(default) 사용
         */
        'store' => null,

        /*
         * 캐시 만료시간(단위 minute)
         * 0 이면 캐시 사용안함
         */
        'expire' => 0,
    ],

    /*
     * Embera\Embera 설정값
     * https://github.com/mpratt/Embera/blob/master/doc/01-usage.md
     */
    'config' => [
        /*
         * true/false - Wether the library should use providers that support https on their html response.
         */
        'https_only' => false,

        /*
         * https://github.com/mpratt/Embera/blob/master/doc/04-fake-responses.md
         * const ALLOW_FAKE_RESPONSES = 1;
         * const DISABLE_FAKE_RESPONSES = 2;
         * const ONLY_FAKE_RESPONSES = 3;
         */
        'fake_responses' => 2,

        /*
         * Array with tags that should be ignored when detecting urls from a text. So that for example Embera doesnt replace urls inside an iframe or img tag.
         */
        'ignore_tags' => ['pre', 'code', 'a', 'img', 'iframe', 'oembed'],

        /*
         *  true/false - Wether we modify the html response in order to get responsive html. - More Information in the responsive data documentation. (BETA)
         */
        'responsive' => false,

        'width' => 0,
        'height' => 0,
        /*
         * Set the maximun width of the embeded resource
         */
        'maxheight' => 0,

        /*
         * Set the maximun width of the embeded resource
         */
        'maxwidth' => 0,
    ],


    /*
     * Provider 리스트
     * providers가 없는 경우 DefaultProviderCollection를 사용하여 전체 Provider가 등록됨
     */
    'providers' => [
        Embera\Provider\Youtube::class,
    ]

];

全局使用

use MagnetoLv1\Oembed\Facades\Oembed;

$oembed = Oembed::get('https://www.youtube.com/watch?v=QSV0LghD1D8');
echo json_encode($oembed);
输出
{
  "author_name": "SBS Running Man",
  "title": "이광수, 폭탄 선언 “이선빈과 결혼하겠습니다” 《Running Man》런닝맨 EP451",
  "provider_name": "YouTube",
  "height": 270,
  "width": 480,
  "html": "<iframe width=\"480\" height=\"270\" src=\"https://www.youtube.com/embed/QSV0LghD1D8?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>",
  "provider_url": "https://www.youtube.com/",
  "thumbnail_url": "https://i.ytimg.com/vi/QSV0LghD1D8/hqdefault.jpg",
  "type": "video",
  "thumbnail_height": 360,
  "author_url": "https://www.youtube.com/user/NewSundaySBS",
  "version": "1.0",
  "thumbnail_width": 480,
  "embera_using_fake_response": 0,
  "embera_provider_name": "Youtube"
}