mpratt / embera
Oembed消费者库。将URL转换为它们的HTML嵌入代码。支持150多个网站,如YouTube、Twitter、vimeo、Instagram等。
Requires
- php: >=5.6
- ext-json: *
Requires (Dev)
- phpstan/phpstan: ^1.4
- phpunit/phpunit: ^9.0
Suggests
- ext-curl: Fetch data using curl instead of using file_get_contents
- dev-master
- 2.0.41
- 2.0.40
- 2.0.39
- 2.0.38
- 2.0.37
- 2.0.36
- 2.0.35
- 2.0.34
- 2.0.33
- 2.0.32
- 2.0.30
- 2.0.29
- 2.0.28
- 2.0.27
- 2.0.26
- 2.0.25
- 2.0.24
- 2.0.23
- 2.0.22
- 2.0.21
- 2.0.20
- 2.0.19
- 2.0.18
- 2.0.17
- 2.0.16
- 2.0.15
- 2.0.14
- 2.0.13
- 2.0.12
- 2.0.11
- 2.0.10
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 2.0.0-RC1
- 1.x-dev
- 1.9.6
- 1.9.5
- 1.9.3
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.15
- 1.8.14
- 1.8.13
- 1.8.12
- 1.8.11
- 1.8.10
- 1.8.9
- 1.8.8
- 1.8.7
- 1.8.6
- 1.8.5
- 1.8.4
- 1.8.3
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7
- 1.6
- 1.5
- 1.4
- 1.3
- 1.2
- 1.1
- 1.0
- 0.9
This package is auto-updated.
Last update: 2024-09-17 04:42:15 UTC
README
Embera是一个用PHP编写的Oembed消费者库。它从文本中提取URL,查询匹配的服务以获取媒体信息并将生成的HTML嵌入。它支持+150个网站,如YouTube、Twitter、Livestream、Dailymotion、Instagram、Vimeo和更多。
安装
使用以下命令安装最新稳定版本
$ composer require mpratt/embera:~2.0
独立安装(无Composer)
下载最新版本或克隆此存储库,并在Embera/src
目录中包含Àutoloader.php
文件。
require '....../Autoloader.php'; use Embera\Embera; $embera = new Embera();
要求
- PHP >= 7.0(应在5.6上工作)
- 启用Curl或allow_url_fopen
基本用法
最常见或基本的例子是以下这个
use Embera\Embera; $embera = new Embera(); echo $embera->autoEmbed('Hi! Have you seen this video? https://www.youtube.com/watch?v=J---aiyznGQ Its the best!');
最后一个例子返回以下类似文本
Hi! Have you seen this video? <iframe width="459" height="344" src="https://www.youtube.com/embed/J---aiyznGQ?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen ></iframe> Its the best!
您还可以检查URL的oembed数据
use Embera\Embera; $embera = new Embera(); print_r($embera->getUrlData([ 'https://vimeo.com/374131624', 'https://www.flickr.com/photos/bees/8597283706/in/photostream', ]));
这将返回以下类似内容
Array ( [https://vimeo.com/374131624] => Array ( [type] => video [version] => 1.0 [provider_name] => Vimeo [provider_url] => https://vimeo.com/ [title] => VACATION movie [author_name] => Andrey Kasay [author_url] => https://vimeo.com/andreykasay [is_plus] => 0 [account_type] => basic [html] => <iframe src="......."></iframe> [width] => 426 [height] => 240 [duration] => 146 [description] => Остросюжетное кино про жизнь [thumbnail_url] => https://i.vimeocdn.com/video/832478725_295x166.jpg [thumbnail_width] => 295 [thumbnail_height] => 166 [thumbnail_url_with_play_button] => https://i.vimeocdn.com/......Fcrawler_play.png [upload_date] => 2019-11-19 06:27:37 [video_id] => 374131624 [uri] => /videos/374131624 [embera_using_fake_response] => 0 [embera_provider_name] => Vimeo ) [https://www.flickr.com/photos/bees/8597283706/in/photostream] => Array ( [type] => photo [flickr_type] => photo [title] => Durumu [author_name] => bees [author_url] => https://www.flickr.com/photos/bees/ [width] => 1024 [height] => 723 [url] => https://live.staticflickr.com/8385/8597283706_7b51ea50b1_b.jpg [web_page] => https://www.flickr.com/photos/bees/8597283706/ [thumbnail_url] => https://live.staticflickr.com/8385/8597283706_7b51ea50b1_q.jpg [thumbnail_width] => 150 [thumbnail_height] => 150 [web_page_short_url] => https://flic.kr/p/e6HjVq [license] => All Rights Reserved [license_id] => 0 [html] => ......... [version] => 1.0 [cache_age] => 3600 [provider_name] => Flickr [provider_url] => https://www.flickr.com/ [embera_using_fake_response] => 0 [embera_provider_name] => Flickr [html_alternative] => ........ ) )
响应数据取决于提供商,每个提供商都返回关于咨询媒体的信息,但是这个库始终尝试提供可嵌入的html
键,该键可以用于在HTML文档中嵌入信息。
此库具有模拟响应/离线支持,这是一种在不查询oembed提供商的情况下获取可嵌入HTML代码的方法。它还具有缓存支持、提供者集合、响应式嵌入和其他许多功能。您可以通过阅读下面的文档了解更多信息。
文档
从版本 >= 1.9.x 迁移
文件夹结构已更改,库现在位于src
文件夹中,如果您不使用Composer,您可以在其中找到自动加载器。
配置数组已更改,以使其更简单。请参阅使用/配置说明以更新它。
另一个主要更改是inspectUrlInfo()
方法现在称为getUrlData()
。由于库现在允许其他类型的模板,因此不再存在HtmlFormatter
类。
更新应该相对简单,请检查文档。
提交错误和功能请求
错误和功能请求在GitHub上跟踪
作者
Michael Pratt - yo@michael-pratt.com - http://www.michael-pratt.com 参与此项目的贡献者名单。
如果您喜欢这个库,它对您有用,并想支持我,您可以通过Paypal来支持。
许可证
Embera根据MIT许可证许可 - 请参阅LICENSE文件以获取详细信息