Giter Club home page Giter Club logo

oembed's Introduction

Scrutinizer Code Quality Build Status Code Intelligence Status

OEmbed

PHP library to retreive and display embed media from various media providers that support OEmbed data format. Websites such as YouTube, Vimeo, Twitter, Imgur and others.

This library also comes with support for direct mp4/video sources and some of the media providers that don't use OEmbed.

Installation

Library is written in PHP 8 with various neat features it gives, so apologies to everybody who wanted to use it in previous versions of PHP. If you do need similar library, I could recommend checking my previous package in this field: cohensive/embed.

Add following require to your composer.json file:

"cohensive/oembed": "dev-master"
// or
"cohensive/oembed": "0.11"

Then run composer install or composer update to download it and autoload.

Or run:

$ composer require cohensive/oembed

If you're installing this library and want to utilize it with Laravel, package should automatically load its Service Provider.

If you plan to use OEmbed facade with Laravel, add Facade to your app.php config file in aliases section:

'aliases' => array(

	//...
	'OEmbed' => 'Cohensive\OEmbed\Facades\OEmbed'
	//...

)

Usage

Standalone use:

// Use of factory will automatically load list of providers.
$factory = new \Cohensive\OEmbed\Factory();
$embed = $factory->get('http://youtu.be/uifYHNyH-jA');

if ($embed) {
	// Print default embed html code.
	echo $embed->html();

	// Print embed html code with custom width. Works for IFRAME and VIDEO html embed code.
	echo $embed->html(['width' => 600]);

	// Checks if embed data contains details on thumbnail.
	$embed->hasThumbnail();

	// Returns embed "src" - URL string / array of strings / null for current embed.
	// Accepts same options as "html" method.
	$embed->src();

	// Returns an array containing thumbnail details: url, width and height.
	$embed->thumbnail();

	// Returns an array containing all available embed data including default HTML code.
	$embed->data();
}

Laravel use:

// Either use Facade:
$embed = OEmbed::get('http://youtu.be/uifYHNyH-jA');

// Load via Dependency Injection:
public function method(OEmbed $oembed) {
	$embed = OEmbed::get('http://youtu.be/uifYHNyH-jA');
}

if ($embed) {
	// Print default embed html code.
	echo $embed->html();

	// Print embed html code with custom width. Works for IFRAME and VIDEO html embed code.
	echo $embed->html(['width' => 600]);

	// Checks if embed data contains details on thumbnail.
	$embed->hasThumbnail();

	// Returns an array containing thumbnail details: url, width and height.
	$embed->thumbnail();

	// Return thumbnail url if it exists or null.
	$embed->thumbnailUrl();

	// Returns an array containing all available embed data including default HTML code.
	$embed->data();
}

Config

Library comes with a big config file located in resources/ folder. That file contains an array where you can specify few things on a global basis and will you to pick which media providers you want to be used and which not.

Config file will be automatically loaded if you're using library with Laravel, which you can also publish and edit:

$ php artisan vendor:publish

If you're using OEmbed in standalone mode, you can add your own config file into Factory or OEmbed classes.

oembed's People

Contributors

kanecohen avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.