Dailymotioncom.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Muzich\CoreBundle\Factory\Elements;
  3. use Muzich\CoreBundle\Factory\ElementFactory;
  4. use Muzich\CoreBundle\Entity\Element;
  5. use Symfony\Component\DependencyInjection\Container;
  6. use Doctrine\ORM\EntityManager;
  7. use Muzich\CoreBundle\Factory\UrlMatchs;
  8. /**
  9. *
  10. *
  11. * @author bux
  12. */
  13. class Dailymotioncom extends ElementFactory
  14. {
  15. public function __construct(Element $element, Container $container, EntityManager $entity_manager)
  16. {
  17. $this->url_matchs = UrlMatchs::$dailymotion;
  18. parent::__construct($element, $container, $entity_manager);
  19. }
  20. public function proceedDatas()
  21. {
  22. $this->setElementDatasWithApi();
  23. $this->proceedEmbedCode();
  24. $this->proceedThumbnailUrl();
  25. }
  26. /**
  27. * URL_API: http://www.dailymotion.com/doc/api/obj-video.html
  28. * URL_TYPE: /video/xnqcwx_le-nazisme-dans-le-couple_fun#hp-v-v2
  29. */
  30. public function setElementDatasWithApi()
  31. {
  32. $response = $this->getApiConnector()->getResponseForUrl('https://api.dailymotion.com/video/'
  33. .$this->url_analyzer->getRefId().'&fields=thumbnail_medium_url,title,tags');
  34. $this->getApiConnector()->setElementDatasWithResponse($response, array(
  35. Element::DATA_THUMB_URL => 'thumbnail_medium_url',
  36. Element::DATA_TITLE => 'title',
  37. ));
  38. if ($response->have('tags'))
  39. {
  40. $this->setDataTagsForElement(implode(' ', $response->get('tags')));
  41. }
  42. }
  43. public function proceedEmbedCode()
  44. {
  45. if (($ref_id = $this->element->getData(Element::DATA_REF_ID)))
  46. {
  47. $width = $this->container->getParameter('dailymotion_player_width');
  48. $height = $this->container->getParameter('dailymotion_player_height');
  49. $this->element->setEmbed(
  50. '<iframe frameborder="0" width="'.$width.'" height="'.$height.'" '
  51. .'src="http://www.dailymotion.com/embed/video/'.$ref_id.'?autoPlay=1"></iframe>'
  52. );
  53. }
  54. }
  55. public function proceedThumbnailUrl()
  56. {
  57. if (($thumb = $this->element->getData(Element::DATA_THUMB_URL)))
  58. {
  59. $this->element->setThumbnailUrl($thumb);
  60. }
  61. }
  62. }