DailymotioncomFactory.php 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 DailymotioncomFactory extends BaseFactory
  10. {
  11. public function getEmbedCode()
  12. {
  13. $url = $this->getCleanedUrl();
  14. $embed_url = null;
  15. // /video/xnqcwx_le-nazisme-dans-le-couple_fun#hp-v-v2
  16. if (preg_match("#(video\/)([a-zA-Z0-9]+)([a-zA-Z0-9_-]*)#", $url, $chaines))
  17. {
  18. $embed_url = 'http://www.dailymotion.com/embed/video/'.$chaines[2];
  19. }
  20. if ($embed_url)
  21. {
  22. $width = $this->container->getParameter('dailymotion_player_width');
  23. $height = $this->container->getParameter('dailymotion_player_height');
  24. return '<iframe frameborder="0" width="'.$width.'" height="'.$height.'" '
  25. .'src="'.$embed_url.'"></iframe>';
  26. }
  27. return null;
  28. }
  29. /*
  30. * http://www.dailymotion.com/doc/api/obj-video.html
  31. */
  32. public function getThumbnailUrl()
  33. {
  34. // https://api.dailymotion.com/video/xmi3i1&fields=thumbnail_medium_url
  35. $url_object = $this->getCleanedUrl();
  36. $url = null;
  37. if (preg_match("#(video\/)([a-zA-Z0-9]+)([a-zA-Z0-9_-]*)#", $url_object, $chaines))
  38. {
  39. $ch = curl_init('https://api.dailymotion.com/video/'.$chaines[2].'&fields=thumbnail_medium_url');
  40. $options = array(
  41. CURLOPT_RETURNTRANSFER => true,
  42. CURLOPT_HTTPHEADER => array('Content-type: application/json')
  43. );
  44. curl_setopt_array( $ch, $options );
  45. $result = json_decode(curl_exec($ch));
  46. if (isset($result->thumbnail_medium_url))
  47. {
  48. $url = $result->thumbnail_medium_url;
  49. }
  50. }
  51. return $url;
  52. }
  53. }
  54. ?>