DeezercomFactory.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 DeezercomFactory extends BaseFactory
  10. {
  11. public function getEmbedCode()
  12. {
  13. $data = $this->getCleanedUrl();
  14. $embed = null;
  15. $element_id = null;
  16. $type = null;
  17. // album
  18. // http://www.deezer.com/fr/music/pantera/far-beyond-driven-80398
  19. if (preg_match("#^\/[a-zA-Z_-]+\/music\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+-([0-9]+)#", $data, $chaines))
  20. {
  21. $element_id = $chaines[1];
  22. $type = 'album';
  23. }
  24. // playlist
  25. // http://www.deezer.com/fr/music/playlist/18701350
  26. else if (preg_match("#^\/[a-zA-Z_-]+\/music\/playlist\/([0-9]+)#", $data, $chaines))
  27. {
  28. $element_id = $chaines[1];
  29. $type = 'playlist';
  30. }
  31. if ($element_id)
  32. {
  33. $width = $this->container->getParameter('deezer_player_width');
  34. $heigth = $this->container->getParameter('deezer_player_height');
  35. $embed = '<iframe scrolling="no" frameborder="0" allowTransparency="true" '
  36. .'src="http://www.deezer.com/fr/plugins/player?autoplay=false&playlist=true'
  37. .'&width='.$width.'&height='.$heigth.'&cover=true&btn_popup=true&type='.$type.'&id='.$element_id.'&title=" '
  38. .'width="'.$width.'" height="'.$heigth.'"></iframe>'
  39. ;
  40. }
  41. return $embed;
  42. }
  43. public function getThumbnailUrl()
  44. {
  45. $url_object = $this->getCleanedUrl();
  46. $url = null;
  47. // album
  48. // http://www.deezer.com/fr/music/pantera/far-beyond-driven-80398
  49. if (preg_match("#^\/[a-zA-Z_-]+\/music\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+-([0-9]+)#", $url_object, $chaines))
  50. {
  51. $id = $chaines[1];
  52. $ch = curl_init('http://api.deezer.com/2.0/album/'.$id);
  53. $options = array(
  54. CURLOPT_RETURNTRANSFER => true,
  55. CURLOPT_HTTPHEADER => array('Content-type: application/json')
  56. );
  57. curl_setopt_array( $ch, $options );
  58. $result = json_decode(curl_exec($ch));
  59. if (isset($result->cover))
  60. {
  61. $url = $result->cover;
  62. }
  63. }
  64. return $url;
  65. }
  66. }