A Oembed consumer library, that gives you information about urls. It helps you replace urls to youtube or vimeo for example, with their html embed code. It has advanced features like offline support, responsive embeds and caching support.

Overview

Embera - PHP Oembed consumer library

Build Status Total Downloads Latest Stable Version

Support via PayPal

Embera is an Oembed consumer library written in PHP. It takes urls from a text and queries the matching service for information about the media and embeds the resulting html. It supports +150 sites, such as Youtube, Twitter, Livestream, Dailymotion, Instagram, Vimeo and many many more.

Installation

Install the latest stable version with:

$ composer require mpratt/embera:~2.0

Standalone Installation (without Composer)

Download the latest release or clone this repository and include the Àutoloader.php file inside the Embera/src directory.

require '....../Autoloader.php';

use Embera\Embera;

$embera = new Embera();

Requirements

  • PHP >= 7.0 (It should work on 5.6)
  • Curl or allow_url_fopen should be enabled

Basic Usage

The most common or basic example is this one:

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!');

The last example returns something like the following text:

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!

You can also inspect urls for their oembed data:

use Embera\Embera;

$embera = new Embera();
print_r($embera->getUrlData([
    'https://vimeo.com/374131624',
    'https://www.flickr.com/photos/bees/8597283706/in/photostream',
]));

That will return something like this

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] => ........
        )
)

The response data depends on the provider, each of them returns information about the consulted media, however this library always tries to provide an embeddable html key that can be used to embed the information on a html document.

This library has fake responses / Offline support which is a way of getting the html embeddable code without the need of querying the oembed provider. It also has caching support, provider collections, responsive embeds and many other features. You can find out more by reading the documentation below.

Documentation

Migrating from version >= 1.9.x

The folder structure has changed, the library is now in the src folder and you can find an autoloader there if you are not using composer.

The configuration array has changed in order to make it simpler. Take a look at the Usage/Configuration instructions to update it.

The other major change is that the inspectUrlInfo() method is now called getUrlData(). The HtmlFormatter class does not exist anymore since the library allows now other type of templating.

Updating should be fairly easy, check the documentation.

Submitting bugs and feature requests

Bugs and feature request are tracked on GitHub

Author

Michael Pratt - [email protected] - http://www.michael-pratt.com See also the list of contributors which participated in this project.

If you like this library, it has been useful to you and want to support me, you can do it via paypal.

Support via PayPal

License

Embera is licensed under the MIT License - see the LICENSE file for details

