|
@@ -0,0 +1,83 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+namespace Muzich\CoreBundle\Factory\Elements;
|
|
4
|
+
|
|
5
|
+use Muzich\CoreBundle\Factory\ElementFactory;
|
|
6
|
+use Muzich\CoreBundle\Entity\Element;
|
|
7
|
+use Muzich\CoreBundle\lib\Api\Response as ApiResponse;
|
|
8
|
+use Muzich\CoreBundle\Factory\UrlMatchs;
|
|
9
|
+use Symfony\Component\DependencyInjection\Container;
|
|
10
|
+use Doctrine\ORM\EntityManager;
|
|
11
|
+
|
|
12
|
+class Mixcloudcom extends ElementFactory
|
|
13
|
+{
|
|
14
|
+
|
|
15
|
+ public function __construct(Element $element, Container $container, EntityManager $entity_manager)
|
|
16
|
+ {
|
|
17
|
+ $this->url_matchs = UrlMatchs::$mixcloud;
|
|
18
|
+ parent::__construct($element, $container, $entity_manager);
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ public function proceedDatas()
|
|
22
|
+ {
|
|
23
|
+ $this->setElementDatasWithApi();
|
|
24
|
+ $this->proceedThumbnailUrl();
|
|
25
|
+ $this->proceedEmbedCode();
|
|
26
|
+ }
|
|
27
|
+
|
|
28
|
+ protected function setElementDatasWithApi()
|
|
29
|
+ {
|
|
30
|
+ if (($response = $this->getApiDatasResponse()))
|
|
31
|
+ {
|
|
32
|
+ $this->setElementSharingData($response);
|
|
33
|
+ $this->setTagsData($response);
|
|
34
|
+ }
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ protected function getApiDatasResponse()
|
|
38
|
+ {
|
|
39
|
+ if (($response = $this->getApiConnector()->getResponseForUrl('http://api.mixcloud.com'.$this->getCleanedUrl())))
|
|
40
|
+ if ($response->haveNot('error'))
|
|
41
|
+ return $response;
|
|
42
|
+
|
|
43
|
+ return null;
|
|
44
|
+ }
|
|
45
|
+
|
|
46
|
+ protected function setElementSharingData(ApiResponse $response)
|
|
47
|
+ {
|
|
48
|
+ $this->getApiConnector()->setElementDatasWithResponse($response, array(
|
|
49
|
+ Element::DATA_TITLE => 'name',
|
|
50
|
+ Element::DATA_NORMALIZED_URL => 'url',
|
|
51
|
+ Element::DATA_REF_ID => 'key',
|
|
52
|
+ Element::DATA_TYPE => Element::TYPE_TRACK,
|
|
53
|
+ Element::DATA_ARTIST => array('user' => 'name'),
|
|
54
|
+ Element::DATA_THUMB_URL => array('pictures' => 'medium')
|
|
55
|
+ ));
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ protected function setTagsData(ApiResponse $response)
|
|
59
|
+ {
|
|
60
|
+ $tags = $response->get('tags');
|
|
61
|
+ $tags_array = array();
|
|
62
|
+ if (count($tags))
|
|
63
|
+ {
|
|
64
|
+ foreach ($tags as $tag_data)
|
|
65
|
+ {
|
|
66
|
+ $tags_array[] = $tag_data['name'];
|
|
67
|
+ }
|
|
68
|
+ }
|
|
69
|
+ $this->setDataTagsForElement(implode(' ', $tags_array));
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ public function proceedEmbedCode()
|
|
73
|
+ {
|
|
74
|
+ if (($response = $this->getApiConnector()->getResponseForUrl(
|
|
75
|
+ 'http://api.mixcloud.com'.$this->element->getData(Element::DATA_REF_ID).'embed-json/?width=100%'
|
|
76
|
+ )))
|
|
77
|
+ {
|
|
78
|
+ if ($response->get('html'))
|
|
79
|
+ $this->element->setEmbed($response->get('html'));
|
|
80
|
+ }
|
|
81
|
+ }
|
|
82
|
+
|
|
83
|
+}
|