pax_global_header 0000666 0000000 0000000 00000000064 13435002260 0014505 g ustar 00root root 0000000 0000000 52 comment=4f0d7c0ba8dce13228fd35b7a73cd4ef5ab0f02c Embed-3.3.9/ 0000775 0000000 0000000 00000000000 13435002260 0012535 5 ustar 00root root 0000000 0000000 Embed-3.3.9/LICENSE 0000664 0000000 0000000 00000002075 13435002260 0013546 0 ustar 00root root 0000000 0000000 The MIT License (MIT) Copyright (c) 2017 Oscar Otero Marzoa Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Embed-3.3.9/README.md 0000664 0000000 0000000 00000026154 13435002260 0014024 0 ustar 00root root 0000000 0000000 # Embed [![Build Status][ico-travis]][link-travis] [![Quality Score][ico-scrutinizer]][link-scrutinizer] [![Reference Status][ico-references]][link-references] [![Latest Version on Packagist][ico-version]][link-packagist] [![Total Downloads][ico-downloads]][link-packagist] [![Monthly Downloads][ico-m-downloads]][link-packagist] [![Software License][ico-license]](LICENSE) [![SensioLabs Insight][ico-sensiolabs]][link-sensiolabs] PHP library to get information from any web page (using oembed, opengraph, twitter-cards, scrapping the html, etc). It's compatible with any web service (youtube, vimeo, flickr, instagram, etc) and has adapters to some sites like (archive.org, github, facebook, etc). Requirements: * PHP 5.5+ * Curl library installed > * If you need PHP 5.3 support, use the 1.x version * If you need PHP 5.4 support, use the 2.x version ## Online demo http://oscarotero.com/embed3/demo ## Installation This package is installable and autoloadable via Composer as [embed/embed](https://packagist.org/packages/embed/embed). ``` $ composer require embed/embed ``` If you cannot (or don't want to) use composer, just include the [PSR-4 autoload.php file](src/autoloader.php) in your code. ## Usage ```php use Embed\Embed; //Load any url: $info = Embed::create('https://www.youtube.com/watch?v=PP1xn5wHtxE'); //Get content info $info->title; //The page title $info->description; //The page description $info->url; //The canonical url $info->type; //The page type (link, video, image, rich) $info->tags; //The page keywords (tags) $info->images; //List of all images found in the page $info->image; //The image choosen as main image $info->imageWidth; //The width of the main image $info->imageHeight; //The height of the main image $info->code; //The code to embed the image, video, etc $info->width; //The width of the embed code $info->height; //The height of the embed code $info->aspectRatio; //The aspect ratio (width/height) $info->authorName; //The resource author $info->authorUrl; //The author url $info->providerName; //The provider name of the page (Youtube, Twitter, Instagram, etc) $info->providerUrl; //The provider url $info->providerIcons; //All provider icons found in the page $info->providerIcon; //The icon choosen as main icon $info->publishedDate; //The published date of the resource $info->license; //The license url of the resource $info->linkedData; //The linked-data info (http://json-ld.org/) $info->feeds; //The RSS/Atom feeds ``` ## The adapter The adapter is the class that get all information of the page from the providers and choose the best result for each value. For example, a page can provide multiple titles from opengraph, twitter cards, oembed, the `
". "Play with this gist on SassMeister.". '
'. ''; } } Embed-3.3.9/src/Adapters/Slides.php 0000664 0000000 0000000 00000001410 13435002260 0017017 0 ustar 00root root 0000000 0000000 isValid() && $response->getUrl()->match([ 'slides.com/*', ]); } /** * {@inheritdoc} */ public function getCode() { return Utils::iframe($this->getResponse()->getUrl()->withAddedPath('embed'), $this->width, $this->height); } /** * {@inheritdoc} */ public function getWidth() { return 576; } /** * {@inheritdoc} */ public function getHeight() { return 420; } } Embed-3.3.9/src/Adapters/Snipplr.php 0000664 0000000 0000000 00000001621 13435002260 0017227 0 ustar 00root root 0000000 0000000 isValid() && $response->getUrl()->match([ 'snipplr.com/view/*', ]); } /** * {@inheritdoc} */ public function getCode() { $this->width = null; $this->height = null; $id = $this->getResponse()->getUrl()->getDirectoryPosition(1); return <<View this snippet on Snipplr
CODE;
}
}
Embed-3.3.9/src/Adapters/Webpage.php 0000664 0000000 0000000 00000001236 13435002260 0017154 0 ustar 00root root 0000000 0000000 providers = [
'oembed' => new Providers\OEmbed($this),
'opengraph' => new Providers\OpenGraph($this),
'linkpulse' => new Providers\Linkpulse($this),
'twittercards' => new Providers\TwitterCards($this),
'dcterms' => new Providers\Dcterms($this),
'sailthru' => new Providers\Sailthru($this),
'html' => new Providers\Html($this),
];
}
}
Embed-3.3.9/src/Adapters/Wikipedia.php 0000664 0000000 0000000 00000001305 13435002260 0017505 0 ustar 00root root 0000000 0000000 isValid() && $response->getUrl()->match([
'*.wikipedia.org/wiki/*',
]);
}
/**
* {@inheritdoc}
*/
protected function init()
{
parent::init();
$this->providers = ['wikipedia' => new Api\Wikipedia($this)] + $this->providers;
}
/**
* {@inheritdoc}
*/
public function getProviderName()
{
return 'Wikipedia';
}
}
Embed-3.3.9/src/Adapters/Youtube.php 0000664 0000000 0000000 00000000645 13435002260 0017241 0 ustar 00root root 0000000 0000000 isValid([200, 429]) && $response->getUrl()->match([
'*.youtube.*',
]);
}
}
Embed-3.3.9/src/Bag.php 0000664 0000000 0000000 00000010436 13435002260 0014532 0 ustar 00root root 0000000 0000000 set($parameters);
}
/**
* Save a value.
*
* @param string|array $name
* @param mixed $value
*/
public function set($name, $value = null)
{
if (!is_array($name)) {
$name = [$name => $value];
}
foreach ($name as $name => $value) {
$name = self::normalizeName($name);
$value = self::normalizeValue($value);
$this->parameters[$name] = $value;
}
}
/**
* Adds a subvalue.
*
* @param string $name
* @param mixed $value
*/
public function add($name, $value = null)
{
$name = self::normalizeName($name);
$value = self::normalizeValue($value);
if (!isset($this->parameters[$name])) {
$this->parameters[$name] = [];
} elseif (!is_array($this->parameters[$name])) {
$this->parameters[$name] = (array) $this->parameters[$name];
}
$this->parameters[$name][] = $value;
}
/**
* Get a value.
*
* @param string $name
* @param bool $isHtml
*
* @return string|null
*/
public function get($name, $isHtml = false)
{
$name = self::normalizeName($name);
if (strpos($name, '[') !== false) {
$names = explode('[', str_replace(']', '', $name));
$key = array_shift($names);
$item = isset($this->parameters[$key]) ? $this->parameters[$key] : [];
foreach ($names as $key) {
if (!isset($item[$key])) {
return;
}
$item = $item[$key];
}
return $isHtml ? $item : self::toPlainValue($item);
}
if (isset($this->parameters[$name])) {
return $isHtml ? $this->parameters[$name] : self::toPlainValue($this->parameters[$name]);
}
}
/**
* Return all stored values keys.
*
* @return array
*/
public function getKeys()
{
return array_keys($this->parameters);
}
/**
* Return the raw stored values.
*
* @return array
*/
public function getAll()
{
return $this->parameters;
}
/**
* Check if a value exists and is not empty.
*
* @param string $name
*
* @return bool
*/
public function has($name)
{
$name = self::normalizeName($name);
if (strpos($name, '[') !== false) {
$names = explode('[', str_replace(']', '', $name));
$key = array_shift($names);
$item = isset($this->parameters[$key]) ? $this->parameters[$key] : [];
foreach ($names as $key) {
if (!isset($item[$key])) {
return false;
}
$item = $item[$key];
}
return !empty($item);
}
return !empty($this->parameters[$name]);
}
/**
* Normalize a variable name.
*
* @param string $name
*
* @return string
*/
private static function normalizeName($name)
{
return strtolower(trim($name));
}
/**
* Normalize a value.
* If it's a string, removes spaces and normalize some utf-8 chars.
*
* @param mixed $value
*
* @return mixed
*/
private static function normalizeValue($value)
{
if (is_string($value)) {
$value = str_ireplace([' ', ' '], ' ', $value);
$value = trim($value);
return ($value === '') ? null : $value;
}
return $value;
}
/**
* Remove the html code and entities in a value
*
* @param mixed $value
*
* @return mixed
*/
private static function toPlainValue($value)
{
if (is_string($value)) {
$value = strip_tags($value);
$value = html_entity_decode($value, ENT_QUOTES | ENT_XML1, 'UTF-8');
$value = trim($value);
return ($value === '') ? null : $value;
}
return $value;
}
}
Embed-3.3.9/src/DataInterface.php 0000664 0000000 0000000 00000004731 13435002260 0016534 0 ustar 00root root 0000000 0000000 null,
'min_image_width' => 1,
'min_image_height' => 1,
'choose_bigger_image' => false,
'images_blacklist' => [],
'url_blacklist' => [
'?&ns_campaign=*',
'?&ns_source=*',
'?&utm_campaign=*',
'?&utm_medium=*',
'?&utm_source=*',
],
'follow_canonical' => true,
'html' => [
'max_images' => -1,
'external_images' => false
],
'oembed' => [
'parameters' => [],
'embedly_key' => null,
'iframely_key' => null,
],
'google' => [
'key' => null,
],
'soundcloud' => [
'key' => null,
],
'facebook' => [
'key' => null,
'events_fields' => 'id,cover,description,end_time,name,owner,place,start_time,timezone',
'videos_fields' => 'id,description,embed_html',
]
];
/**
* Gets the info from an url.
*
* @param Url|string $url
* @param array|null $config
* @param DispatcherInterface|null $dispatcher
*
* @return Adapter
*/
public static function create($url, array $config = null, DispatcherInterface $dispatcher = null)
{
if (!($url instanceof Url)) {
$url = Url::create($url);
}
if ($config === null) {
$config = self::$default_config;
} else {
$config += self::$default_config;
}
if ($dispatcher === null) {
$dispatcher = new CurlDispatcher();
}
$info = self::process($url, $config, $dispatcher);
if ($info->getConfig('follow_canonical') === false) {
return $info;
}
// Repeat the process if:
// - The canonical url is different
// - No embed code has found
$from = preg_replace('|^(\w+://)|', '', rtrim((string)$info->getResponse()->getUrl(), '/'));
$to = preg_replace('|^(\w+://)|', '', rtrim($info->url, '/'));
if ($from !== $to && empty($info->code)) {
//accept new result if valid
try {
return self::process(Url::create($info->url), $config, $dispatcher);
} catch (\Exception $e) {
return $info;
}
}
return $info;
}
/**
* Process the url.
*
* @param Url $url
* @param array $config
* @param DispatcherInterface $dispatcher
*
* @throws Exceptions\InvalidUrlException If the urls is not valid
*
* @return Adapter
*/
private static function process(Url $url, array $config, DispatcherInterface $dispatcher)
{
$response = $dispatcher->dispatch($url);
//If is a file use File Adapter
$adapter = self::getClass('File', $config);
if ($adapter::check($response)) {
return new $adapter($response, $config, $dispatcher);
}
//Search the adapter using the domain
$adapter = self::getClass($response->getUrl()->getClassNameForDomain(), $config);
if (class_exists($adapter) && $adapter::check($response)) {
return new $adapter($response, $config, $dispatcher);
}
//Use the default webpage adapter
$adapter = self::getClass('Webpage', $config);
if ($adapter::check($response)) {
return new $adapter($response, $config, $dispatcher);
}
if ($response->getError() === null) {
$exception = new Exceptions\InvalidUrlException(sprintf("Invalid url '%s' (Status code %s)", (string) $url, $response->getStatusCode()));
} else {
$exception = new Exceptions\InvalidUrlException($response->getError());
}
$exception->setResponse($response);
throw $exception;
}
/**
* Returns a class name using the custom_adapters_namespace
*
* @param string $name
* @param array $config
*
* @return string
*/
private static function getClass($name, array $config)
{
if (!empty($config['custom_adapters_namespace'])) {
$namespaces = (array) $config['custom_adapters_namespace'];
foreach ($namespaces as $namespace) {
$class = $namespace.$name;
if (class_exists($class)) {
return $class;
}
}
}
return 'Embed\\Adapters\\'.$name;
}
}
Embed-3.3.9/src/Exceptions/ 0000775 0000000 0000000 00000000000 13435002260 0015445 5 ustar 00root root 0000000 0000000 Embed-3.3.9/src/Exceptions/EmbedException.php 0000664 0000000 0000000 00000000137 13435002260 0021052 0 ustar 00root root 0000000 0000000 response = $response;
}
/**
* Get the response related with this error
*
* @return Response|null
*/
public function getResponse()
{
return $this->response;
}
}
Embed-3.3.9/src/Http/ 0000775 0000000 0000000 00000000000 13435002260 0014243 5 ustar 00root root 0000000 0000000 Embed-3.3.9/src/Http/AbstractResponse.php 0000664 0000000 0000000 00000004542 13435002260 0020243 0 ustar 00root root 0000000 0000000 startingUrl = $startingUrl;
$this->url = $url;
$this->statusCode = (int)$statusCode;
$this->contentType = $contentType;
$this->headers = $headers;
$this->info = $info;
}
/**
* Get the starting url.
*
* @return Url
*/
public function getStartingUrl()
{
return $this->startingUrl;
}
/**
* Get the http code of the response, for example: 200.
*
* @return int
*/
public function getStatusCode()
{
return $this->statusCode;
}
/**
* Get the content-type of the response, for example: text/html.
*
* @return string|null
*/
public function getContentType()
{
return $this->contentType;
}
/**
* Returns the final url.
*
* @return Url
*/
public function getUrl()
{
return $this->url;
}
/**
* Returns the http headers.
*
* @return array
*/
public function getHeaders()
{
return $this->headers;
}
/**
* Returns extra http info.
*
* @return array
*/
public function getInfo()
{
return $this->info;
}
/**
* Returns dispatch error.
*
* @return string|null
*/
public function getError()
{
return empty($this->info['error']) ? null : $this->info['error'];
}
/**
* Get a header.
*
* @param string $name
*
* @return string|null
*/
public function getHeader($name)
{
$name = strtolower($name);
return isset($this->headers[$name]) ? implode(',', $this->headers[$name]) : null;
}
/**
* Check if the response is valid or not.
*
* @param array $codes
*
* @return bool
*/
public function isValid(array $codes = null)
{
if ($codes === null) {
return $this->statusCode === 200;
}
return in_array($this->statusCode, $codes);
}
}
Embed-3.3.9/src/Http/CurlDispatcher.php 0000664 0000000 0000000 00000016262 13435002260 0017677 0 ustar 00root root 0000000 0000000 'image/jpeg',
'jpeg' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
'mp3' => 'audio/mpeg',
'mp4' => 'video/mp4',
'ogg' => 'audio/ogg',
'ogv' => 'video/ogg',
'webm' => 'video/webm',
];
private $config = [
CURLOPT_MAXREDIRS => 10,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 10,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_ENCODING => '',
CURLOPT_AUTOREFERER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_USERAGENT => 'Embed PHP library',
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
];
/**
* Constructor.
*
* @param array $config
*/
public function __construct(array $config = [])
{
$this->config = $config + $this->config;
if (!isset($this->config[CURLOPT_COOKIEJAR])) {
$cookies = str_replace('//', '/', sys_get_temp_dir().'/embed-cookies.'.uniqid());
if (is_file($cookies)) {
if (!is_writable($cookies)) {
throw new EmbedException(sprintf('The temporary cookies file "%s" is not writable', $cookies));
}
} elseif (!is_writable(dirname($cookies))) {
throw new EmbedException(sprintf('The temporary folder "%s" is not writable', dirname($cookies)));
}
$this->config[CURLOPT_COOKIEJAR] = $cookies;
$this->config[CURLOPT_COOKIEFILE] = $cookies;
}
}
/**
* Return all responses for debug purposes
*
* @return AbstractResponse[]
*/
public function getAllResponses()
{
return $this->responses;
}
/**
* Remove the cookies file on destruct the instance.
*/
public function __destruct()
{
$cookies = $this->config[CURLOPT_COOKIEJAR];
if (is_file($cookies)) {
unlink($cookies);
}
}
/**
* {@inheritdoc}
*/
public function dispatch(Url $url)
{
$options = $this->config;
$extension = $url->getExtension();
if (!empty($extension) && isset(self::$acceptHeaders[$extension])) {
$options[CURLOPT_HTTPHEADER] = ['Accept: '.self::$acceptHeaders[$extension]];
} else {
$options[CURLOPT_HTTPHEADER] = ['Accept: */*'];
}
$response = $this->exec($url, $options);
//Some sites returns 403 with the default user-agent
if ($response->getStatusCode() === 403) {
$options[CURLOPT_USERAGENT] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36';
return $this->exec($url, $options);
}
//Other sites needs a certificate
if (
class_exists('Composer\\CaBundle\\CaBundle')
&& $response->getStatusCode() === 0
&& strpos($response->getError(), 'SSL') !== false
) {
$options[CURLOPT_SSL_VERIFYHOST] = 2;
$options[CURLOPT_SSL_VERIFYPEER] = true;
$options[CURLOPT_CAINFO] = CaBundle::getSystemCaRootBundlePath();
return $this->exec($url, $options);
}
return $response;
}
/**
* Execute a curl request
*
* @param Url $url
* @param array $options
*
* @return Response
*/
protected function exec(Url $url, array $options)
{
$connection = curl_init((string) $url);
curl_setopt_array($connection, $options);
$curl = new CurlResult($connection);
//Get only text responses
$curl->onHeader(function ($name, $value, $data) {
if ($name === 'content-type') {
$data->isBinary = !preg_match('/(text|html|json)/', strtolower($value));
}
});
$curl->onBody(function ($string, stdClass $data) {
return empty($data->isBinary);
});
curl_exec($connection);
$result = $curl->getResult();
curl_close($connection);
return $this->responses[] = new Response(
$url,
Url::create($result['url']),
$result['statusCode'],
$result['contentType'],
$result['content'],
$result['headers'],
$result['info']
);
}
/**
* {@inheritdoc}
*/
public function dispatchImages(array $urls)
{
if (empty($urls)) {
return [];
}
$curl_multi = curl_multi_init();
$responses = [];
$connections = [];
foreach ($urls as $k => $url) {
if ($url->getScheme() === 'data') {
$response = ImageResponse::createFromBase64($url);
if ($response) {
$responses[$k] = $response;
}
continue;
}
$connection = curl_init((string) $url);
$options = $this->config;
$options[CURLOPT_HTTPHEADER] = ['Accept: image/*'];
curl_setopt_array($connection, $options);
curl_multi_add_handle($curl_multi, $connection);
$curl = new CurlResult($connection);
$curl->onBody(function ($body, stdClass $data) {
if (($info = @getimagesizefromstring($body))) {
$data->width = $info[0];
$data->height = $info[1];
$data->mime = $info['mime'];
return false;
}
});
$connections[$k] = $curl;
}
if (!empty($connections)) {
do {
$return = curl_multi_exec($curl_multi, $active);
} while ($return === CURLM_CALL_MULTI_PERFORM);
while ($active && $return === CURLM_OK) {
if (curl_multi_select($curl_multi) === -1) {
usleep(100);
}
do {
$return = curl_multi_exec($curl_multi, $active);
} while ($return === CURLM_CALL_MULTI_PERFORM);
}
foreach ($connections as $k => $connection) {
$resource = $connection->getResource();
curl_multi_remove_handle($curl_multi, $resource);
$result = $connection->getResult();
if (!empty($result['data']->mime)) {
$responses[$k] = $this->responses[] = new ImageResponse(
$urls[$k],
Url::create($result['url']),
$result['statusCode'],
$result['contentType'],
[$result['data']->width, $result['data']->height],
$result['headers'],
$result['info']
);
}
}
}
curl_multi_close($curl_multi);
ksort($responses, SORT_NUMERIC);
return array_values($responses);
}
}
Embed-3.3.9/src/Http/CurlResult.php 0000664 0000000 0000000 00000006071 13435002260 0017064 0 ustar 00root root 0000000 0000000 resource = $resource;
$this->data = (object) [];
curl_setopt($this->resource, CURLOPT_HEADERFUNCTION, [$this, 'headerCallback']);
curl_setopt($this->resource, CURLOPT_WRITEFUNCTION, [$this, 'writeCallback']);
}
/**
* Returns the response result.
*/
public function getResult()
{
$result = curl_getinfo($this->resource);
if (curl_errno($this->resource)) {
$result['error'] = curl_error($this->resource);
}
return [
'url' => isset($result['url']) ? $result['url'] : null,
'statusCode' => isset($result['http_code']) ? $result['http_code'] : null,
'contentType' => isset($result['content_type']) ? $result['content_type'] : null,
'info' => $result,
'content' => $this->body,
'headers' => $this->headers,
'data' => $this->data,
];
}
/**
* Returns the resource.
*
* @return resource
*/
public function getResource()
{
return $this->resource;
}
/**
* Callback used on receive a header.
*
* @param callable $callback
*/
public function onHeader(callable $callback)
{
$this->onHeader = $callback;
}
/**
* Callback used on receive a body string portion.
*
* @param callable $callback
*/
public function onBody(callable $callback)
{
$this->onBody = $callback;
}
/**
* Callback used to collect the headers.
*
* @param resource $resource
* @param string $string
*
* @return int
*/
public function headerCallback($resource, $string)
{
if (!strpos($string, ':')) {
return strlen($string);
}
list($name, $value) = array_map('trim', explode(':', $string, 2));
$name = strtolower($name);
if (!isset($this->headers[$name])) {
$this->headers[$name] = [];
}
$this->headers[$name][] = $value;
if ($this->onHeader === null || call_user_func($this->onHeader, $name, $value, $this->data) !== false) {
return strlen($string);
}
return -1;
}
/**
* Callback used to get the body content.
*
* @param resource $resource
* @param string $string
*
* @return int
*/
public function writeCallback($resource, $string)
{
$this->body .= $string;
if ($this->onBody === null || call_user_func($this->onBody, $this->body, $this->data) !== false) {
return strlen($string);
}
//Cancel
$this->body = null;
return -1;
}
}
Embed-3.3.9/src/Http/DispatcherInterface.php 0000664 0000000 0000000 00000000666 13435002260 0020673 0 ustar 00root root 0000000 0000000 getContent(), 2);
if ((count($pieces) !== 2) || (strpos($pieces[0], 'image/') === false) || (strpos($pieces[1], 'base64,') !== 0)) {
return false;
}
if (($info = @getimagesizefromstring(base64_decode(substr($pieces[1], 7)))) !== false) {
return new self(
$url,
$url,
200,
$info['mime'],
[$info[0], $info[1]],
[],
[]
);
}
}
public function __construct(Url $startingUrl, Url $url, $statusCode, $contentType, $size, array $headers, array $info)
{
parent::__construct($startingUrl, $url, $statusCode, $contentType, $headers, $info);
$this->size = $size;
}
/**
* Get the image width.
*
* @return int
*/
public function getWidth()
{
return (int) $this->size[0];
}
/**
* Get the image height.
*
* @return int
*/
public function getHeight()
{
return (int) $this->size[1];
}
}
Embed-3.3.9/src/Http/Redirects.php 0000664 0000000 0000000 00000004205 13435002260 0016701 0 ustar 00root root 0000000 0000000 'www.google.com/url*',
'googleTranslator' => 'translate.google.com/translate',
'hashBang' => '*#!*',
'spotify' => 'play.spotify.com/*',
'tumblr' => 't.umblr.com/redirect',
];
/**
* Resolve the url redirection.
*
* @param Url $url
*
* @return Url
*/
public static function resolve(Url $url)
{
foreach (self::$patterns as $method => $pattern) {
if ($url->match($pattern)) {
return self::$method($url);
}
}
return $url;
}
/**
* Resolve a google redirection url.
*
* @param Url $url
*
* @return Url
*/
public static function google(Url $url)
{
if (($value = $url->getQueryParameter('url'))) {
return Url::create($value);
}
return $url;
}
/**
* Resolve a google translation url.
*
* @param Url $url
*
* @return Url
*/
public static function googleTranslator(Url $url)
{
if (($value = $url->getQueryParameter('u'))) {
return Url::create($value);
}
return $url;
}
/**
* Resolve an url with hashbang.
*
* @param Url $url
*
* @return Url
*/
public static function hashBang(Url $url)
{
if (($path = preg_replace('|^(/?!)|', '', $url->getFragment()))) {
return $url->withPath($url->getPath().$path);
}
return $url;
}
/**
* Redirect the player of spotify.
*
* @param Url $url
*
* @return Url
*/
public static function spotify(Url $url)
{
return $url->withHost('open.spotify.com');
}
/**
* Redirect the tumblr url
*
* @param Url $url
*
* @return Url
*/
public static function tumblr(Url $url)
{
if (($value = $url->getQueryParameter('z'))) {
return Url::create($value);
}
return $url;
}
}
Embed-3.3.9/src/Http/Response.php 0000664 0000000 0000000 00000011261 13435002260 0016553 0 ustar 00root root 0000000 0000000 setContent($content);
}
/**
* Get the content.
*
* @return string|null
*/
public function getContent()
{
return $this->content;
}
/**
* Get the content as HTML.
*
* @return DOMDocument|false
*/
public function getHtmlContent()
{
if ($this->htmlContent === null) {
try {
if (empty($content = $this->content)) {
return $this->htmlContent = false;
}
$errors = libxml_use_internal_errors(true);
$entities = libxml_disable_entity_loader(true);
$this->htmlContent = new DOMDocument();
if (mb_detect_encoding($content, 'UTF-8', true) === 'UTF-8') {
$content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8');
$content = preg_replace(
'/]*>/',
'',
$content
);
} elseif (mb_detect_encoding($content, 'SJIS', true) === 'SJIS') {
$content = mb_convert_encoding($content, 'HTML-ENTITIES', 'SJIS');
$content = preg_replace('/]*>/', '', $content);
} elseif (mb_detect_encoding($content, 'ISO-8859-1', true) === 'ISO-8859-1') {
$content = mb_convert_encoding($content, 'HTML-ENTITIES', 'ISO-8859-1');
$content = preg_replace('/]*>/', '', $content);
}
$this->htmlContent->loadHTML(trim($content));
libxml_use_internal_errors($errors);
libxml_disable_entity_loader($entities);
} catch (Exception $exception) {
return $this->htmlContent = false;
}
}
return $this->htmlContent;
}
/**
* Get the content as an array from JSON.
*
* @return array|false
*/
public function getJsonContent()
{
if ($this->jsonContent === null) {
try {
if (($content = $this->content) === '') {
return $this->jsonContent = false;
}
$this->jsonContent = json_decode($content, true);
} catch (\Exception $exception) {
return $this->jsonContent = false;
}
}
return $this->jsonContent;
}
/**
* Get the content as XML.
*
* @return SimpleXMLElement|false
*/
public function getXMLContent()
{
if ($this->xmlContent === null) {
try {
if (($content = $this->content) === '') {
return $this->xmlContent = false;
}
$errors = libxml_use_internal_errors(true);
$this->xmlContent = new SimpleXMLElement($content);
libxml_use_internal_errors($errors);
} catch (Exception $exception) {
return $this->xmlContent = false;
}
}
return $this->xmlContent;
}
/**
* Set the response content.
*
* @param string $content
*/
private function setContent($content)
{
$this->content = $content;
if (empty($this->contentType)) {
return;
}
//Remove charset from Content-Type
if (strpos($this->contentType, ';') !== false) {
list($mime, $charset) = array_map('trim', explode(';', $this->contentType));
$this->contentType = $mime;
$charset = str_replace(['"', "'"], '', substr(strstr($charset, '='), 1));
$this->content = Utils::toUtf8($content, trim($charset));
}
}
}
Embed-3.3.9/src/Http/Url.php 0000664 0000000 0000000 00000036623 13435002260 0015530 0 ustar 00root root 0000000 0000000 parseUrl($url);
}
/**
* Returns the url.
*
* @return string
*/
public function __toString()
{
if ($this->url === null) {
return $this->url = $this->buildUrl();
}
return $this->url;
}
/**
* Remove the built url on clone.
*/
public function __clone()
{
$this->url = null;
}
/**
* Check if the url match with a specific pattern. The patterns only accepts * and ?
*
* @param string|array $patterns The pattern or an array with various patterns
*
* @return bool
*/
public function match($patterns)
{
if (!is_array($patterns)) {
$patterns = [$patterns];
}
//Remove scheme and query
$long_url = preg_replace('|^(\w+://)|', '', (string) $this);
$short_url = preg_replace('|(\?.*)?$|', '', $long_url);
foreach ($patterns as $pattern) {
if ($pattern[0] === '?') { // ?hello=world => *?hello=world
$pattern = '*' . $pattern;
}
$pattern = str_replace('\\*', '.*', preg_quote($pattern, '|'));
if (strpos($pattern, '?') === false) {
$url = $short_url;
} else {
$pattern = str_replace('\\?&', '[\\?&]', $pattern);
$url = $long_url;
}
if (preg_match('|^'.$pattern.'$|i', $url)) {
return true;
}
}
return false;
}
/**
* Return the content of the url (for embedded images).
*
* @return string The content or null
*/
public function getContent()
{
return isset($this->info['content']) ? $this->info['content'] : null;
}
/**
* Return the extension of the url (html, php, jpg, etc).
*
* @return string The scheme or null
*/
public function getExtension()
{
return isset($this->info['extension']) ? $this->info['extension'] : null;
}
/**
* Returns a new instance with other relative url.
*
* @param string $url
*
* @return Url
*/
public function createAbsolute($url)
{
return self::create($this->getAbsolute($url));
}
/**
* Returns a clone with other extension.
*
* @param string $extension
*
* @return Url
*/
public function withExtension($extension)
{
$clone = clone $this;
$clone->info['extension'] = $extension;
if (empty($clone->info['file'])) {
$clone->info['file'] = array_pop($clone->info['path']);
}
return $clone;
}
/**
* Return the scheme of the url (for example http, https, ftp, etc).
*
* @return string The scheme or null
*/
public function getScheme()
{
return isset($this->info['scheme']) ? $this->info['scheme'] : null;
}
/**
* Returns a clone with other scheme.
*
* @param string $scheme
*
* @return Url
*/
public function withScheme($scheme)
{
$clone = clone $this;
$clone->info['scheme'] = $scheme;
return $clone;
}
/**
* Return the host of the url (for example: google.com).
*
* @return string The host or null
*/
public function getHost()
{
return isset($this->info['host']) ? $this->info['host'] : null;
}
/**
* Returns a clone with other host.
*
* @param string $host
*
* @return Url
*/
public function withHost($host)
{
$clone = clone $this;
$clone->info['host'] = $host;
return $clone;
}
/**
* Return the domain of the url (for example: google).
*
* @param bool $first_level True to return the first level domain (.com, .es, etc)
*
* @return string
*/
public function getDomain($first_level = false)
{
$host = $this->getHost();
if (empty($host)) {
return '';
}
$host = array_reverse(explode('.', $host));
switch (count($host)) {
case 1:
return $host[0];
case 2:
return $first_level ? ($host[1].'.'.$host[0]) : $host[1];
default:
$tld = $host[1].'.'.$host[0];
$suffixes = self::getSuffixes();
if (in_array($tld, $suffixes, true)) {
return $first_level ? $host[2].'.'.$tld : $host[2];
}
return $first_level ? $host[1].'.'.$host[0] : $host[1];
}
}
/**
* Return a specific directory position in the path of the url.
*
* @param int $position The position of the directory (0 based index)
*
* @return string|null
*/
public function getDirectoryPosition($position)
{
if ($position === count($this->info['path'])) {
return $this->info['file'];
}
return isset($this->info['path'][$position]) ? $this->info['path'][$position] : null;
}
/**
* Returns a clone with other directory in a specific position.
*
* @param int|null $key The position of the subdirectory (0 based index)
* @param string $value The new value
*
* @return Url
*/
public function withDirectoryPosition($key, $value)
{
$clone = clone $this;
$pos = $clone->info['path'];
$hasFile = isset($clone->info['file']);
if ($hasFile) {
$pos[] = $clone->info['file'];
}
$pos[$key] = $value;
if ($hasFile) {
$clone->info['file'] = array_pop($pos);
}
$clone->info['path'] = $pos;
return $clone;
}
/**
* Return all directories.
*
* @return string
*/
public function getDirectories()
{
return !empty($this->info['path']) ? '/'.implode('/', $this->info['path']).'/' : '/';
}
/**
* Slice path.
*
* @param int $offset
* @param int|null $length
*
* @return array
*/
public function getSlicePath($offset, $length = null)
{
$array = explode('/', $this->getPath());
if (empty($array[0])) {
array_shift($array);
}
return array_slice($array, $offset, $length);
}
/**
* Return the url path.
*
* @return string
*/
public function getPath()
{
$path = !empty($this->info['path']) ? '/'.implode('/', array_map('self::urlEncode', $this->info['path'])).'/' : '/';
if (isset($this->info['file'])) {
$path .= self::urlEncode($this->info['file']);
if (isset($this->info['extension'])) {
$path .= '.'.$this->info['extension'];
}
}
return $path;
}
/**
* Returns a clone with other path.
*
* @param string $path
*
* @return Url
*/
public function withPath($path)
{
$clone = clone $this;
$clone->setPath($path);
return $clone;
}
/**
* Returns a clone with path appended.
*
* @param string $path
*
* @return Url
*/
public function withAddedPath($path)
{
$path = $this->getPath().'/'.$path;
return $this->withPath($path);
}
/**
* Check if the url has a query parameter.
*
* @param string $name
*
* @return bool
*/
public function hasQueryParameter($name)
{
return isset($this->info['query'][$name]);
}
/**
* Returns all query parameters.
*
* @return array
*/
public function getQueryParameters()
{
return $this->info['query'];
}
/**
* Returns a query parameter value.
*
* @param string $name
*
* @return string|null
*/
public function getQueryParameter($name)
{
return isset($this->info['query'][$name]) ? $this->info['query'][$name] : null;
}
/**
* Returns a clone with a new query parameter.
*
* @param string $name The parameter name
* @param string $value The parameter value
*
* @return Url
*/
public function withQueryParameter($name, $value)
{
$clone = clone $this;
$clone->info['query'][$name] = $value;
return $clone;
}
/**
* Returns a clone with new query parameters merged.
*
* @param array $parameters
*
* @return Url
*/
public function withAddedQueryParameters(array $parameters)
{
$clone = clone $this;
$clone->info['query'] = empty($clone->info['query']) ? $parameters : array_replace($clone->info['query'], $parameters);
return $clone;
}
/**
* Returns a clone with new query parameters.
*
* @param array $parameters
*
* @return Url
*/
public function withQueryParameters(array $parameters)
{
$clone = clone $this;
$clone->info['query'] = $parameters;
return $clone;
}
/**
* Return the url fragment.
*
* @return string
*/
public function getFragment()
{
return isset($this->info['fragment']) ? $this->info['fragment'] : null;
}
/**
* Return ClassName for domain.
*
* Domains started with numbers will get N prepended to their class name.
*
* @return string
*/
public function getClassNameForDomain()
{
$className = str_replace(array('-', ' '), '', ucwords(strtolower($this->getDomain())));
if (is_numeric(mb_substr($className, 0, 1))) {
$className = 'N'.$className;
}
return $className;
}
/**
* Build the url using the splitted data.
*/
protected function buildUrl()
{
$url = '';
if (isset($this->info['content'])) {
return 'data:'.$this->info['content'];
}
if (isset($this->info['scheme'])) {
$url .= $this->info['scheme'].'://';
}
$user = isset($this->info['user']) ? $this->info['user'] : '';
$pass = isset($this->info['pass']) ? ':'.$this->info['pass'] : '';
if ($user || $pass) {
$url .= $user.$pass.'@';
}
if (isset($this->info['host'])) {
$url .= $this->info['host'];
}
if (isset($this->info['port'])) {
$url .= ':'.$this->info['port'];
}
$url .= $this->getPath();
if (!empty($this->info['query'])) {
$url .= '?'.rtrim(http_build_query($this->info['query']), '=');
}
if (isset($this->info['fragment'])) {
$url .= '#'.$this->info['fragment'];
}
return $url;
}
/**
* Parse an url and split into different pieces.
*
* @param string $url The url to parse
*/
protected function parseUrl($url)
{
$this->info = self::parse($url);
if (isset($this->info['path'])) {
$this->setPath($this->info['path']);
}
if (empty($this->info['query'])) {
$this->info['query'] = [];
return;
}
// Fix dots and other characters used in query's variables names
// https://github.com/oscarotero/Embed/issues/101
$queryString = preg_replace_callback('/(^|(?<=&))[^=[&]+/', function ($key) {
return bin2hex(urldecode($key[0]));
}, $this->info['query']);
parse_str($queryString, $query);
$this->info['query'] = [];
foreach ((array) $query as $key => $value) {
$this->info['query'][hex2bin($key)] = $value;
}
}
/**
* Return an absolute url based in a relative.
*
* @return string
*/
public function getAbsolute($url)
{
$url = trim($url);
if (empty($url)) {
return '';
}
if (preg_match('|^\w+:[^/]|', $url)) {
return $url;
}
if (preg_match('|^\w+://|', $url)) {
return self::validUrlOrEmpty($url);
}
if (strpos($url, '://') === 0) {
return self::validUrlOrEmpty($this->getScheme().$url);
}
if (strpos($url, '//') === 0) {
return self::validUrlOrEmpty($this->getScheme().":$url");
}
if ($url[0] === '/') {
return self::validUrlOrEmpty($this->getScheme().'://'.$this->getHost().$url);
}
return self::validUrlOrEmpty($this->getScheme().'://'.$this->getHost().$this->getDirectories().$url);
}
/**
* Parses and adds path and file value.
*
* @param string $path
*/
private function setPath($path)
{
$this->info['path'] = $this->info['file'] = $this->info['extension'] = $this->info['content'] = null;
if ($this->getScheme() === 'data') {
$this->info['content'] = $path;
return;
}
$file = substr(strrchr($path, '/'), 1);
if (strlen($file)) {
$path = substr($path, 0, -strlen($file));
if (preg_match('/(.*)\.([\w]+)$/', $file, $match)) {
$this->info['file'] = urldecode($match[1]);
$this->info['extension'] = $match[2];
} else {
$this->info['file'] = urldecode($file);
}
}
$this->info['path'] = [];
foreach (explode('/', $path) as $dir) {
$dir = urldecode($dir);
if ($dir !== '') {
$this->info['path'][] = $dir;
}
}
}
private static function getSuffixes()
{
if (self::$public_suffix_list === null) {
self::$public_suffix_list = (@include __DIR__.'/../resources/public_suffix_list.php') ?: [];
}
return self::$public_suffix_list;
}
/**
* UTF-8 compatible parse_url
* http://php.net/manual/en/function.parse-url.php#114817
*
* @param string $url
*
* @return string
*/
private static function parse($url)
{
$enc_url = preg_replace_callback(
'%[^:/@?&=#]+%usD',
function ($matches) {
return urlencode($matches[0]);
},
$url
);
$parts = parse_url($enc_url);
if ($parts === false) {
throw new \InvalidArgumentException('Malformed URL: ' . $url);
}
if (!empty($parts['scheme']) && !in_array($parts['scheme'], ['http', 'https', 'data'])) {
throw new \InvalidArgumentException(sprintf('Invalid URL scheme: "%s"', $parts['scheme']));
}
foreach ($parts as $name => $value) {
$parts[$name] = urldecode($value);
}
return $parts;
}
private static function urlEncode($path)
{
// : - used for files
// @ and , - used for GoogleMaps adapter url (in view and streetview modes)
return str_replace(['%3A','%40','%2C'], [':','@',','], urlencode($path));
}
private static function validUrlOrEmpty($url)
{
return parse_url($url) === false ? '' : $url;
}
}
Embed-3.3.9/src/Providers/ 0000775 0000000 0000000 00000000000 13435002260 0015301 5 ustar 00root root 0000000 0000000 Embed-3.3.9/src/Providers/Api/ 0000775 0000000 0000000 00000000000 13435002260 0016012 5 ustar 00root root 0000000 0000000 Embed-3.3.9/src/Providers/Api/Archive.php 0000664 0000000 0000000 00000003547 13435002260 0020115 0 ustar 00root root 0000000 0000000 getResponse()->getUrl()->withQueryParameter('output', 'json');
$response = $adapter->getDispatcher()->dispatch($endPoint);
if (($json = $response->getJsonContent())) {
$this->bag->set($json);
}
}
/**
* {@inheritdoc}
*/
public function getTitle()
{
return $this->bag->get('metadata[title][0]');
}
/**
* {@inheritdoc}
*/
public function getDescription()
{
return $this->bag->get('metadata[description][0]');
}
/**
* {@inheritdoc}
*/
public function getType()
{
switch ($this->bag->get('metadata[mediatype][0]')) {
case 'movies':
return 'video';
case 'audio':
return 'audio';
case 'texts':
return 'rich';
}
}
/**
* {@inheritdoc}
*/
public function getProviderName()
{
return 'Internet Archive';
}
/**
* {@inheritdoc}
*/
public function getUrl()
{
return $this->normalizeUrl($this->bag->get('url'));
}
/**
* {@inheritdoc}
*/
public function getAuthorName()
{
$this->bag->get('metadata[creator][0]');
}
/**
* {@inheritdoc}
*/
public function getImagesUrls()
{
$images = (array) $this->bag->get('misc[image]');
foreach (array_keys((array) $this->bag->get('files')) as $url) {
$images[] = $url;
}
return $this->normalizeUrls($images);
}
}
Embed-3.3.9/src/Providers/Api/Facebook.php 0000664 0000000 0000000 00000005603 13435002260 0020240 0 ustar 00root root 0000000 0000000 getEndPoint())) {
$response = $adapter->getDispatcher()->dispatch($endPoint);
if ($json = $response->getJsonContent()) {
$this->bag->set($json);
}
}
}
/**
* {@inheritdoc}
*/
public function getTitle()
{
return $this->bag->get('name');
}
/**
* {@inheritdoc}
*/
public function getDescription()
{
return $this->bag->get('description') ?: $this->bag->get('about');
}
/**
* {@inheritdoc}
*/
public function getProviderName()
{
return 'Facebook';
}
/**
* {@inheritdoc}
*/
public function getUrl()
{
return $this->normalizeUrl($this->bag->get('url'));
}
/**
* {@inheritdoc}
*/
public function getAuthorName()
{
return $this->bag->get('username') ?: $this->bag->get('owner[name]');
}
/**
* {@inheritdoc}
*/
public function getImagesUrls()
{
$images = (array) $this->bag->get('cover[source]');
if (($id = $this->bag->get('id'))) {
$images[] = 'https://graph.facebook.com/'.$id.'/picture';
}
return $this->normalizeUrls($images);
}
/**
* {@inheritdoc}
*/
public function getPublishedTime()
{
return $this->bag->get('start_time');
}
/**
* {@inheritdoc}
*/
public function getCode()
{
return $this->bag->get('embed_html', true);
}
/**
* Returns the Graph API Endpoint
*
* @return Url|null
*/
private function getEndPoint()
{
$url = $this->adapter->getResponse()->getUrl();
$key = $this->adapter->getConfig('facebook[key]');
if (empty($key)) {
return;
}
if ($url->getDirectoryPosition(0) === 'events') {
return Url::create('https://graph.facebook.com/')
->withAddedPath($url->getDirectoryPosition(1))
->withQueryParameter('access_token', $key)
->withQueryParameter('fields', $this->adapter->getConfig('facebook[events_fields]'));
}
if ($url->getDirectoryPosition(1) === 'videos') {
return Url::create('https://graph.facebook.com/')
->withAddedPath($url->getDirectoryPosition(2))
->withQueryParameter('access_token', $key)
->withQueryParameter('fields', $this->adapter->getConfig('facebook[videos_fields]'));
}
}
}
Embed-3.3.9/src/Providers/Api/Gist.php 0000664 0000000 0000000 00000002606 13435002260 0017435 0 ustar 00root root 0000000 0000000 getResponse()->getUrl()->withExtension('json');
$response = $adapter->getDispatcher()->dispatch($endPoint);
if (($json = $response->getJsonContent())) {
$this->bag->set($json);
}
}
/**
* {@inheritdoc}
*/
public function getDescription()
{
return $this->bag->get('description');
}
/**
* {@inheritdoc}
*/
public function getType()
{
if ($this->getCode() !== null) {
return 'rich';
}
}
/**
* {@inheritdoc}
*/
public function getAuthorName()
{
return $this->bag->get('owner');
}
/**
* {@inheritdoc}
*/
public function getPublishedTime()
{
return $this->bag->get('created_at');
}
/**
* {@inheritdoc}
*/
public function getCode()
{
if (($code = $this->bag->get('div', true)) && ($stylesheet = $this->normalizeUrl($this->bag->get('stylesheet')))) {
return ''.$code;
}
}
}
Embed-3.3.9/src/Providers/Api/GoogleMaps.php 0000664 0000000 0000000 00000011220 13435002260 0020554 0 ustar 00root root 0000000 0000000 null,
];
/**
* {@inheritdoc}
*/
public function __construct(Adapter $adapter)
{
parent::__construct($adapter);
$mode = $adapter->getResponse()->getUrl()->getDirectoryPosition(1);
// Default is view (if mode is not mentioned in the url)
$this->mode = 'view';
switch ($mode) {
case 'place':
case 'dir':
case 'search':
$this->mode = $mode;
break;
}
// check streetview mode
// simple check,- starts with @, ends with t
if ((substr($mode, 0, 1) === '@') && (substr($mode, -1) === 't')) {
$this->mode = 'streetview';
}
}
/**
* {@inheritdoc}
*/
public function getTitle()
{
$url = $this->adapter->getResponse()->getUrl();
if ($this->mode === 'place') {
return $url->getDirectoryPosition(2);
}
if ($this->mode === 'dir') {
return $url->getDirectoryPosition(2).' / '.$url->getDirectoryPosition(3);
}
}
/**
* {@inheritdoc}
*/
public function getProviderName()
{
return 'Google Maps';
}
/**
* {@inheritdoc}
*/
public function getCode()
{
$url = $this->adapter->getResponse()->getUrl();
$key = $this->adapter->getConfig('google[key]');
if (empty($key)) {
return;
}
switch ($this->mode) {
case 'view':
$pos = self::getPosition($this->mode, $url);
return Utils::iframe($url
->withPath('maps/embed/v1/'.$this->mode)
->withQueryParameters([
'center' => $pos['coordinates'],
'zoom' => $pos['zoom'],
'key' => $key,
]));
case 'streetview':
$pos = self::getPosition($this->mode, $url);
return Utils::iframe($url
->withPath('maps/embed/v1/'.$this->mode)
->withQueryParameters([
'location' => $pos['coordinates'],
'heading' => $pos['heading'],
'pitch' => $pos['pitch'],
'fov' => $pos['fov'],
'key' => $key,
]));
case 'place':
case 'search':
return Utils::iframe($url
->withPath('maps/embed/v1/'.$this->mode)
->withQueryParameters([
'q' => $url->getDirectoryPosition(2),
'key' => $key,
]));
case 'dir':
return Utils::iframe($url
->withPath('maps/embed/v1/directions')
->withQueryParameters([
'origin' => $url->getDirectoryPosition(2),
'destination' => $url->getDirectoryPosition(3),
'key' => $key,
]));
}
}
/**
* Returns parsed position data from url.
*
* @param string $mode The url mode
* @param Url $url
*
* @return array
*/
private static function getPosition($mode, Url $url)
{
// Set defaults
$position = [
'coordinates' => '',
'zoom' => '4',
'heading' => '0',
'pitch' => '0',
'fov' => '90'
];
if ($mode === 'view') {
$pos = explode(",", $url->getDirectoryPosition(1));
$position['coordinates'] = str_replace('@', '', $pos[0]).','.$pos[1];
$position['zoom'] = str_replace('z', "", $pos[2]);
}
if ($mode === 'streetview') {
$pos = explode(",", $url->getDirectoryPosition(1));
$position['coordinates'] = str_replace('@', '', $pos[0]).','.$pos[1];
$position['zoom'] = str_replace('a', '', $pos[2]); // seems not used by google (emulated by other params)
$position['heading'] = str_replace('h', '', $pos[4]);
$position['fov'] = str_replace('y', '', $pos[3]);
$pitch = str_replace('t', '', $pos[5]); // t is pitch but in 180% format
if (is_numeric($pitch)) {
$position['pitch'] = floatval($pitch) - 90;
}
}
return $position;
}
}
Embed-3.3.9/src/Providers/Api/Imageshack.php 0000664 0000000 0000000 00000003667 13435002260 0020573 0 ustar 00root root 0000000 0000000 getResponse()->getUrl()->getDirectoryPosition(1);
$endPoint = Url::create('https://api.imageshack.com/v2/images/'.$id);
$response = $adapter->getDispatcher()->dispatch($endPoint);
if (($json = $response->getJsonContent()) && !empty($json['result'])) {
$this->bag->set($json['result']);
}
}
/**
* {@inheritdoc}
*/
public function getTitle()
{
return $this->bag->get('title');
}
/**
* {@inheritdoc}
*/
public function getDescription()
{
return $this->bag->get('description');
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'photo';
}
/**
* {@inheritdoc}
*/
public function getPublishedTime()
{
return $this->bag->get('creation_date');
}
/**
* {@inheritdoc}
*/
public function getWidth()
{
return $this->bag->get('width');
}
/**
* {@inheritdoc}
*/
public function getHeight()
{
return $this->bag->get('height');
}
/**
* {@inheritdoc}
*/
public function getAuthorName()
{
return $this->bag->get('owner[username]');
}
/**
* {@inheritdoc}
*/
public function getAuthorUrl()
{
$username = $this->getAuthorName();
if (!empty($username)) {
return 'http://imageshack.com/user/'.$username;
}
}
/**
* {@inheritdoc}
*/
public function getImagesUrls()
{
return $this->normalizeUrls($this->bag->get('direct_link'));
}
}
Embed-3.3.9/src/Providers/Api/Soundcloud.php 0000664 0000000 0000000 00000003575 13435002260 0020654 0 ustar 00root root 0000000 0000000 getConfig('soundcloud[key]');
if (!empty($key)) {
$endPoint = Url::create('http://api.soundcloud.com/resolve.json')
->withQueryParameters([
'client_id' => $key,
'url' => (string) $adapter->getResponse()->getUrl(),
]);
$response = $adapter->getDispatcher()->dispatch($endPoint);
if ($json = $response->getJsonContent()) {
$this->bag->set($json);
}
}
}
/**
* {@inheritdoc}
*/
public function getTitle()
{
return $this->bag->get('title');
}
/**
* {@inheritdoc}
*/
public function getDescription()
{
return $this->bag->get('description');
}
/**
* {@inheritdoc}
*/
public function getUrl()
{
return $this->normalizeUrl($this->bag->get('permalink_url'));
}
/**
* {@inheritdoc}
*/
public function getImagesUrls()
{
$images = [];
if (empty($this->bag->get('artwork_url')) && ($img = $this->bag->get('user[avatar_url]'))) {
$images[] = str_replace('-large.jpg', '-t500x500.jpg', $img);
}
return $this->normalizeUrls($images);
}
/**
* {@inheritdoc}
*/
public function getAuthorName()
{
return $this->bag->get('user[username]');
}
/**
* {@inheritdoc}
*/
public function getAuthorUrl()
{
return $this->normalizeUrl($this->bag->get('user[permalink_url]'));
}
}
Embed-3.3.9/src/Providers/Api/Wikipedia.php 0000664 0000000 0000000 00000007172 13435002260 0020440 0 ustar 00root root 0000000 0000000 getResponse()->getUrl()->getDirectoryPosition(1);
if (!empty($titles)) {
//extract images
$endPoint = $adapter->getResponse()->getUrl()
->withPath('/w/api.php')
->withQueryParameters([
'action' => 'query',
'format' => 'json',
'continue' => '',
'titles' => $titles,
'prop' => 'images',
]);
$response = $adapter->getDispatcher()->dispatch($endPoint);
if (($json = $response->getJsonContent())) {
$this->bag->set('images', $json);
}
//extract content
$endPoint = $endPoint
->withQueryParameter('prop', 'extracts')
->withQueryParameter('exchars', 1500);
$response = $adapter->getDispatcher()->dispatch($endPoint);
if (($json = $response->getJsonContent())) {
$this->bag->set('extracts', $json);
}
}
}
/**
* {@inheritdoc}
*/
public function getTitle()
{
$pages = $this->bag->get('extracts[query][pages]');
if (!empty($pages)) {
$page = current($pages);
return strip_tags($page['title']);
}
}
/**
* {@inheritdoc}
*/
public function getDescription()
{
$pages = $this->bag->get('extracts[query][pages]');
if (!empty($pages)) {
return $this->bag->get('extracts[query][pages]['.key($pages).'][extract]');
}
}
/**
* {@inheritdoc}
*/
public function getImagesUrls()
{
$images = [];
$pages = $this->bag->get('images[query][pages]');
if (!empty($pages)) {
$page = current($pages);
$imgs = [];
if (isset($page['images'])) {
foreach ($page['images'] as $image) {
switch (strrchr($image['title'], '.')) {
case '.png':
case '.jpg':
case '.gif':
case '.jpeg':
$imgs[] = $image['title'];
break;
}
}
}
//Get image urls
if (!empty($imgs)) {
$endPoint = $this->adapter->getResponse()->getUrl()
->withPath('/w/api.php')
->withQueryParameters([
'action' => 'query',
'prop' => 'imageinfo',
'iiprop' => 'url',
'format' => 'json',
'continue' => '',
'titles' => implode('|', $imgs),
]);
$response = $this->adapter->getDispatcher()->dispatch($endPoint);
$json = $response->getJsonContent();
if (isset($json['query']['pages'])) {
foreach ($json['query']['pages'] as $page) {
if (isset($page['imageinfo'][0]['url'])) {
$images[] = $page['imageinfo'][0]['url'];
}
}
}
}
}
return $this->normalizeUrls($images);
}
}
Embed-3.3.9/src/Providers/Dcterms.php 0000664 0000000 0000000 00000003151 13435002260 0017413 0 ustar 00root root 0000000 0000000 getResponse()->getHtmlContent())) {
return;
}
foreach ($html->getElementsByTagName('meta') as $meta) {
$name = trim(strtolower($meta->getAttribute('name')));
$value = $meta->getAttribute('content');
if (empty($name) || empty($value)) {
continue;
}
foreach (['dc.', 'dc:', 'dcterms:'] as $prefix) {
if (stripos($name, $prefix) === 0) {
$name = substr($name, strlen($prefix));
$this->bag->set($name, $value);
}
}
}
}
/**
* {@inheritdoc}
*/
public function getTitle()
{
return $this->bag->get('title');
}
/**
* {@inheritdoc}
*/
public function getDescription()
{
return $this->bag->get('description');
}
/**
* {@inheritdoc}
*/
public function getAuthorName()
{
return $this->bag->get('creator') ?: $this->bag->get('author');
}
/**
* {@inheritdoc}
*/
public function getPublishedTime()
{
foreach (['date', 'date.created', 'date.issued'] as $key) {
if ($found = $this->bag->get($key)) {
return $found;
}
}
}
}
Embed-3.3.9/src/Providers/Html.php 0000664 0000000 0000000 00000026347 13435002260 0016732 0 ustar 00root root 0000000 0000000 getResponse()->getHtmlContent())) {
return;
}
$this->extractLinks($html);
$this->extractMetas($html);
$this->extractImages($html);
//Title
$title = $html->getElementsByTagName('title');
if ($title->length) {
$this->bag->set('title', $title->item(0)->nodeValue);
}
}
/**
* {@inheritdoc}
*/
public function getTitle()
{
return $this->bag->get('title');
}
/**
* {@inheritdoc}
*/
public function getDescription()
{
return $this->bag->get('description');
}
/**
* {@inheritdoc}
*/
public function getType()
{
return $this->bag->has('video_src') ? 'video' : null;
}
/**
* {@inheritdoc}
*/
public function getTags()
{
$keywords = $this->bag->get('keywords').','.$this->bag->get('news_keywords');
return array_filter(
array_map('trim', explode(',', $keywords)),
function ($value) {
return !empty($value) && substr($value, -3) !== '...';
}
);
}
/**
* {@inheritdoc}
*/
public function getFeeds()
{
return $this->normalizeUrls($this->bag->get('feeds'));
}
/**
* {@inheritdoc}
*/
public function getCode()
{
$src = $this->normalizeUrl($this->bag->get('video_src'));
if ($src !== null) {
switch ($this->bag->get('video_type')) {
case 'application/x-shockwave-flash':
return Utils::flash($src, $this->getWidth(), $this->getHeight());
}
}
}
/**
* {@inheritdoc}
*/
public function getUrl()
{
return $this->normalizeUrl($this->bag->get('canonical'));
}
/**
* {@inheritdoc}
*/
public function getAuthorName()
{
return $this->bag->get('author') ?: $this->bag->get('article:author') ?: $this->bag->get('contributors');
}
/**
* {@inheritdoc}
*/
public function getProviderIconsUrls()
{
return $this->normalizeUrls($this->bag->get('icons'));
}
/**
* {@inheritdoc}
*/
public function getImagesUrls()
{
$images = $this->normalizeUrls($this->bag->get('images'));
if (!empty($images)) {
$maxImages = $this->adapter->getConfig('html[max_images]', -1);
if ($maxImages > -1) {
return array_slice($images, 0, $maxImages);
}
}
return $images;
}
/**
* {@inheritdoc}
*/
public function getWidth()
{
return ((int) $this->bag->get('video_width')) ?: null;
}
/**
* {@inheritdoc}
*/
public function getHeight()
{
return ((int) $this->bag->get('video_height')) ?: null;
}
/**
* {@inheritdoc}
*/
public function getPublishedTime()
{
$keys = [
'article:published_time',
'created',
'date',
'datepublished',
'datePublished',
'newsrepublic:publish_date',
'pagerender',
'pub_date',
'publication-date',
'publish-date',
'rc.datecreation',
'timestamp',
'article:modified_time',
'eomportal-lastupdate',
'shareaholic:article_published_time',
];
foreach ($keys as $key) {
if ($found = $this->bag->get($key)) {
return $found;
}
}
}
/**
* {@inheritdoc}
*/
public function getLicense()
{
return $this->bag->get('copyright');
}
/**
* {@inheritdoc}
*/
public function getLinkedData()
{
$data = [];
if (!($html = $this->adapter->getResponse()->getHtmlContent())) {
return $data;
}
foreach ($html->getElementsByTagName('script') as $script) {
if ($script->hasAttribute('type') && strtolower($script->getAttribute('type')) === 'application/ld+json') {
$value = trim($script->nodeValue);
if (empty($value)) {
continue;
}
try {
$data[] = json_decode($value);
} catch (Exception $exception) {
continue;
}
}
}
return $data;
}
/**
* Extract information from the elements.
*
* @param DOMDocument $html
*/
private function extractLinks(DOMDocument $html)
{
foreach ($html->getElementsByTagName('link') as $link) {
if ($link->hasAttribute('rel') && $link->hasAttribute('href')) {
$rel = trim(strtolower($link->getAttribute('rel')));
$href = $link->getAttribute('href');
if (empty($href)) {
continue;
}
switch ($rel) {
case 'favicon':
case 'favico':
case 'icon':
case 'shortcut icon':
case 'apple-touch-icon-precomposed':
case 'apple-touch-icon':
$this->bag->add('icons', $href);
break;
case 'image_src':
$this->bag->add('images', $href);
break;
case 'alternate':
switch ($link->getAttribute('type')) {
case 'application/atom+xml':
case 'application/json':
case 'application/rdf+xml':
case 'application/rss+xml':
case 'application/xml':
case 'text/xml':
$this->bag->add('feeds', $href);
break;
}
break;
default:
$this->bag->set($rel, $href);
}
}
}
}
/**
* Extract information from the elements.
*
* @param DOMDocument $html
*/
private function extractMetas(DOMDocument $html)
{
foreach ($html->getElementsByTagName('meta') as $meta) {
$value = $meta->getAttribute('content');
if (empty($value)) {
continue;
}
if ($meta->hasAttribute('name')) {
$name = trim(strtolower($meta->getAttribute('name')));
switch ($name) {
case 'msapplication-tileimage':
$this->bag->add('icons', $value);
continue 2;
default:
$this->bag->set($name, $value);
continue 2;
}
}
if ($meta->hasAttribute('itemprop')) {
$this->bag->set($meta->getAttribute('itemprop'), $value);
}
if ($meta->hasAttribute('http-equiv')) {
$this->bag->set($meta->getAttribute('http-equiv'), $value);
}
if ($meta->hasAttribute('property')) {
$this->bag->set($meta->getAttribute('property'), $value);
}
}
}
/**
* Extract
elements.
*
* @param DOMDocument $html
*/
private function extractImages(DOMDocument $html)
{
if ($this->adapter->getConfig('html[max_images]') === 0) {
return;
}
//Extract only from the main element
$main = self::getMainElement($html);
if (!$main) {
return;
}
$url = $this->adapter->getResponse()->getUrl();
$externalImages = $this->adapter->getConfig('html[external_images]');
foreach ($main->getElementsByTagName('img') as $img) {
if (!$img->hasAttribute('src')) {
continue;
}
try {
$src = $url->createAbsolute($img->getAttribute('src'));
} catch (Exception $exception) {
continue;
}
//Avoid external images
if (!self::imageIsValid($src, $url, $externalImages)) {
continue;
}
$parent = $img->parentNode;
//The image is in a link
while ($parent && isset($parent->tagName)) {
if ($parent->tagName === 'a') {
//The link is external
if ($parent->hasAttribute('href')) {
try {
$href = $url->createAbsolute($parent->getAttribute('href'));
} catch (Exception $exception) {
continue 2;
}
if (!self::imageIsValid($href, $url, $externalImages)) {
continue 2;
}
}
//The link has rel=nofollow
if ($parent->hasAttribute('rel') && (string) $parent->getAttribute('rel') === 'nofollow') {
continue 2;
}
break;
}
$parent = $parent->parentNode;
}
$this->bag->add('images', (string) $src);
}
}
/**
* Check whether a image url is valid or not.
*
* @param Url $url
* @param Url $baseUrl
* @param mixed $externalImages
*
* @return bool
*/
private static function imageIsValid(Url $url, Url $baseUrl, $externalImages)
{
//base64 or same domain
if ($url->getContent() !== null || $url->getDomain() === $baseUrl->getDomain()) {
return true;
}
return is_bool($externalImages) ? $externalImages : $url->match($externalImages);
}
/**
* Returns the main element of the document.
*
* @param DOMDocument $html
*
* @return DOMElement
*/
private static function getMainElement(DOMDocument $html)
{
//
$content = $html->getElementsByTagName('main');
if ($content->length !== 0) {
return $content->item(0);
}
// Popular ids: #main, #content, #page
$content = $html->getElementById('main') ?: $html->getElementById('content') ?: $html->getElementById('page');
if ($content) {
return $content;
}
// Wordpress ids: #post-*
foreach ($html->getElementsByTagName('article') as $article) {
if ($article->hasAttribute('id') && (strpos($article->getAttribute('id'), 'post-') === 0)) {
return $article;
}
}
// Returns or
return $html->getElementsByTagName('body')->item(0) ?: $html->getElementsByTagName('html')->item(0);
}
}
Embed-3.3.9/src/Providers/Linkpulse.php 0000664 0000000 0000000 00000004340 13435002260 0017761 0 ustar 00root root 0000000 0000000 getResponse()->getHtmlContent())) {
return;
}
foreach ($html->getElementsByTagName('meta') as $meta) {
$name = trim(strtolower($meta->getAttribute('property')));
$value = $meta->getAttribute('content');
if (empty($name)) {
$name = trim(strtolower($meta->getAttribute('name')));
}
if (empty($name) || empty($value)) {
continue;
}
if (strpos($name, 'lp:') === 0) {
$name = substr($name, 3);
} elseif (strpos($name, 'lp.article:') !== 0) {
continue;
}
$this->bag->set($name, $value);
}
}
/**
* {@inheritdoc}
*/
public function getTitle()
{
return $this->bag->get('title');
}
/**
* {@inheritdoc}
*/
public function getDescription()
{
return $this->bag->get('description');
}
/**
* {@inheritdoc}
*/
public function getUrl()
{
$url = $this->normalizeUrl($this->bag->get('url'));
if ($url !== $this->adapter->getResponse()->getUrl()->getAbsolute('/')) {
return $url;
}
}
/**
* {@inheritdoc}
*/
public function getTags()
{
return (array) $this->bag->get('article.section') ?: [];
}
/**
* {@inheritdoc}
*/
public function getAuthorName()
{
return $this->bag->get('article.author');
}
/**
* {@inheritdoc}
*/
public function getImagesUrls()
{
return $this->normalizeUrls((array) $this->bag->get('image'));
}
/**
* {@inheritdoc}
*/
public function getPublishedTime()
{
return $this->bag->get('article.published_time')
?: $this->bag->get('article.modified_time');
}
}
Embed-3.3.9/src/Providers/OEmbed.php 0000664 0000000 0000000 00000013060 13435002260 0017145 0 ustar 00root root 0000000 0000000 getEndPoint();
if ($endPoint) {
$this->extractOembed($adapter->getDispatcher()->dispatch($endPoint));
}
}
/**
* {@inheritdoc}
*/
public function getTitle()
{
return $this->bag->get('title');
}
/**
* {@inheritdoc}
*/
public function getDescription()
{
return $this->bag->get('description');
}
/**
* {@inheritdoc}
*/
public function getType()
{
$type = $this->bag->get('type');
if (strpos($type, ':') !== false) {
$type = substr(strrchr($type, ':'), 1);
}
switch ($type) {
case 'video':
case 'photo':
case 'link':
case 'rich':
return $type;
case 'movie':
return 'video';
}
}
/**
* {@inheritdoc}
*/
public function getTags()
{
if ($this->bag->has('meta[keywords]')) {
//it means we are using iframe.ly api
return array_map('trim', explode(',', $this->bag->get('meta[keywords]')));
}
return [];
}
/**
* {@inheritdoc}
*/
public function getCode()
{
return $this->bag->get('html', true);
}
/**
* {@inheritdoc}
*/
public function getUrl()
{
if ($this->getType() === 'photo') {
return $this->normalizeUrl($this->bag->get('web_page'));
}
return $this->normalizeUrl($this->bag->get('url') ?: $this->bag->get('web_page'));
}
/**
* {@inheritdoc}
*/
public function getAuthorName()
{
return $this->bag->get('author_name');
}
/**
* {@inheritdoc}
*/
public function getAuthorUrl()
{
return $this->normalizeUrl($this->bag->get('author_url'));
}
/**
* {@inheritdoc}
*/
public function getProviderName()
{
return $this->bag->get('provider_name');
}
/**
* {@inheritdoc}
*/
public function getProviderUrl()
{
return $this->normalizeUrl($this->bag->get('provider_url'));
}
/**
* {@inheritdoc}
*/
public function getImagesUrls()
{
$images = [];
if ($this->getType() === 'photo') {
$images[] = $this->bag->get('url');
}
foreach (['image', 'thumbnail', 'thumbnail_url'] as $type) {
if ($this->bag->has($type)) {
$ret = $this->bag->get($type);
if (is_array($ret)) {
$images = array_merge($images, $ret);
} else {
$images[] = $ret;
}
}
}
return $this->normalizeUrls($images);
}
/**
* {@inheritdoc}
*/
public function getWidth()
{
return $this->bag->get('width');
}
/**
* {@inheritdoc}
*/
public function getHeight()
{
return $this->bag->get('height');
}
/**
* {@inheritdoc}
*/
public function getLicense()
{
return $this->bag->get('license_url');
}
/**
* @return Url|null
*/
private function getEndPoint()
{
//Search using the domain
$class = 'Embed\\Providers\\OEmbed\\'.$this->adapter->getResponse()->getUrl()->getClassNameForDomain();
$extraParameters = (array) $this->adapter->getConfig('oembed[parameters]');
if (class_exists($class)) {
$endPoint = $class::create($this->adapter);
if ($endPoint && ($url = $endPoint->getEndPoint())) {
return $url->withAddedQueryParameters($extraParameters);
}
}
//Search in the DOM
$endPoint = OEmbed\DOM::create($this->adapter);
if ($endPoint && ($url = $endPoint->getEndPoint())) {
return $url->withAddedQueryParameters($extraParameters);
}
//Try with embedly
$endPoint = OEmbed\Embedly::create($this->adapter);
if ($endPoint && ($url = $endPoint->getEndPoint())) {
return $url->withAddedQueryParameters($extraParameters);
}
//Try with iframely
$endPoint = OEmbed\Iframely::create($this->adapter);
if ($endPoint && ($url = $endPoint->getEndPoint())) {
return $url->withAddedQueryParameters($extraParameters);
}
}
/**
* Save the oembed data in the bag.
*
* @param Response $response
*/
private function extractOembed(Response $response)
{
// extract from xml
if (($response->getUrl()->getExtension() === 'xml') || ($response->getUrl()->getQueryParameter('format') === 'xml')) {
if ($xml = $response->getXmlContent()) {
foreach ($xml as $element) {
$content = trim((string) $element);
if (stripos($content, 'bag->set($element->getName(), $content);
}
}
// extract from json
} else {
if (($json = $response->getJsonContent()) && empty($json['Error'])) {
$this->bag->set($json);
}
}
}
}
Embed-3.3.9/src/Providers/OEmbed/ 0000775 0000000 0000000 00000000000 13435002260 0016434 5 ustar 00root root 0000000 0000000 Embed-3.3.9/src/Providers/OEmbed/Amcharts.php 0000664 0000000 0000000 00000000347 13435002260 0020713 0 ustar 00root root 0000000 0000000 getResponse());
}
/**
* Construct.
*
* @param Response $response
*/
protected function __construct(Response $response)
{
$this->response = $response;
}
/**
* Returns the oembed endPoint.
*
* @return Url|null
*/
public function getEndPoint()
{
$html = $this->response->getHtmlContent();
if ($html && ($url = self::getEndPointFromDom($html))) {
try {
$endPoint = $this->response->getUrl()->createAbsolute($url);
} catch (Exception $exception) {
return null;
}
if ($endPoint->getExtension() !== 'xml' && !$endPoint->hasQueryParameter('format')) {
return $endPoint->withQueryParameter('format', 'json');
}
return $endPoint;
}
}
/**
* Extract oembed information from the elements
* Note: Some sites use instead.
*
* @param DOMDocument $html
*
* @return string|null
*/
protected static function getEndPointFromDom(DOMDocument $html)
{
foreach (['link', 'meta'] as $tagName) {
foreach ($html->getElementsByTagName($tagName) as $link) {
$rel = trim(strtolower($link->getAttribute('rel')));
$href = $link->getAttribute('href');
if (empty($href)) {
continue;
}
if ($rel === 'alternate') {
switch (strtolower($link->getAttribute('type'))) {
case 'application/json+oembed':
case 'application/xml+oembed':
case 'text/json+oembed':
case 'text/xml+oembed':
return $href;
}
}
}
}
}
}
Embed-3.3.9/src/Providers/OEmbed/Dailymotion.php 0000664 0000000 0000000 00000000357 13435002260 0021442 0 ustar 00root root 0000000 0000000 withQueryParameters([
'url' => (string) $this->response->getUrl(),
'format' => 'json',
'for' => 'embed',
]);
}
}
Embed-3.3.9/src/Providers/OEmbed/Dotsub.php 0000664 0000000 0000000 00000000344 13435002260 0020406 0 ustar 00root root 0000000 0000000 getConfig('oembed[embedly_key]');
if (!empty($key)) {
return new static($adapter->getResponse(), $key);
}
}
/**
* Constructor.
*
* @param Response $response
* @param string $key
*/
protected function __construct(Response $response, $key)
{
$this->response = $response;
$this->key = $key;
}
/**
* {@inheritdoc}
*/
public function getEndPoint()
{
return Url::create('http://api.embed.ly/1/oembed')
->withQueryParameters([
'url' => (string) $this->response->getUrl(),
'format' => 'json',
'key' => $this->key,
]);
}
}
Embed-3.3.9/src/Providers/OEmbed/EndPoint.php 0000664 0000000 0000000 00000001775 13435002260 0020677 0 ustar 00root root 0000000 0000000 getResponse();
if ($response->getUrl()->match(static::$pattern)) {
return new static($response);
}
}
/**
* Constructor.
*
* @param Response $response
*/
protected function __construct(Response $response)
{
$this->response = $response;
}
/**
* {@inheritdoc}
*/
public function getEndPoint()
{
return Url::create(static::$endPoint)
->withQueryParameters([
'url' => (string) $this->response->getUrl(),
'format' => 'json',
]);
}
}
Embed-3.3.9/src/Providers/OEmbed/EndPointInterface.php 0000664 0000000 0000000 00000000753 13435002260 0022513 0 ustar 00root root 0000000 0000000 response->getUrl()->match(['*/videos/*', '/video.php'])) {
$endPoint = Url::create('https://www.facebook.com/plugins/video/oembed.json');
} else {
$endPoint = Url::create('https://www.facebook.com/plugins/post/oembed.json');
}
return $endPoint->withQueryParameters([
'url' => (string) $this->response->getUrl(),
'format' => 'json',
]);
}
}
Embed-3.3.9/src/Providers/OEmbed/Flickr.php 0000664 0000000 0000000 00000000343 13435002260 0020357 0 ustar 00root root 0000000 0000000 getConfig('oembed[iframely_key]');
if (!empty($key)) {
return new static($adapter->getResponse(), $key);
}
}
/**
* Constructor.
*
* @param Response $response
* @param string $key
*/
protected function __construct(Response $response, $key)
{
$this->response = $response;
$this->key = $key;
}
/**
* {@inheritdoc}
*/
public function getEndPoint()
{
return Url::create('http://open.iframe.ly/api/oembed')
->withQueryParameters([
'url' => (string) $this->response->getUrl(),
'format' => 'json',
'api_key' => $this->key,
]);
}
}
Embed-3.3.9/src/Providers/OEmbed/Imgur.php 0000664 0000000 0000000 00000000402 13435002260 0020224 0 ustar 00root root 0000000 0000000 response->getUrl()->withScheme('https');
return Url::create(static::$endPoint)
->withQueryParameters([
'url' => (string) $url,
]);
}
}
Embed-3.3.9/src/Providers/OEmbed/Instagram.php 0000664 0000000 0000000 00000001176 13435002260 0021077 0 ustar 00root root 0000000 0000000 response->getUrl()->withScheme('http');
return Url::create(static::$endPoint)
->withQueryParameters([
'url' => (string) $url,
'format' => 'json',
]);
}
}
Embed-3.3.9/src/Providers/OEmbed/Jsbin.php 0000664 0000000 0000000 00000001117 13435002260 0020212 0 ustar 00root root 0000000 0000000 response->getUrl()->withDirectoryPosition(2, 'embed');
return Url::create(static::$endPoint)
->withQueryParameters([
'url' => (string) $url,
'format' => 'json',
]);
}
}
Embed-3.3.9/src/Providers/OEmbed/Kickstarter.php 0000664 0000000 0000000 00000000366 13435002260 0021440 0 ustar 00root root 0000000 0000000 response->getUrl()->withDirectoryPosition(0, 'doc');
return Url::create(static::$endPoint)
->withQueryParameters([
'url' => (string) $url,
'format' => 'json',
]);
}
}
Embed-3.3.9/src/Providers/OEmbed/Shoudio.php 0000664 0000000 0000000 00000000335 13435002260 0020560 0 ustar 00root root 0000000 0000000 withQueryParameters([
'url' => (string) $this->response->getUrl()->withQueryParameters([]),
'format' => 'json'
]);
}
}
Embed-3.3.9/src/Providers/OEmbed/Tumblr.php 0000664 0000000 0000000 00000001523 13435002260 0020413 0 ustar 00root root 0000000 0000000 getResponse();
if ($response->getStartingUrl()->match(static::$pattern)) {
return new static($response);
}
}
/**
* {@inheritdoc}
*/
public function getEndPoint()
{
return Url::create(static::$endPoint)
->withQueryParameters([
'url' => (string) $this->response->getStartingUrl()
]);
}
}
Embed-3.3.9/src/Providers/OEmbed/Twitter.php 0000664 0000000 0000000 00000000367 13435002260 0020615 0 ustar 00root root 0000000 0000000 getResponse()->getHtmlContent())) {
return;
}
foreach ($html->getElementsByTagName('meta') as $meta) {
$name = trim(strtolower($meta->getAttribute('property')));
$value = $meta->getAttribute('content');
if (empty($name)) {
$name = trim(strtolower($meta->getAttribute('name')));
}
if (empty($name) || empty($value)) {
continue;
}
if (strpos($name, 'og:') === 0) {
$name = substr($name, 3);
} elseif (
strpos($name, 'article:') !== 0
&& strpos($name, 'image:') !== 0
&& strpos($name, 'video:') !== 0
&& strpos($name, 'book:') !== 0
&& strpos($name, 'music:') !== 0
&& strpos($name, 'profile:') !== 0
) {
continue;
}
switch ($name) {
case 'image':
case 'image:url':
case 'image:secure_url':
$this->bag->add('images', $value);
break;
case 'article:tag':
case 'video:tag':
case 'book:tag':
$this->bag->add('tags', $value);
break;
default:
$this->bag->set($name, $value);
}
}
}
/**
* {@inheritdoc}
*/
public function getTitle()
{
return $this->bag->get('title');
}
/**
* {@inheritdoc}
*/
public function getDescription()
{
return $this->bag->get('description');
}
/**
* {@inheritdoc}
*/
public function getType()
{
$type = $this->bag->get('type');
if (strpos($type, ':') !== false) {
$type = substr(strrchr($type, ':'), 1);
}
switch ($type) {
case 'video':
case 'photo':
case 'link':
case 'rich':
return $type;
case 'article':
return 'link';
}
if ($this->bag->has('video')) {
return 'video';
}
}
/**
* {@inheritdoc}
*/
public function getCode()
{
$names = ['video:secure_url', 'video:url', 'video'];
foreach ($names as $name) {
if ($this->bag->has($name)) {
$video = $this->normalizeUrl($this->bag->get($name));
if (!($videoPath = parse_url($video, PHP_URL_PATH)) || !($type = pathinfo($videoPath, PATHINFO_EXTENSION))) {
$type = $this->bag->get('video:type');
}
switch ($type) {
case 'swf':
case 'application/x-shockwave-flash':
return Utils::flash($video, $this->getWidth(), $this->getHeight());
case 'mp4':
case 'ogg':
case 'ogv':
case 'webm':
case 'application/mp4':
case 'video/mp4':
case 'video/ogg':
case 'video/ogv':
case 'video/webm':
$images = $this->getImagesUrls();
return Utils::videoHtml(current($images), $video, $this->getWidth(), $this->getHeight());
case 'text/html':
return Utils::iframe($video, $this->getWidth(), $this->getHeight());
}
}
}
}
/**
* {@inheritdoc}
*/
public function getUrl()
{
return $this->normalizeUrl($this->bag->get('url'));
}
/**
* {@inheritdoc}
*/
public function getTags()
{
return (array) $this->bag->get('tags') ?: [];
}
/**
* {@inheritdoc}
*/
public function getAuthorName()
{
return $this->bag->get('article:author') ?: $this->bag->get('book:author');
}
/**
* {@inheritdoc}
*/
public function getProviderName()
{
return $this->bag->get('site_name');
}
/**
* {@inheritdoc}
*/
public function getImagesUrls()
{
return $this->normalizeUrls($this->bag->get('images'));
}
/**
* {@inheritdoc}
*/
public function getWidth()
{
return $this->bag->get('image:width') ?: $this->bag->get('video:width');
}
/**
* {@inheritdoc}
*/
public function getHeight()
{
return $this->bag->get('image:height') ?: $this->bag->get('video:height');
}
/**
* {@inheritdoc}
*/
public function getPublishedTime()
{
return $this->bag->get('article:published_time')
?: $this->bag->get('article:modified_time')
?: $this->bag->get('video:release_date')
?: $this->bag->get('music:release_date');
}
/**
* {@inheritdoc}
*/
public function getProviderUrl()
{
return $this->bag->get('website');
}
}
Embed-3.3.9/src/Providers/Provider.php 0000664 0000000 0000000 00000005426 13435002260 0017613 0 ustar 00root root 0000000 0000000 bag = new Bag();
$this->adapter = $adapter;
}
/**
* Returns the bag containing all data.
*
* @return Bag
*/
public function getBag()
{
return $this->bag;
}
/**
* {@inheritdoc}
*/
public function getTitle()
{
}
/**
* {@inheritdoc}
*/
public function getDescription()
{
}
/**
* {@inheritdoc}
*/
public function getType()
{
}
/**
* {@inheritdoc}
*/
public function getTags()
{
return [];
}
/**
* {@inheritdoc}
*/
public function getFeeds()
{
return [];
}
/**
* {@inheritdoc}
*/
public function getCode()
{
}
/**
* {@inheritdoc}
*/
public function getUrl()
{
}
/**
* {@inheritdoc}
*/
public function getAuthorName()
{
}
/**
* {@inheritdoc}
*/
public function getAuthorUrl()
{
}
/**
* {@inheritdoc}
*/
public function getProviderIconsUrls()
{
return [];
}
/**
* {@inheritdoc}
*/
public function getProviderName()
{
}
/**
* {@inheritdoc}
*/
public function getProviderUrl()
{
}
/**
* {@inheritdoc}
*/
public function getImagesUrls()
{
return [];
}
/**
* {@inheritdoc}
*/
public function getWidth()
{
}
/**
* {@inheritdoc}
*/
public function getHeight()
{
}
/**
* {@inheritdoc}
*/
public function getPublishedTime()
{
}
/**
* {@inheritdoc}
*/
public function getLicense()
{
}
/**
* {@inheritdoc}
*/
public function getLinkedData()
{
return [];
}
/**
* Returns the urls as absolute.
*
* @param mixed $urls
*
* @return array
*/
protected function normalizeUrls($urls)
{
if (!is_array($urls)) {
return [];
}
return array_map([$this, 'normalizeUrl'], array_filter($urls));
}
/**
* Returns the url as absolute.
*
* @param string|null $url
*
* @return string|null
*/
protected function normalizeUrl($url)
{
if (empty($url)) {
return;
}
return $this->adapter->getResponse()->getUrl()->getAbsolute($url);
}
}
Embed-3.3.9/src/Providers/Sailthru.php 0000664 0000000 0000000 00000002615 13435002260 0017611 0 ustar 00root root 0000000 0000000 getResponse()->getHtmlContent())) {
return;
}
foreach ($html->getElementsByTagName('meta') as $meta) {
$name = trim(strtolower($meta->getAttribute('name')));
$value = $meta->getAttribute('content');
if (empty($name) || empty($value)) {
continue;
}
if (strpos($name, 'sailthru.') === 0) {
$this->bag->set(substr($name, 9), $value);
}
}
}
/**
* {@inheritdoc}
*/
public function getImagesUrls()
{
$images = [];
foreach ($this->bag->getKeys() as $name) {
if (strpos($name, 'image') !== false) {
$images[] = $this->bag->get($name);
}
}
return $this->normalizeUrls($images);
}
/**
* {@inheritdoc}
*/
public function getAuthorName()
{
return $this->bag->get('author');
}
/**
* {@inheritdoc}
*/
public function getPublishedTime()
{
return $this->bag->get('date');
}
}
Embed-3.3.9/src/Providers/TwitterCards.php 0000664 0000000 0000000 00000005613 13435002260 0020436 0 ustar 00root root 0000000 0000000 getResponse()->getHtmlContent())) {
return;
}
foreach ($html->getElementsByTagName('meta') as $meta) {
$name = trim(strtolower($meta->getAttribute('name')));
$value = $meta->getAttribute('content') ?: $meta->getAttribute('value');
if (empty($name) || empty($value)) {
continue;
}
if (strpos($name, 'twitter:') === 0) {
$name = substr($name, 8);
if ($name === 'image' || $name === 'image:src') {
$this->bag->add('images', $value);
} else {
$this->bag->set($name, $value);
}
}
}
}
/**
* {@inheritdoc}
*/
public function getTitle()
{
return $this->bag->get('title');
}
/**
* {@inheritdoc}
*/
public function getDescription()
{
return $this->bag->get('description');
}
/**
* {@inheritdoc}
*/
public function getType()
{
$type = $this->bag->get('card');
if (strpos($type, ':') !== false) {
$type = substr(strrchr($type, ':'), 1);
}
switch ($type) {
case 'summary':
case 'summary_large_image':
case 'app':
return 'rich';
case 'player':
return 'video';
}
}
/**
* {@inheritdoc}
*/
public function getCode()
{
$src = $this->normalizeUrl($this->bag->get('player'));
if ($src !== null) {
return Utils::iframe($src, $this->getWidth(), $this->getHeight());
}
}
/**
* {@inheritdoc}
*/
public function getUrl()
{
return $this->normalizeUrl($this->bag->get('url'));
}
/**
* {@inheritdoc}
*/
public function getAuthorName()
{
return $this->bag->get('creator');
}
/**
* {@inheritdoc}
*/
public function getAuthorUrl()
{
$author = $this->getAuthorName();
if (!empty($author)) {
return 'https://twitter.com/'.ltrim($author, '@');
}
}
/**
* {@inheritdoc}
*/
public function getImagesUrls()
{
return $this->normalizeUrls($this->bag->get('images'));
}
/**
* {@inheritdoc}
*/
public function getWidth()
{
return $this->bag->get('player:width');
}
/**
* {@inheritdoc}
*/
public function getHeight()
{
return $this->bag->get('player:height');
}
}
Embed-3.3.9/src/Utils.php 0000664 0000000 0000000 00000015016 13435002260 0015140 0 ustar 00root root 0000000 0000000 element.
*
* @param string $poster Poster attribute
* @param string|array $sources Video sources
* @param int $width Width attribute
* @param int $height Height attribute
*
* @return string
*/
public static function videoHtml($poster, $sources, $width = 0, $height = 0)
{
$code = self::element('video', [
'poster' => ($poster ?: null),
'width' => ($width ?: null),
'height' => ($height ?: null),
'controls' => true,
]);
foreach ((array) $sources as $source) {
$code .= self::element('source', ['src' => $source]);
}
return $code.'';
}
/**
* Creates an