YoutubeFactory.php 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Muzich\CoreBundle\ElementFactory\Site;
  3. use Muzich\CoreBundle\ElementFactory\Site\base\BaseFactory;
  4. /**
  5. *
  6. *
  7. * @author bux
  8. */
  9. class YoutubeFactory extends BaseFactory
  10. {
  11. public function getEmbedCode()
  12. {
  13. $url = $this->getCleanedUrl();
  14. $embed_url = null;
  15. // http://youtu.be/9hQVA2sloGc
  16. if (preg_match("#\/([a-zA-Z0-9]+)#", $url, $chaines))
  17. {
  18. $embed_url = 'http://www.youtube.com/embed/'.$chaines[1];
  19. }
  20. if ($embed_url)
  21. {
  22. $width = $this->container->getParameter('youtube_player_width');
  23. $height = $this->container->getParameter('youtube_player_height');
  24. return '<iframe width="'.$width.'" height="'.$height.'" src="'.$embed_url.'" '
  25. .'frameborder="0" allowfullscreen></iframe>';
  26. }
  27. return null;
  28. }
  29. public function getThumbnailUrl()
  30. {
  31. $url_object = $this->getCleanedUrl();
  32. $url = null;
  33. // http://youtu.be/9hQVA2sloGc
  34. if (preg_match("#\/([a-zA-Z0-9]+)#", $url_object, $chaines))
  35. {
  36. $url = 'http://img.youtube.com/vi/'.$chaines[1].'/default.jpg';
  37. }
  38. return $url;
  39. }
  40. }