diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc8781f --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# Created by .ignore support plugin (hsz.mobi) +.idea +index.php +composer.lock +Dockerfile +vendor \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 7beed77..1fe0c81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,12 +4,17 @@ sudo: false # Setup build matrix language: php php: - - 5.3 - 5.4 - 5.5 - 5.6 - 7.0 - - hhvm + - 7.1 + - 7.2 + +matrix: + include: + - php: 5.3 + dist: precise # Dependencies before_install: diff --git a/README.md b/README.md index a7ade0e..9d31cc8 100644 --- a/README.md +++ b/README.md @@ -66,72 +66,13 @@ echo $video->getLargestThumbnail(); ## Registering your own service video (it's easy !) If you want to register an implementation of some service your class just needs to implement the "RicardoFiorani\Adapter\VideoAdapterInterface" or extend the RicardoFiorani\Adapter\AbstractServiceAdapter -A Fully functional example can be found [Here](https://github.com/ricardofiorani/php-video-url-parser/tree/master/example/RegisteringANewService.md). +A Fully functional example can be found [Here](https://github.com/ricardofiorani/php-video-url-parser/tree/master/documentation/RegisteringANewService.md). PS: If you've made your awesome implementation of some well known service, feel free to send a Pull Request. All contributions are welcome :) ## Using your own framework's template engine -In this project I've used a simple renderer (which just does an echo of an iframe) but you can use your own implementation. It must follow the RicardoFiorani\Renderer\EmbedRendererInterface and just like that. +A Fully functional example can be found [Here](https://github.com/ricardofiorani/php-video-url-parser/tree/master/documentation/IntegratingYourOwnRenderer.md). -Here's an example: -### My Example Renderer Class -```php -namespace MyVendor\MyRenderer; - - -class MyOwnRenderer implements \RicardoFiorani\Renderer\EmbedRendererInterface -{ - - /** - * @param string $embedUrl - * @param integer $height - * @param integer $width - * @return string - */ - public function render($embedUrl, $height, $width) - { - //Just for example porpoises - return "Hell yeah baby, you've rendered: ".addslashes($embedUrl); - - //A functional example would be like - //return ''; - } -} -``` -### My Example Renderer Factory Class -```php -namespace MyVendor\MyRenderer\Factory; - -class MyOwnRendererFactory implements RendererFactoryInterface -{ - /** - * @return EmbedRendererInterface - */ - public function __invoke() - { - return new MyOwnRenderer(); - } -} -``` -### Registering my renderer - -```php -getServiceContainer()->setRenderer('MyOwnRenderer', 'MyVendor\\MyRenderer\\Factory\\MyOwnRendererFactory'); - -$video = $vsm->parse('https://www.youtube.com/watch?v=PkOcm_XaWrw'); - -//This will output "Hell yeah baby, you've rendered: http://www.youtube.com/embed/PkOcm_XaWrw" -echo $video->getEmbedCode(500,500); - -``` ### Currently Suported Services * Youtube @@ -139,5 +80,14 @@ echo $video->getEmbedCode(500,500); * Dailymotion * Facebook Videos - +### Currently Supported PHP Versions +* PHP 5.3 +* PHP 5.4 +* PHP 5.5 +* PHP 5.6 +* PHP 7.0 +* PHP 7.1 +* PHP 7.2 + +> Please note that even this lib is not passing tests on HHVM, we can't guarantee. Please use it on your own risk. diff --git a/composer.json b/composer.json index 8988897..d0c4485 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "ricardofiorani/php-video-url-parser", - "description": "PHP Video URL Parser is a simple video url parser.", + "description": "A Simple and efficient PHP Video URL Parser that gives you thumbnails and embed codes for various services as Youtube, Vimeo, DailyMotion and Facebook", "require-dev": { "phpunit/phpunit": "^4.8", "fabpot/php-cs-fixer" : ">= 1.0" diff --git a/documentation/IntegratingYourOwnRenderer.md b/documentation/IntegratingYourOwnRenderer.md new file mode 100644 index 0000000..a256b40 --- /dev/null +++ b/documentation/IntegratingYourOwnRenderer.md @@ -0,0 +1,77 @@ +# Functional Example of Integrating your own renderer +In this project I've used a simple renderer (which just does an echo of an iframe) but you can use your own implementation. +First, It must follow the RicardoFiorani\Renderer\EmbedRendererInterface interface. + +Basically you need two classes: + +* The Renderer Implementation +* The Renderer's Factory + +The examples can be seem below: + +### My Renderer Implementation Class +This is the concrete implementation on how your renderer is going to handle the embed URL to give you an embed code. +In here you can inject any dependency you might need by the constructor and add any logic you need. +Please note that it should implement the interface "\RicardoFiorani\Renderer\EmbedRendererInterface". +```php +'; + } +} +``` +### My Renderer Implementation Factory Class +This is the Factory of your renderer, basically all it must do is to implement the interface RicardoFiorani\Renderer\Factory\RendererFactoryInterface +```php +getServiceContainer()->setRenderer('MyOwnRenderer', MyVendor\MyRenderer\Factory\MyOwnRendererFactory::class); + +$video = $vsm->parse('https://www.youtube.com/watch?v=PkOcm_XaWrw'); + +//This will output "Hello, I'm embedding http://www.youtube.com/embed/PkOcm_XaWrw" +echo $video->getEmbedCode(500,500); +``` diff --git a/example/RegisteringANewService.md b/documentation/RegisteringANewService.md similarity index 64% rename from example/RegisteringANewService.md rename to documentation/RegisteringANewService.md index 4c7b4aa..d9798d5 100644 --- a/example/RegisteringANewService.md +++ b/documentation/RegisteringANewService.md @@ -5,9 +5,6 @@ getThumbNailSizes())) { - throw new \RicardoFiorani\Exception\InvalidThumbnailSizeException; + throw new InvalidThumbnailSizeException(); } - return 'http://www.dailymotion.com/' . $size . '/video/' . $this->videoId; + return $this->getScheme($forceSecure) . '://www.dailymotion.com/' . $size . '/video/' . $this->videoId; } /** - * Returns the small thumbnail's url + * Returns the small thumbnail's url. + * + * @param bool $forceSecure * @return string + * @throws InvalidThumbnailSizeException */ - public function getSmallThumbnail() + public function getSmallThumbnail($forceSecure = false) { //Since this service does not provide other thumbnails sizes we just return the default size - return $this->getThumbnail(self::THUMBNAIL_DEFAULT); + return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure); } /** - * Returns the medium thumbnail's url + * Returns the medium thumbnail's url. + * + * @param bool $forceSecure * @return string + * @throws InvalidThumbnailSizeException */ - public function getMediumThumbnail() + public function getMediumThumbnail($forceSecure = false) { //Since this service does not provide other thumbnails sizes we just return the default size - return $this->getThumbnail(self::THUMBNAIL_DEFAULT); + return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure); } /** - * Returns the large thumbnail's url + * Returns the large thumbnail's url. + * + * @param bool $forceSecure * @return string + * @throws InvalidThumbnailSizeException */ - public function getLargeThumbnail() + public function getLargeThumbnail($forceSecure = false) { //Since this service does not provide other thumbnails sizes we just return the default size - return $this->getThumbnail(self::THUMBNAIL_DEFAULT); + return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure); } /** - * Returns the largest thumnbnaail's url + * Returns the largest thumnbnaail's url. + * @param bool $forceSecure * @return string + * @throws InvalidThumbnailSizeException */ - public function getLargestThumbnail() + public function getLargestThumbnail($forceSecure = false) { //Since this service does not provide other thumbnails sizes we just return the default size - return $this->getThumbnail(self::THUMBNAIL_DEFAULT); + return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure); } /** - * @param bool $autoplay + * @param bool $forceAutoplay + * @param bool $forceSecure * @return string */ - public function getEmbedUrl($autoplay = false) + public function getEmbedUrl($forceAutoplay = false, $forceSecure = false) { - return '//www.dailymotion.com/embed/video/' . $this->videoId . ($autoplay ? '?amp&autoplay=1' : ''); + return $this->getScheme($forceSecure) . '://www.dailymotion.com/embed/video/' . $this->videoId . ($forceAutoplay ? '?amp&autoplay=1' : ''); } /** @@ -133,7 +148,6 @@ class DailymotionServiceAdapter extends AbstractServiceAdapter getServiceContainer()->registerService($serviceName, $patterns, "\\MyVendor\\ServiceAdapter\\Factory\\DailymotionServiceAdapterFactory"); +$vsd->getServiceContainer()->registerService($serviceName, $patterns, MyVendor\ServiceAdapter\Factory\DailymotionServiceAdapterFactory::class); //This will get you an DailymotionServiceAdapter $video = $vsd->parse('http://www.dailymotion.com/video/x33ncwc_kittens-fight-in-tiny-boxing-ring_animals'); diff --git a/src/Adapter/AbstractServiceAdapter.php b/src/Adapter/AbstractServiceAdapter.php index ec4b168..01aa57c 100644 --- a/src/Adapter/AbstractServiceAdapter.php +++ b/src/Adapter/AbstractServiceAdapter.php @@ -115,29 +115,37 @@ public function setRenderer($renderer) /** * @param int $width * @param int $height - * @param bool $autoplay + * @param bool $forceAutoplay + * @param bool $forceSecure * * @return string - * * @throws NotEmbeddableException */ - public function getEmbedCode($width, $height, $autoplay = false, $secure = false) + public function getEmbedCode($width, $height, $forceAutoplay = false, $forceSecure = false) { if (false == $this->isEmbeddable()) { throw new NotEmbeddableException(); } - return $this->getRenderer()->renderVideoEmbedCode($this->getEmbedUrl($autoplay, $secure), $width, $height); + return $this->getRenderer()->renderVideoEmbedCode( + $this->getEmbedUrl($forceAutoplay, $forceSecure), + $width, + $height + ); } /** - * Switches the protocol scheme between http and https + * Switches the protocol scheme between http and https in case you want to force https * - * @param bool|false $secure + * @param bool|false $forceSecure * @return string */ - public function getScheme($secure = false) + public function getScheme($forceSecure = false) { - return ($secure ? 'https' : 'http'); + if ($forceSecure) { + return 'https'; + } + + return parse_url($this->rawUrl, PHP_URL_SCHEME); } } diff --git a/src/Adapter/Dailymotion/DailymotionServiceAdapter.php b/src/Adapter/Dailymotion/DailymotionServiceAdapter.php index 5a8bfb9..753ba93 100644 --- a/src/Adapter/Dailymotion/DailymotionServiceAdapter.php +++ b/src/Adapter/Dailymotion/DailymotionServiceAdapter.php @@ -64,79 +64,79 @@ public function getThumbNailSizes() /** * @param string $size - * @param bool $secure + * @param bool $forceSecure * * @return string * @throws InvalidThumbnailSizeException */ - public function getThumbnail($size, $secure = false) + public function getThumbnail($size, $forceSecure = false) { if (false == in_array($size, $this->getThumbNailSizes())) { throw new InvalidThumbnailSizeException(); } - return $this->getScheme($secure) . '://www.dailymotion.com/' . $size . '/video/' . $this->videoId; + return $this->getScheme($forceSecure) . '://www.dailymotion.com/' . $size . '/video/' . $this->videoId; } /** * Returns the small thumbnail's url. * - * @param bool $secure + * @param bool $forceSecure * @return string * @throws InvalidThumbnailSizeException */ - public function getSmallThumbnail($secure = false) + public function getSmallThumbnail($forceSecure = false) { //Since this service does not provide other thumbnails sizes we just return the default size - return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $secure); + return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure); } /** * Returns the medium thumbnail's url. * - * @param bool $secure + * @param bool $forceSecure * @return string * @throws InvalidThumbnailSizeException */ - public function getMediumThumbnail($secure = false) + public function getMediumThumbnail($forceSecure = false) { //Since this service does not provide other thumbnails sizes we just return the default size - return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $secure); + return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure); } /** * Returns the large thumbnail's url. * - * @param bool $secure + * @param bool $forceSecure * @return string * @throws InvalidThumbnailSizeException */ - public function getLargeThumbnail($secure = false) + public function getLargeThumbnail($forceSecure = false) { //Since this service does not provide other thumbnails sizes we just return the default size - return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $secure); + return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure); } /** * Returns the largest thumnbnaail's url. - * @param bool $secure + * @param bool $forceSecure * @return string * @throws InvalidThumbnailSizeException */ - public function getLargestThumbnail($secure = false) + public function getLargestThumbnail($forceSecure = false) { //Since this service does not provide other thumbnails sizes we just return the default size - return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $secure); + return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure); } /** - * @param bool $autoplay - * @param bool $secure + * @param bool $forceAutoplay + * @param bool $forceSecure * @return string */ - public function getEmbedUrl($autoplay = false, $secure = false) + public function getEmbedUrl($forceAutoplay = false, $forceSecure = false) { - return $this->getScheme($secure) . '://www.dailymotion.com/embed/video/' . $this->videoId . ($autoplay ? '?amp&autoplay=1' : ''); + return $this->getScheme($forceSecure) . '://www.dailymotion.com/embed/video/' . $this->videoId . ($forceAutoplay ? '?amp&autoplay=1' : ''); } /** diff --git a/src/Adapter/Facebook/FacebookServiceAdapter.php b/src/Adapter/Facebook/FacebookServiceAdapter.php index cf2c18d..a49f1eb 100644 --- a/src/Adapter/Facebook/FacebookServiceAdapter.php +++ b/src/Adapter/Facebook/FacebookServiceAdapter.php @@ -65,27 +65,27 @@ public function getThumbNailSizes() /** * @param string $size * - * @param bool $secure + * @param bool $forceSecure * @return string * @throws InvalidThumbnailSizeException */ - public function getThumbnail($size, $secure = false) + public function getThumbnail($size, $forceSecure = false) { if (false == in_array($size, $this->getThumbNailSizes())) { throw new InvalidThumbnailSizeException(); } - return $this->getScheme($secure) . '://graph.facebook.com/' . $this->getVideoId() . '/picture'; + return $this->getScheme($forceSecure) . '://graph.facebook.com/' . $this->getVideoId() . '/picture'; } /** * Returns the small thumbnail's url. * - * @param bool $secure + * @param bool $forceSecure * @return string * @throws ThumbnailSizeNotAvailable */ - public function getSmallThumbnail($secure = false) + public function getSmallThumbnail($forceSecure = false) { throw new ThumbnailSizeNotAvailable(); } @@ -93,23 +93,23 @@ public function getSmallThumbnail($secure = false) /** * Returns the medium thumbnail's url. * - * @param bool $secure + * @param bool $forceSecure * @return string * @throws InvalidThumbnailSizeException */ - public function getMediumThumbnail($secure = false) + public function getMediumThumbnail($forceSecure = false) { - return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT, $secure); + return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT, $forceSecure); } /** * Returns the large thumbnail's url. * - * @param bool $secure + * @param bool $forceSecure * @return string * @throws ThumbnailSizeNotAvailable */ - public function getLargeThumbnail($secure = false) + public function getLargeThumbnail($forceSecure = false) { throw new ThumbnailSizeNotAvailable(); } @@ -117,24 +117,24 @@ public function getLargeThumbnail($secure = false) /** * Returns the largest thumbnail's url. * - * @param bool $secure + * @param bool $forceSecure * @return string * @throws InvalidThumbnailSizeException */ - public function getLargestThumbnail($secure = false) + public function getLargestThumbnail($forceSecure = false) { - return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT, $secure); + return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT, $forceSecure); } /** - * @param bool $autoplay + * @param bool $forceAutoplay * - * @param bool $secure + * @param bool $forceSecure * @return string */ - public function getEmbedUrl($autoplay = false, $secure = false) + public function getEmbedUrl($forceAutoplay = false, $forceSecure = false) { - return $this->getScheme($secure) . '://www.facebook.com/video/embed?video_id=' . $this->getVideoId(); + return $this->getScheme($forceSecure) . '://www.facebook.com/video/embed?video_id=' . $this->getVideoId(); } /** diff --git a/src/Adapter/VideoAdapterInterface.php b/src/Adapter/VideoAdapterInterface.php index f02bde2..350f05b 100644 --- a/src/Adapter/VideoAdapterInterface.php +++ b/src/Adapter/VideoAdapterInterface.php @@ -47,52 +47,52 @@ public function getThumbnail($size); /** * Returns the small thumbnail's url. * - * @param bool $secure + * @param bool $forceSecure * @return string */ - public function getSmallThumbnail($secure = false); + public function getSmallThumbnail($forceSecure = false); /** * Returns the medium thumbnail's url. * - * @param bool $secure + * @param bool $forceSecure * @return string */ - public function getMediumThumbnail($secure = false); + public function getMediumThumbnail($forceSecure = false); /** * Returns the large thumbnail's url. * - * @param bool $secure + * @param bool $forceSecure * @return string */ - public function getLargeThumbnail($secure = false); + public function getLargeThumbnail($forceSecure = false); /** * Returns the largest thumnbnail's url. * - * @param bool $secure + * @param bool $forceSecure * @return string */ - public function getLargestThumbnail($secure = false); + public function getLargestThumbnail($forceSecure = false); /** - * @param bool $autoplay - * @param bool $secure + * @param bool $forceAutoplay + * @param bool $forceSecure * * @return string */ - public function getEmbedUrl($autoplay = false, $secure = false); + public function getEmbedUrl($forceAutoplay = false, $forceSecure = false); /** * @param int $width * @param int $height - * @param bool $autoplay - * @param bool $secure + * @param bool $forceAutoplay + * @param bool $forceSecure * * @return string */ - public function getEmbedCode($width, $height, $autoplay = false, $secure = false); + public function getEmbedCode($width, $height, $forceAutoplay = false, $forceSecure = false); /** * @return bool diff --git a/src/Adapter/Vimeo/VimeoServiceAdapter.php b/src/Adapter/Vimeo/VimeoServiceAdapter.php index e6d7a3c..2b4e69e 100644 --- a/src/Adapter/Vimeo/VimeoServiceAdapter.php +++ b/src/Adapter/Vimeo/VimeoServiceAdapter.php @@ -125,23 +125,28 @@ private function setThumbnails(array $thumbnails) * * @throws InvalidThumbnailSizeException */ - public function getThumbnail($size, $secure = false) + public function getThumbnail($size, $forceSecure = false) { if (false == in_array($size, $this->getThumbNailSizes())) { throw new InvalidThumbnailSizeException(); } - return $this->getScheme($secure) . '://' . $this->thumbnails[$size]['host'] . $this->thumbnails[$size]['path']; + return sprintf( + '%s://%s%s', + $this->getScheme($forceSecure), + $this->thumbnails[$size]['host'], + $this->thumbnails[$size]['path'] + ); } /** - * @param bool $autoplay + * @param bool $forceAutoplay * * @return string */ - public function getEmbedUrl($autoplay = false, $secure = false) + public function getEmbedUrl($forceAutoplay = false, $forceSecure = false) { - return $this->getScheme($secure) . '://player.vimeo.com/video/' . $this->getVideoId() . ($autoplay ? '?autoplay=1' : ''); + return $this->getScheme($forceSecure) . '://player.vimeo.com/video/' . $this->getVideoId() . ($forceAutoplay ? '?autoplay=1' : ''); } /** @@ -161,51 +166,51 @@ public function getThumbNailSizes() /** * Returns the small thumbnail's url. * - * @param bool $secure + * @param bool $forceSecure * @return string * @throws InvalidThumbnailSizeException */ - public function getSmallThumbnail($secure = false) + public function getSmallThumbnail($forceSecure = false) { - return $this->getThumbnail(self::THUMBNAIL_SMALL,$secure); + return $this->getThumbnail(self::THUMBNAIL_SMALL,$forceSecure); } /** * Returns the medium thumbnail's url. * - * @param bool $secure + * @param bool $forceSecure * @return string * @throws InvalidThumbnailSizeException */ - public function getMediumThumbnail($secure = false) + public function getMediumThumbnail($forceSecure = false) { - return $this->getThumbnail(self::THUMBNAIL_MEDIUM,$secure); + return $this->getThumbnail(self::THUMBNAIL_MEDIUM,$forceSecure); } /** * Returns the large thumbnail's url. * - * @param bool $secure - * @param $secure + * @param bool $forceSecure + * @param $forceSecure * @return string * @throws InvalidThumbnailSizeException */ - public function getLargeThumbnail($secure = false) + public function getLargeThumbnail($forceSecure = false) { - return $this->getThumbnail(self::THUMBNAIL_LARGE,$secure); + return $this->getThumbnail(self::THUMBNAIL_LARGE,$forceSecure); } /** * Returns the largest thumnbnaail's url. * - * @param bool $secure - * @param $secure + * @param bool $forceSecure + * @param $forceSecure * @return string * @throws InvalidThumbnailSizeException */ - public function getLargestThumbnail($secure = false) + public function getLargestThumbnail($forceSecure = false) { - return $this->getThumbnail(self::THUMBNAIL_LARGE,$secure); + return $this->getThumbnail(self::THUMBNAIL_LARGE,$forceSecure); } /** diff --git a/src/Adapter/Youtube/YoutubeServiceAdapter.php b/src/Adapter/Youtube/YoutubeServiceAdapter.php index c7bbe67..76af95c 100644 --- a/src/Adapter/Youtube/YoutubeServiceAdapter.php +++ b/src/Adapter/Youtube/YoutubeServiceAdapter.php @@ -5,6 +5,7 @@ * Date: 29/08/2015 * Time: 14:53. */ + namespace RicardoFiorani\Adapter\Youtube; use RicardoFiorani\Adapter\AbstractServiceAdapter; @@ -60,17 +61,17 @@ public function hasThumbnail() /** * @param string $size - * @param bool $secure + * @param bool $forceSecure * @return string * @throws InvalidThumbnailSizeException */ - public function getThumbnail($size, $secure = false) + public function getThumbnail($size, $forceSecure = false) { if (false == in_array($size, $this->getThumbNailSizes())) { throw new InvalidThumbnailSizeException(); } - return $this->getScheme($secure) . '://img.youtube.com/vi/' . $this->getVideoId() . '/' . $size . '.jpg'; + return $this->getScheme($forceSecure) . '://img.youtube.com/vi/' . $this->getVideoId() . '/' . $size . '.jpg'; } /** @@ -88,13 +89,20 @@ public function getThumbNailSizes() } /** - * @param bool $autoplay - * @param bool $secure + * @param bool $forceAutoplay + * @param bool $forceSecure * @return string */ - public function getEmbedUrl($autoplay = false, $secure = false) + public function getEmbedUrl($forceAutoplay = false, $forceSecure = false) { - return $this->getScheme($secure) . '://www.youtube.com/embed/' . $this->getVideoId() . ($autoplay ? '?amp&autoplay=1' : ''); + $queryString = $this->generateQuerystring($forceAutoplay); + + return sprintf( + '%s://www.youtube.com/embed/%s?%s', + $this->getScheme($forceSecure), + $this->getVideoId(), + http_build_query($queryString) + ); } /** @@ -102,9 +110,9 @@ public function getEmbedUrl($autoplay = false, $secure = false) * * @return string */ - public function getSmallThumbnail($secure = false) + public function getSmallThumbnail($forceSecure = false) { - return $this->getThumbnail(self::THUMBNAIL_STANDARD_DEFINITION, $secure); + return $this->getThumbnail(self::THUMBNAIL_STANDARD_DEFINITION, $forceSecure); } /** @@ -112,9 +120,9 @@ public function getSmallThumbnail($secure = false) * * @return string */ - public function getMediumThumbnail($secure = false) + public function getMediumThumbnail($forceSecure = false) { - return $this->getThumbnail(self::THUMBNAIL_MEDIUM_QUALITY, $secure); + return $this->getThumbnail(self::THUMBNAIL_MEDIUM_QUALITY, $forceSecure); } /** @@ -122,9 +130,9 @@ public function getMediumThumbnail($secure = false) * * @return string */ - public function getLargeThumbnail($secure = false) + public function getLargeThumbnail($forceSecure = false) { - return $this->getThumbnail(self::THUMBNAIL_HIGH_QUALITY, $secure); + return $this->getThumbnail(self::THUMBNAIL_HIGH_QUALITY, $forceSecure); } /** @@ -132,9 +140,9 @@ public function getLargeThumbnail($secure = false) * * @return string */ - public function getLargestThumbnail($secure = false) + public function getLargestThumbnail($forceSecure = false) { - return $this->getThumbnail(self::THUMBNAIL_MAX_QUALITY, $secure); + return $this->getThumbnail(self::THUMBNAIL_MAX_QUALITY, $forceSecure); } /** @@ -144,4 +152,20 @@ public function isEmbeddable() { return true; } + + /** + * @param bool $forceAutoplay + * @return array + */ + private function generateQuerystring($forceAutoplay = false) + { + parse_str(parse_url($this->rawUrl, PHP_URL_QUERY), $queryString); + unset($queryString['v']); + + if ($forceAutoplay) { + $queryString['autoplay'] = (int) $forceAutoplay; + } + + return $queryString; + } } diff --git a/src/Renderer/DefaultRenderer.php b/src/Renderer/DefaultRenderer.php index dad2bc2..cfb8cc6 100644 --- a/src/Renderer/DefaultRenderer.php +++ b/src/Renderer/DefaultRenderer.php @@ -1,10 +1,8 @@ '; + return sprintf( + '', + $width, + $height, + addslashes($embedUrl) + ); } } diff --git a/test/Adapter/AbstractServiceAdapterTest.php b/test/Adapter/AbstractServiceAdapterTest.php index 5016ab4..22c4e09 100644 --- a/test/Adapter/AbstractServiceAdapterTest.php +++ b/test/Adapter/AbstractServiceAdapterTest.php @@ -93,8 +93,10 @@ public function testGetEmbedCode($url) public function testGetScheme($url) { $facebookVideo = $this->getMockingObject($url); - $schemeInsecure = $facebookVideo->getScheme(false); - $this->assertEquals('http', $schemeInsecure); + + $originalScheme = $facebookVideo->getScheme(false); + $this->assertEquals(parse_url($url, PHP_URL_SCHEME), $originalScheme); + $schemeSecure = $facebookVideo->getScheme(true); $this->assertEquals('https', $schemeSecure); } diff --git a/test/Adapter/DailymotionServiceAdapterTest.php b/test/Adapter/DailymotionServiceAdapterTest.php index efa4f12..5833fda 100644 --- a/test/Adapter/DailymotionServiceAdapterTest.php +++ b/test/Adapter/DailymotionServiceAdapterTest.php @@ -94,7 +94,7 @@ public function testIfGetEmbedUrlUsesRightScheme($url) $this->assertContains('https', $embedUrl); $embedUrl = $videoObject->getEmbedUrl(false, false); - $this->assertNotContains('https', $embedUrl); + $this->assertEquals(parse_url($url, PHP_URL_SCHEME), parse_url($embedUrl, PHP_URL_SCHEME)); } /** diff --git a/test/Adapter/FacebookServiceAdapterTest.php b/test/Adapter/FacebookServiceAdapterTest.php index 532ebf1..2bf5db9 100644 --- a/test/Adapter/FacebookServiceAdapterTest.php +++ b/test/Adapter/FacebookServiceAdapterTest.php @@ -115,7 +115,7 @@ public function testIfGetEmbedUrlUsesRightScheme($url) $this->assertContains('https', $embedUrl); $embedUrl = $videoObject->getEmbedUrl(false, false); - $this->assertNotContains('https', $embedUrl); + $this->assertEquals(parse_url($url, PHP_URL_SCHEME), parse_url($embedUrl, PHP_URL_SCHEME)); } /** diff --git a/test/Adapter/VimeoServiceAdapterTest.php b/test/Adapter/VimeoServiceAdapterTest.php index 583a62c..c60afaf 100644 --- a/test/Adapter/VimeoServiceAdapterTest.php +++ b/test/Adapter/VimeoServiceAdapterTest.php @@ -112,7 +112,7 @@ public function testIfGetEmbedUrlUsesRightScheme($url) $this->assertContains('https', $embedUrl); $embedUrl = $videoObject->getEmbedUrl(false, false); - $this->assertNotContains('https', $embedUrl); + $this->assertEquals(parse_url($url, PHP_URL_SCHEME), parse_url($embedUrl, PHP_URL_SCHEME)); } /** diff --git a/test/Adapter/YoutubeServiceAdapterTest.php b/test/Adapter/YoutubeServiceAdapterTest.php index 32ae089..81a477d 100644 --- a/test/Adapter/YoutubeServiceAdapterTest.php +++ b/test/Adapter/YoutubeServiceAdapterTest.php @@ -92,7 +92,7 @@ public function testIfGetEmbedUrlUsesRightScheme($url) $this->assertContains('https', $embedUrl); $embedUrl = $videoObject->getEmbedUrl(false, false); - $this->assertNotContains('https', $embedUrl); + $this->assertEquals(parse_url($url, PHP_URL_SCHEME), parse_url($embedUrl, PHP_URL_SCHEME)); } /** @@ -114,6 +114,7 @@ public function exampleUrlDataProvider() array( 'https://www.youtube.com/watch?v=uarCDXc3BjU', 'https://youtu.be/uarCDXc3BjU', + 'http://youtu.be/uarBDXc3BjU', '', ), );