1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: Ricardo Fiorani |
5
|
|
|
* Date: 02/09/2015 |
6
|
|
|
* Time: 22:42. |
7
|
|
|
*/ |
8
|
|
|
namespace RicardoFiorani\Adapter\Facebook; |
9
|
|
|
|
10
|
|
|
use RicardoFiorani\Adapter\AbstractServiceAdapter; |
11
|
|
|
use RicardoFiorani\Exception\InvalidThumbnailSizeException; |
12
|
|
|
use RicardoFiorani\Exception\ThumbnailSizeNotAvailable; |
13
|
|
|
use RicardoFiorani\Renderer\EmbedRendererInterface; |
14
|
|
|
|
15
|
|
|
class FacebookServiceAdapter extends AbstractServiceAdapter |
16
|
|
|
{ |
17
|
|
|
const THUMBNAIL_SIZE_DEFAULT = 'default'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* AbstractVideoAdapter constructor. |
21
|
|
|
* |
22
|
|
|
* @param string $url |
23
|
|
|
* @param string $pattern |
24
|
|
|
* @param EmbedRendererInterface $renderer |
25
|
|
|
*/ |
26
|
|
|
public function __construct($url, $pattern, EmbedRendererInterface $renderer) |
27
|
|
|
{ |
28
|
|
|
$match = array(); |
29
|
|
|
preg_match($pattern, $url, $match); |
30
|
|
|
$this->setVideoId($match[1]); |
31
|
|
|
|
32
|
|
|
return parent::__construct($url, $pattern, $renderer); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Returns the service name . |
37
|
|
|
* |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
|
|
public function getServiceName() |
41
|
|
|
{ |
42
|
|
|
return 'Facebook'; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Returns if the service has a thumbnail image. |
47
|
|
|
* |
48
|
|
|
* @return bool |
49
|
|
|
*/ |
50
|
|
|
public function hasThumbnail() |
51
|
|
|
{ |
52
|
|
|
return true; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Returns all thumbnails available sizes. |
57
|
|
|
* |
58
|
|
|
* @return array |
|
|
|
|
59
|
|
|
*/ |
60
|
|
|
public function getThumbNailSizes() |
61
|
|
|
{ |
62
|
|
|
return array(self::THUMBNAIL_SIZE_DEFAULT); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param string $size |
67
|
|
|
* |
68
|
|
|
* @param bool $forceSecure |
69
|
|
|
* @return string |
70
|
|
|
* @throws InvalidThumbnailSizeException |
71
|
|
|
*/ |
72
|
|
View Code Duplication |
public function getThumbnail($size, $forceSecure = false) |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
if (false == in_array($size, $this->getThumbNailSizes())) { |
|
|
|
|
75
|
|
|
throw new InvalidThumbnailSizeException(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $this->getScheme($forceSecure) . '://graph.facebook.com/' . $this->getVideoId() . '/picture'; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Returns the small thumbnail's url. |
83
|
|
|
* |
84
|
|
|
* @param bool $forceSecure |
85
|
|
|
* @return string |
|
|
|
|
86
|
|
|
* @throws ThumbnailSizeNotAvailable |
87
|
|
|
*/ |
88
|
|
|
public function getSmallThumbnail($forceSecure = false) |
89
|
|
|
{ |
90
|
|
|
throw new ThumbnailSizeNotAvailable(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Returns the medium thumbnail's url. |
95
|
|
|
* |
96
|
|
|
* @param bool $forceSecure |
97
|
|
|
* @return string |
98
|
|
|
* @throws InvalidThumbnailSizeException |
99
|
|
|
*/ |
100
|
|
|
public function getMediumThumbnail($forceSecure = false) |
101
|
|
|
{ |
102
|
|
|
return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT, $forceSecure); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Returns the large thumbnail's url. |
107
|
|
|
* |
108
|
|
|
* @param bool $forceSecure |
109
|
|
|
* @return string |
|
|
|
|
110
|
|
|
* @throws ThumbnailSizeNotAvailable |
111
|
|
|
*/ |
112
|
|
|
public function getLargeThumbnail($forceSecure = false) |
113
|
|
|
{ |
114
|
|
|
throw new ThumbnailSizeNotAvailable(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Returns the largest thumbnail's url. |
119
|
|
|
* |
120
|
|
|
* @param bool $forceSecure |
121
|
|
|
* @return string |
122
|
|
|
* @throws InvalidThumbnailSizeException |
123
|
|
|
*/ |
124
|
|
|
public function getLargestThumbnail($forceSecure = false) |
125
|
|
|
{ |
126
|
|
|
return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT, $forceSecure); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param bool $forceAutoplay |
131
|
|
|
* |
132
|
|
|
* @param bool $forceSecure |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
|
|
public function getEmbedUrl($forceAutoplay = false, $forceSecure = false) |
136
|
|
|
{ |
137
|
|
|
return $this->getScheme($forceSecure) . '://www.facebook.com/video/embed?video_id=' . $this->getVideoId(); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return bool |
142
|
|
|
*/ |
143
|
|
|
public function isEmbeddable() |
144
|
|
|
{ |
145
|
|
|
return true; |
146
|
|
|
} |
147
|
|
|
} |
|
|
|
|
148
|
|
|
|