Comments
  • Custom Provider Parameters

    Custom Provider Parameters

    re: https://github.com/mpratt/Embera/blob/master/doc/07-advanced-usage.md#passing-custom-parameters-to-provider

    This doesn't work for Facebook/Instagram access_tokens. $config['instagram_access_token'] will not be seen by the Instagram provider. If I pass $config['access_token'] then both Facebook and Instagram work fine.

    It's unclear to me how best to fix this. access_token does need to be in $this->config but using instagram_access_token means it only appears in getParams() and the Instagram provider uses the legacy endpoint.

    I'd be happy to create a PR with a proposed fix, but perhaps you would more quickly know the best way to deal with this.

    opened by billtomczak 9
  • twiitter embed doesn't work

    twiitter embed doesn't work

    https://twitter.com/RalphGarman/status/362589356495605762/ Array ( [0] => 0: Invalid response for https://publish.twitter.com/oembed.json?url=https%3A%2F%2Ftwitter.com%2FRalphGarman%2Fstatus%2F362589356495605762 [1] => 0: Invalid response for https://publish.twitter.com/oembed.json?url=https%3A%2F%2Ftwitter.com%2FRalphGarman%2Fstatus%2F362589356495605762 )

    opened by chuja3 9
  • Ignore or modify links

    Ignore or modify links

    Hi, I guess oEmbed was invented to enhance user generated content. The big problem I have is that I'm getting a mix of plaintext and html. Plaintext is fine, but for example <a href="http://youtube.com/***">http://youtube.com/***</a> is getting messed up when parsed through Embara.

    There are several solutions I thought off:

    • Strip all links from my content (bad, there are links that are linking to non oembed sites)
    • Strip links from oEmbed sites (a bit bad, I had to maintain another list of regex's)
    • Embara could ignore links wrapped in html (in my opionion the best solution)
    • Embara could remove html from oEmbed site links and replace them with am embed code (good, but sometimes it could be important to keep a link as a link)

    Did you encountered such a problem and what did you do?

    Greets, Sören

    opened by pattyland 7
  • Improve code

    Improve code

    • [x] Tests improvements (use proper methods from php unit instead of php constructions and checks for true and false)
    • [x] Performance improved with using static for closures
    • [x] Optimize regular expressions (replace \w\d with just \w (because \w already include \d), remove excessive escaping, use character classes ([vl]) instead of or (v|l), remove i flag for patterns without alphabetical symbols)
    • [x] Remove obsolete imports
    • [x] Remove obsolete test
    • [x] Fix phpdoc in tests
    opened by vkhramtsov 6
  • How do I change embed to use https?

    How do I change embed to use https?

    Hi, I am trying to use this on a secure server, is it possible to change embed links to https? I see a function for it, just not sure how to use it.

    Thanks, Amir

    opened by amirshawn 6
  • (OLD) Road to Embera 2.0

    (OLD) Road to Embera 2.0

    I am starting to think about version 2.0 of this library. There are some areas of improvement and perhaps I might need to introduce some changes to the API that might break compatibility.

    As of now, the main points that I think are very important in order to release a 2.0 version are:

    • [ ] Reduce Class complexity.
    • [ ] Change the way the library handles custom Oembed Providers. In other words, make it simpler!
    • [ ] Expose an API that allows the user to modify the Oembed response directly.
    • [ ] Use Interfaces so that developers can change parts of the Library via dependency injection.
    • [ ] I am not happy with the configuration array, lets simplify it a bit
    • [ ] Lets get away from the Formatter Class and find another way to use "templates"

    Other stuff I've been thinking about that I'm not sure that should be implemented on Embera are:

    • [ ] A simple caching system (probably file based) for urls
    • [ ] A global (or per Provider) way to handle https embeds
    • [ ] Normalize the oembed responses (some providers reply with thumbnailWidth others with thumbnal_width :unamused: )
    • [ ] Add Embedly/NoEmbed/Iframely providers
    • [ ] Look into responsive embeds and the possibility to implement them on some providers

    We all know that PHP 5.3 is deprecated now (since August 2014), but I still plan on supporting it. Yeah, I know how it feels when you're stuck on a shitty environment without ways to upgrade.. I feel your pain too..

    I'm going to keep fixing bugs and adding providers to version 1.x.x. Version 2.0 should be available somewhere in february 2015.

    I will make a 2.0 branch available over the weekend in order to start playing.

    Feel free to comment and share your ideas/thoughts for this library.

    • Edit: grammar :(
    enhancement 
    opened by mpratt 5
  • Facebook is problematic

    Facebook is problematic

    For posts, the height is too big and the result isn't responsive.

    For pages, a url like https://www.facebook.com/<USER> always seems to return the dreaded 'This Facebook post is no longer available'

    Videos seem to be okay and responsive, if not necessarily what might be desired.

    We've spent quite bit of time trying to figure out how to fix the height issues in posts with little success. The one thing that seems to make everything work better was to skip the modifyResponse() method entirely and unset the provider name. We have a subclass to do this:

    public function modifyResponse(array $response = [])
    {
        unset($response['embera_provider_name']);
    
        return $response;
    }
    

    Pages - now are accessible, if unresponsive and the height is correct Posts - no change other than the height problem is fixed, still not responsive Videos - The video is now fully embedded without the FB user/share links and still responsive

    I'm having trouble wrapping my brain around what the intent behind FaceBook::modifyResponse() code is. I assume the idea is to make the non-responsive response responsive. But it doesn't do that for posts and makes pages not work.

    For now our lame patch does what we need it to do, but it doesn't strike me as a particularly good fix.

    I'd be happy to work on a patch, but I'm unclear how to approach this.

    opened by billtomczak 4
  • Fix several issues

    Fix several issues

    • [x] Remove obsolete use statements
    • [x] Fix php docs
    • [x] Remove array usage where we can use simple compare
    • [x] Optimize some code
    • [x] Remove methods with same body as in parent
    opened by vkhramtsov 4
  • Specify provider(s)

    Specify provider(s)

    Thanks for this awesome library, The issue is, what if i want to specify specifec provider(s) for my request, so it will return if this url is from this provider or not before getting the data and then checking the provider name and stuff ? is this possible ?, or I need to do the filter for the url before using the embera class?

    Thanks

    opened by ayndev 4
  • added proper merging of deep associative arrays

    added proper merging of deep associative arrays

    The array_merge in the configuration doesn't correctly merge the deep associative array as it only merges the first level of the array. Thus when you miss out configuration options from the params config array you run into errors.

    So I've added a deep recursive merge function to correctly merge in the specified configuration options.

    There may be other places where there are incorrect deep merges and you may need to update accordingly.

    opened by buggedcom 4
  • fix: use current `__NAMESPACE__` instead of hardcoded string

    fix: use current `__NAMESPACE__` instead of hardcoded string

    | Q | A | ----------------- | ---------- | Bug fix? | yes | New feature? | no | BC breaks? | no
    | Need Doc update | no

    Describe your change

    Use the __NAMESPACE__ identifier to get the full qualified name for a class instead of a string.

    What problem is this fixing?

    I want to bundle this package within my WordPress plugin together with PHP-Scoper, unfortunately it does not scope a hardcoded namespace string.

    PHP-Scoper is a tool which essentially moves any body of code, including all dependencies such as vendor directories, to a new and distinct namespace.

    WIthout this changes, I get the following error:

    PHP Fatal error:  Uncaught Error: Class 'Embera\\Provider\\TwentyThreeHq' not found in X/vendor/mpratt/embera/src/Embera/ProviderCollection/ProviderCollectionAdapter.php:89
    
    opened by matzeeable 3
Owner
Michael Pratt
Michael Pratt
Oui embed - (o)Embed plugin for @Textpattern

oui_embed Embed everything… Get information from any web page (using oembed, opengraph, twitter-cards, scrapping the html, etc). It’s compatible with

Nicolas Morand 2 Jun 21, 2018
This Magento extension provides a Real Full Page Caching for Magento powered by Varnish with support of Session-Based information caching (Cart, Customer Accounts, ...) via ESI includes

This Magento extension provides a Real Full Page Caching (FPC) for Magento powered by Varnish with support of Session-Based information caching (Cart, Customer Accounts, ...) via ESI includes

Hugues Alary 95 Feb 11, 2022
This package provides a simple and intuitive way to work on the Youtube Data API. It provides fluent interface to Youtube features.

Laravel Youtube Client This package provides a simple and intuitive way to work on the Youtube Data API. It provides fluent interface to Youtube featu

Tilson Mateus 6 May 31, 2023
A web application built on PHP for user to view their credit information in their mysql database

TheCreditInfo Table of Content About Inspiration Technologies Client Pages Usage About Credere is a website created to help you track your credit hist

Abdul-Baseet Shabi 0 Jul 21, 2022
Extracts information about web pages, like youtube videos, twitter statuses or blog articles.

Essence is a simple PHP library to extract media information from websites, like youtube videos, twitter statuses or blog articles. If you were alread

Essence 765 Dec 30, 2022
Arc youtube - Youtube plugin for Textpattern

arc_youtube A Textpattern plugin for easily embedding Youtube videos in pages using a customisable player. This plugin works well with arc_vimeo and o

Andy Carter 5 May 17, 2018
php String Objects Chains like length,forEach,filter,replace,repalcAll much More.... Module

php String Objects Chains like length,forEach,filter,replace,repalcAll much More.... Module

im__koli 1 Mar 29, 2022
Ip2region is a offline IP location library with accuracy rate of 99.9% and 0.0x millseconds searching performance. DB file is ONLY a few megabytes with all IP address stored. binding for Java,PHP,C,Python,Nodejs,Golang,C#,lua. Binary,B-tree,Memory searching algorithm

Ip2region是什么? ip2region - 准确率99.9%的离线IP地址定位库,0.0x毫秒级查询,ip2region.db数据库只有数MB,提供了java,php,c,python,nodejs,golang,c#等查询绑定和Binary,B树,内存三种查询算法。 Ip2region特性

Lion 12.6k Dec 30, 2022
A PocketMine-MP plugin that lets you teleport among offline players

OfflinePlayerTP A PocketMine-MP plugin that lets you teleport among offline players. Commands Command Description /otp <player> Teleport to (offline)

Muqsit Rayyan 8 Sep 23, 2022
A small PHP library to generate YouTube-like ids from numbers.

A small PHP library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user.

Vincent Klaiber 4.9k Dec 30, 2022
this is a simple website about news and it has some features

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

a14z 2 Dec 11, 2022
Laravel & Solana Phantom wallet example built with Bootstrap, JQuery. App connects to Phantom wallet and fetching publicKey and balance information.

Phantom Wallet Authentication Example Laravel & Solana ($SOL) Phantom wallet example built with Bootstrap, JQuery. This is a Web 3.0 app that connects

Solanacraft 3 Oct 19, 2022
Your personal Self-hosted or offline YoutTube Kids!

New Tube You have a problem with youtube kids and need online youtube? This is yours. NewTube! Simply clone the project and put your mp4 video & cover

Javad Adib 7 Dec 28, 2022
IPv4/IPv6 offline address database.IPv4/IPv6双栈地址离线数据库。IPv4 by 纯真网络,IPv6 by ZX Inc.

IPv4/IPv6 offline address database.IPv4/IPv6双栈地址离线数据库。IPv4 by 纯真网络,IPv6 by ZX Inc. Being updating every 5 days 每5天更新一次 IPv4 address locations by 纯真网络

null 0 Jan 26, 2022
Raspberry Pi wifi hotspot with an offline-first community portal. Optionally shares internet access over Tor.

Raspberry Pi wifi hotspot with an offline-first community portal. Optionally shares internet access over Tor.

Martti Malmi 17 Dec 15, 2022
Roach-example-project - Example project to demonstrate how to use RoachPHP in a Laravel project.

Example repository to illustrate how to use roach-php/laravel in a Laravel app. Check app/Spiders/FussballdatenSpider.php for an example spider that c

Kai Sassnowski 11 Dec 15, 2022
Messaging solutions for PHP - It contains advanced features build on top of a transport component

It contains advanced features build on top of a transport component. Client component kind of plug and play things or consumption component that simplify message processing a lot. Read more about it in documentation.

Enqueue 175 Jan 3, 2023
Allow any Discord user to sign in to your website and save their discord user information for later use.

Simple Discord SSO ( Single Sign-On ) Requires at least: 5.0 Tested up to: 5.8.3 Stable tag: 1.0.2 Requires PHP: 7.4 License: GPLv2 or later License U

null 2 Oct 7, 2022
CRUD Build a system to insert student name information, grade the class name, and edit and delete this information

CRUD Build a system to insert student name information, grade the class name, and edit and delete this information

Sajjad 2 Aug 14, 2022