1 | <?php |
||
11 | class SoundCloudProvider extends AbstractOembedProvider |
||
12 | { |
||
13 | const URL_OEMBED = 'https://soundcloud.com/oembed?format=json&url=https://soundcloud.com/%s'; |
||
14 | const URL = 'https://soundcloud.com/%s'; |
||
15 | |||
16 | /** |
||
17 | * @param FormMapper $formMapper |
||
18 | */ |
||
19 | public function buildProviderEditFormBefore(FormMapper $formMapper) |
||
20 | { |
||
21 | $formMapper->add('providerReference', TextType::class, ['label' => $this->getReferenceLabel()]); |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * @param FormMapper $formMapper |
||
26 | */ |
||
27 | public function buildProviderEditFormAfter(FormMapper $formMapper) |
||
28 | { |
||
29 | $formMapper |
||
30 | ->tab('form.embed_options') |
||
31 | ->add( |
||
32 | 'providerMetaData', |
||
33 | ImmutableArrayType::class, |
||
34 | [ |
||
35 | 'keys' => [ |
||
36 | ['autoPlay', CheckboxType::class, ['label' => 'form.auto_play', 'required' => false]], |
||
37 | ['hideRelated', CheckboxType::class, ['label' => 'form.hide_related', 'required' => false]], |
||
38 | ['showComments', CheckboxType::class, ['label' => 'form.show_comments', 'required' => false]], |
||
39 | ['showUser', CheckboxType::class, ['label' => 'form.show_user', 'required' => false]], |
||
40 | ['showReposts', CheckboxType::class, ['label' => 'form.show_reposts', 'required' => false]], |
||
41 | ['showVisual', CheckboxType::class, ['label' => 'form.show_visual', 'required' => false]], |
||
42 | ], |
||
43 | 'label' => 'form.embed_options', |
||
44 | 'required' => false |
||
45 | ] |
||
46 | )->end() |
||
47 | ; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @param string $id |
||
52 | * @return string |
||
53 | */ |
||
54 | public function getOembedUrl($id) |
||
55 | { |
||
56 | return sprintf(self::URL_OEMBED, $id); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param $value |
||
61 | * @return string |
||
62 | * @throws \Exception |
||
63 | */ |
||
64 | 2 | public function parseProviderReference($value) |
|
77 | |||
78 | /** |
||
79 | * @param $id |
||
80 | * @return array |
||
81 | */ |
||
82 | protected function getOembedDataCache($id) |
||
83 | { |
||
84 | $data = parent::getOembedDataCache($id); |
||
85 | $data['embedUrl'] = $this->extractEmbedUrl($data); |
||
86 | |||
87 | return $data; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @param array $data |
||
92 | */ |
||
93 | protected function extractEmbedUrl(array $data) |
||
94 | { |
||
95 | preg_match('/src="(.*)"/', $data['html'], $matches); |
||
96 | $url = $matches[1]; |
||
97 | |||
98 | $data = parse_url($url); |
||
99 | parse_str($data['query'], $data); |
||
100 | |||
101 | return $data['url']; |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * @return string |
||
106 | */ |
||
107 | 1 | public function getIcon() |
|
111 | |||
112 | /** |
||
113 | * @return string |
||
114 | */ |
||
115 | 3 | public function getName() |
|
119 | |||
120 | /** |
||
121 | * @return string |
||
122 | */ |
||
123 | public function getType() |
||
124 | { |
||
127 | } |
||
128 |