wrav/oembed
Composer 安装命令:
composer require wrav/oembed
包简介
A simple plugin to extract media information from websites, like youtube videos, twitter statuses or blog articles.
关键字:
README 文档
README
A simple plugin to extract media information from websites, like youtube videos, twitter statuses or blog articles.
Seeking a New Maintainer
It's been nearly nine years since I released the first version of Oembed. While it's been an incredible journey, I no longer have the time or energy to actively maintain the project. Since 2019, I've been deeply involved in building a data and analytics startup, which has grown significantly and now demands most of my focus.
To keep this library alive and thriving, I'm looking for someone passionate about its future to take over its maintenance and development. If you're interested, please reach out by opening an issue or contacting me directly.
In the meantime, I’ll continue merging pull requests from the community to ensure the project doesn’t stagnate, though I won’t be actively contributing new features or updates. Thank you for your support over the years!
Requirements
This plugin requires Craft CMS 3.0.0-beta.23 or later.
Versions
| Version | CraftCMS Version | Embed Version | PHP Version | Branch | Status |
|---|---|---|---|---|---|
| v1 | ^3.0.0-beta.23 | ^3.3 | >=7.2.5 | v1 | Discontinued |
| v2 | ^4.0 | ^3.3 | ^8.0.2 | v2 | Discontinued |
| v3 | ^3.0 | ^4.0 | ^5.0 | ^v4.4 | ^8.2 | v3 | Active |
| dev-v3-php74-support | ^3.0 | ^4.0 | ^5.0 | ^v4.4 | ^7.4 | dev-v3-php74-support | Active (PHP 7.4 Support) |
Quick FYI on URL issues
Many websites, such as Vimeo, are restricting access to standard URLs (e.g. www.vimeo.com) and sometimes require using the embed URL (e.g., player.vimeo.com) to retrieve oEmbed data.
You can typically find the embed URL through the "share" options on video and oEmbed-supported sites. While the plugin provides general rich content as a fallback, its true potential comes from utilizing the oEmbed protocol and the associated metadata from the content provider.
If you're experiencing issues, check whether the provider or page offers an embed version, and use that URL to ensure you're accessing the most accurate data.
Installing
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project -
Then tell Composer to load the plugin:
composer require wrav/oembed -
In the Control Panel, go to Settings → Plugins and click the “Install” button for oEmbed.
Using oEmbed
To use simply call one of the following methods on your field type
{{ entry.field.valid }} # Get the embed object
{{ entry.field.render }} # Renders HTML
{{ entry.field.embed }} # Get the embed object
{{ entry.field.media }} # Get the embed object
We also provide option to use as a Twig variable
{{ craft.oembed.valid(url, options, cacheFields) }}
{{ craft.oembed.render(url, options, cacheFields) }}
{% set embed = craft.oembed.embed(url, options, cacheFields) %}
{% set media = craft.oembed.media(url, options, cacheFields) %}
Updating the embed URL, such as autoplay, rel, mute paramaters. This allows for you to support features the provider might not yet support
{{
entry.oembed_field.render({
params: {
autoplay: 1,
rel: 0,
mute: 0,
loop: 1,
autopause: 1,
},
attributes: {
title: 'Main title',
'data-title': 'Some other title',
}
})
}}
We still support hte old legacy method, however this might be deprecated in future versions.
{{
entry.oembed_field.render({
autoplay: 1,
rel: 0,
mute: 0,
loop: 1,
autopause: 1,
})
}}
Updating the width & height attributes on the iframe can be done using the following method, however is CSS is still recommended view for sizing your iframe.
{{
entry.oembed_field.render({
width: 640,
height: 480,
})
}}
or
{{
entry.oembed_field.render({
attributes: {
width: 640,
height: 480,
}
})
}}
You can access additional media details using the examples below, these are the default keys.
entry.field.media.title
entry.field.media.description
entry.field.media.url
entry.field.media.type
entry.field.media.tags
entry.field.media.images
entry.field.media.image
entry.field.media.imageWidth
entry.field.media.imageHeight
entry.field.media.code
entry.field.media.width
entry.field.media.height
entry.field.media.aspectRatio
entry.field.media.authorName
entry.field.media.authorUrl
entry.field.media.providerName
entry.field.media.providerUrl
entry.field.media.providerIcons
entry.field.media.providerIcon
entry.field.media.publishedDate
entry.field.media.license
entry.field.media.linkedData
entry.field.media.feeds
You can access additional media details from the data array. These will be snake_case so be aware.
{{ dump(entry.field.media.data) }}
Additional Embed information can be found here
Cache
By default, the plugin will cache the following keys on the oembed object. The plugin can cache additional missing fields using the cache prop parameter which will take an array of strings.
{{ entry.oembed_field.render( { width: 640, height: 480, }, [ 'cacheable_key' ] ) }}
Default Keys
- title
- description
- url
- type
- tags
- images
- image
- imageWidth
- imageHeight
- code
- width
- height
- aspectRatio
- authorName
- authorUrl
- providerName
- providerUrl
- providerIcons
- providerIcon
- publishedDate
- license
- linkedData
- feeds
Cookie Management
The plugin includes automatic cookie file cleanup to prevent server storage issues from accumulating embed-cookie files created by the underlying embed/embed library.
Settings
Cookie cleanup can be configured in the plugin settings:
- Enable Cookie Cleanup (default:
true) - Enable/disable automatic cookie file cleanup - Cookie Max Age (default:
86400seconds / 24 hours) - Maximum age of cookie files before cleanup (minimum: 300 seconds) - Cookies Path (optional) - Custom directory path for cookie files (uses system temp directory if empty)
Manual Cleanup Commands
You can manually manage cookie files using the console commands:
# Clean up old cookie files php craft oembed/cookie/cleanup # Get information about cookie files php craft oembed/cookie/info
Automatic Cleanup
Cookie cleanup runs automatically on plugin initialization with built-in throttling to prevent performance impact:
- Cleanup runs at most once per hour
- Only processes files older than the configured
cookieMaxAge - Only removes files matching the pattern
embed-cookies-* - Preserves non-cookie files and recently created files
GraphQL
I recommend enabling caching in the plugin settings menu to speed up the API resolve timing.
Below is an example of a Oembed field called "foobar" add accessing properties from the embed object.
{
entries {
id,
... on page_page_Entry {
foobar {
code,
providerUrl,
aspectRatio
}
}
}
}
Testing
This project uses Codeception and Docker Compose (Locally) and I would strongly ask for unit tests, however I understand sometimes this may not be needed.
NOTE: If your wanting to run the all project tests you'll need to set up the required Meta, Twitter, etc API tokens in the .env file.
# Setting ENV for testing and edit cp tests/.env.example tests/.env # Spin up docker docker compose up -d # Access shell docker exec -it app sh # Run tests via Codeception vendor/bin/codecept run {your_file} # Run with Coverage XDEBUG_MODE=coverage vendor/bin/codecept run --coverage
Credits
Original built while working at HutSix I've since been granted permission to continue development here.
Change Log
Changes can be viewed here
Support
Get in touch via email, Discord, or by creating a Github issue
wrav/oembed 适用场景与选型建议
wrav/oembed 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 208.23k 次下载、GitHub Stars 达 36, 最近一次更新时间为 2018 年 11 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「oembed」 「cms」 「twitter」 「facebook」 「youtube」 「vimeo」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wrav/oembed 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wrav/oembed 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wrav/oembed 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Handles basic OAuth/OAuth2 authentication along with classes for common services
Bundle with a way of defining oEmbed providers, and rendering oEmbed in templates.
Simple Twitter API wrapper
Get detailed info for any URL on the internet! Scraper for HTML, OpenGraph, Schema data
Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
GraphQL authentication for your headless Craft CMS applications.
统计信息
- 总下载量: 208.23k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 36
- 点击次数: 39
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-11-18
