YoutubecomFactory.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 YoutubecomFactory extends BaseFactory
  10. {
  11. public function getEmbedCode()
  12. {
  13. $url = $this->getCleanedUrl();
  14. $embed_url = null;
  15. // '/watch?v=kOLQIV22JAs&feature=feedrec_grec_index'
  16. if (preg_match("#(v\/|watch\?v=)([\w\-]+)#", $url, $chaines))
  17. {
  18. $embed_url = 'http://www.youtube.com/embed/'.$chaines[2];
  19. }
  20. else if (preg_match("#(v=|watch\?v=)([\w\-]+)#", $url, $chaines))
  21. {
  22. $embed_url = 'http://www.youtube.com/embed/'.$chaines[2];
  23. }
  24. if ($embed_url)
  25. {
  26. $width = $this->container->getParameter('youtube_player_width');
  27. $height = $this->container->getParameter('youtube_player_height');
  28. return '<iframe width="'.$width.'" height="'.$height.'" src="'.$embed_url.'" '
  29. .'frameborder="0" allowfullscreen></iframe>';
  30. }
  31. return null;
  32. }
  33. public function getThumbnailUrl()
  34. {
  35. $url_object = $this->getCleanedUrl();
  36. $url = null;
  37. // '/watch?v=kOLQIV22JAs&feature=feedrec_grec_index'
  38. if (preg_match("#(v\/|watch\?v=)([\w\-]+)#", $url_object, $chaines))
  39. {
  40. $url = 'http://img.youtube.com/vi/'.$chaines[2].'/default.jpg';
  41. }
  42. else if (preg_match("#(v=|watch\?v=)([\w\-]+)#", $url_object, $chaines))
  43. {
  44. $url = 'http://img.youtube.com/vi/'.$chaines[2].'/default.jpg';
  45. }
  46. return $url;
  47. }
  48. }