ActBlue.php
5 years ago
Adways.php
5 years ago
Altru.php
5 years ago
AmCharts.php
5 years ago
Animoto.php
5 years ago
AnnieMusic.php
5 years ago
Apester.php
5 years ago
Archivos.php
5 years ago
AudioClip.php
5 years ago
Audioboom.php
5 years ago
Audiomack.php
5 years ago
Avocode.php
5 years ago
Backtracks.php
5 years ago
BeautifulAI.php
5 years ago
BlackfireIO.php
5 years ago
Blogcast.php
5 years ago
Buttondown.php
5 years ago
Byzart.php
5 years ago
Ceros.php
5 years ago
ChartBlocks.php
5 years ago
Chirbit.php
5 years ago
CircuitLab.php
5 years ago
Clyp.php
5 years ago
CocoCorp.php
5 years ago
CodeHS.php
5 years ago
CodePen.php
5 years ago
CodeSandbox.php
5 years ago
Codepoints.php
5 years ago
Commaful.php
5 years ago
Coub.php
5 years ago
Cueup.php
5 years ago
DailyMotion.php
5 years ago
Datawrapper.php
5 years ago
Deseretnews.php
5 years ago
Deviantart.php
5 years ago
Didacte.php
5 years ago
Digiteka.php
5 years ago
DocDroid.php
5 years ago
DotSUB.php
5 years ago
EduMedia.php
5 years ago
Embedery.php
5 years ago
Ethfiddle.php
5 years ago
Eyrie.php
5 years ago
FITE.php
5 years ago
Facebook.php
4 years ago
Fader.php
5 years ago
FaithLifeTV.php
5 years ago
Fitapp.php
5 years ago
Flickr.php
5 years ago
Flourish.php
5 years ago
GeographCI.php
5 years ago
GeographDE.php
5 years ago
GeographUk.php
5 years ago
GetShow.php
5 years ago
GettyImages.php
5 years ago
Gfycat.php
5 years ago
Giphy.php
5 years ago
GloriaTV.php
5 years ago
Gyazo.php
5 years ago
Hearthis.php
5 years ago
HiHaHo.php
5 years ago
Huffduffer.php
5 years ago
IHeartRadio.php
5 years ago
Infogram.php
5 years ago
Infoveave.php
5 years ago
Injurymap.php
5 years ago
Inoreader.php
5 years ago
Instagram.php
3 years ago
Issuu.php
5 years ago
Jovian.php
5 years ago
KakaoTV.php
5 years ago
Kickstarter.php
5 years ago
Kidoju.php
5 years ago
KirimEmail.php
5 years ago
Kit.php
5 years ago
Kmdr.php
5 years ago
Knacki.php
5 years ago
LearningApps.php
5 years ago
LillePod.php
5 years ago
Livestream.php
5 years ago
Loom.php
5 years ago
Ludus.php
5 years ago
Lumiere.php
5 years ago
Matterport.php
5 years ago
MediaLab.php
5 years ago
MedienArchivKuenste.php
5 years ago
Meetup.php
3 years ago
MermaidInk.php
5 years ago
MessesInfo.php
5 years ago
MicrosoftStream.php
5 years ago
MixCloud.php
5 years ago
ModeloIO.php
5 years ago
MusicboxManiacs.php
5 years ago
Namchey.php
5 years ago
Nanoo.php
5 years ago
NaturalAtlas.php
5 years ago
Nfb.php
5 years ago
NoPaste.php
5 years ago
Omniscope.php
5 years ago
OnSizzle.php
5 years ago
OraTV.php
5 years ago
Orbitvu.php
5 years ago
Outplayed.php
5 years ago
OverflowIO.php
5 years ago
Oz.php
5 years ago
Padlet.php
5 years ago
Pastery.php
5 years ago
Pinpoll.php
5 years ago
Pixdor.php
5 years ago
Playbuzz.php
5 years ago
Podbean.php
5 years ago
PolariShare.php
5 years ago
Polldaddy.php
5 years ago
Portfolium.php
5 years ago
Posixion.php
5 years ago
ProviderAdapter.php
5 years ago
ProviderInterface.php
4 years ago
RadioPublic.php
5 years ago
Rcvis.php
5 years ago
Reddit.php
5 years ago
ReleaseWire.php
5 years ago
Replit.php
5 years ago
ReverbNation.php
5 years ago
Roomshare.php
5 years ago
RoosterTeeth.php
5 years ago
Rumble.php
5 years ago
RunKit.php
5 years ago
Saooti.php
5 years ago
SapoVideos.php
5 years ago
ScreenNine.php
5 years ago
Screencast.php
5 years ago
ScribbleMaps.php
5 years ago
Scribd.php
5 years ago
SendToNews.php
5 years ago
Shortnote.php
5 years ago
Shoudio.php
5 years ago
ShowTheWay.php
5 years ago
Simplecast.php
5 years ago
Sketchfab.php
5 years ago
Slideshare.php
5 years ago
SmashNotes.php
5 years ago
Smugmug.php
5 years ago
SocialExplorer.php
5 years ago
SongLink.php
5 years ago
SoundCloud.php
5 years ago
SpeakerDeck.php
5 years ago
Spotful.php
5 years ago
Spotify.php
5 years ago
Spreaker.php
5 years ago
StandfordDigitalRepository.php
5 years ago
Streamable.php
5 years ago
Subscribi.php
5 years ago
Sudomemo.php
5 years ago
Sutori.php
5 years ago
Sway.php
5 years ago
Ted.php
5 years ago
TheNewYorkTimes.php
5 years ago
Tickcounter.php
5 years ago
TikTok.php
5 years ago
Toornament.php
5 years ago
TourHero.php
5 years ago
Tumblr.php
5 years ago
Tuxx.php
5 years ago
Tvcf.php
5 years ago
TwentyThreeHq.php
5 years ago
Twitter.php
5 years ago
Typecast.php
5 years ago
Typlog.php
5 years ago
UniversitePantheonSorbonne.php
5 years ago
UniversityCambridgeMap.php
5 years ago
Uppy.php
5 years ago
UstreamTV.php
5 years ago
Ustudio.php
5 years ago
Veer.php
5 years ago
Verse.php
5 years ago
Vidyard.php
5 years ago
Vimeo.php
5 years ago
Viously.php
5 years ago
Vlipsy.php
5 years ago
Vlive.php
5 years ago
VoxSnap.php
5 years ago
WaveVideo.php
5 years ago
Wistia.php
5 years ago
Wizer.php
5 years ago
Wokwi.php
5 years ago
WolframCloud.php
5 years ago
Wordpress.php
5 years ago
Wordwall.php
5 years ago
Youtube.php
5 years ago
Zeplin.php
5 years ago
Zingsoft.php
5 years ago
ZnipeTV.php
5 years ago
Zoomable.php
5 years ago
iFixit.php
5 years ago
Facebook.php
224 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Facebook.php |
| 4 | * |
| 5 | * @package Embera |
| 6 | * @author Michael Pratt <yo@michael-pratt.com> |
| 7 | * @link http://www.michael-pratt.com/ |
| 8 | * |
| 9 | * For the full copyright and license information, please view the LICENSE |
| 10 | * file that was distributed with this source code. |
| 11 | */ |
| 12 | |
| 13 | namespace Embera\Provider; |
| 14 | |
| 15 | use Embera\Url; |
| 16 | |
| 17 | /** |
| 18 | * Facebook Provider |
| 19 | * @link https://facebook.com |
| 20 | */ |
| 21 | class Facebook extends ProviderAdapter implements ProviderInterface |
| 22 | { |
| 23 | /** inline {@inheritdoc} */ |
| 24 | protected $shouldSendRequest = false; |
| 25 | /** inline {@inheritdoc} */ |
| 26 | protected $endpoint = 'https://graph.facebook.com/v8.0/oembed_{type}'; |
| 27 | |
| 28 | /** inline {@inheritdoc} */ |
| 29 | protected static $hosts = [ |
| 30 | 'facebook.com', |
| 31 | 'fb.com', |
| 32 | 'fb.watch', |
| 33 | ]; |
| 34 | |
| 35 | /** inline {@inheritdoc} */ |
| 36 | protected $allowedParams = [ 'maxwidth', 'maxheight', 'callback', 'omitscript', 'breaking_change', 'access_token', 'fields' ]; |
| 37 | |
| 38 | /** inline {@inheritdoc} */ |
| 39 | protected $httpsSupport = true; |
| 40 | |
| 41 | /** inline {@inheritdoc} */ |
| 42 | protected $responsiveSupport = false; |
| 43 | |
| 44 | /** Patterns that match posts urls */ |
| 45 | protected $postPatterns = [ |
| 46 | /** |
| 47 | * https://www.facebook.com/{page-name}/posts/{post-id} |
| 48 | * https://www.facebook.com/{username}/posts/{post-id} |
| 49 | * https://www.facebook.com/{username}/activity/{activity-id} |
| 50 | * |
| 51 | * Undocumented: https://www.facebook.com/{username}/photos/{photo-id} |
| 52 | */ |
| 53 | '~facebook\.com/(?:[^/]+)/(?:posts|activity|photos)/(?:[^/]+)/?~i', |
| 54 | |
| 55 | /** |
| 56 | * https://www.facebook.com/notes/{username}/{note-url}/{note-id} |
| 57 | */ |
| 58 | '~facebook\.com/notes/(?:[^/]+)/(?:[^/]+)/(?:[^/]+)/?~i', |
| 59 | |
| 60 | /** |
| 61 | * https://www.facebook.com/photo.php?fbid={photo-id} |
| 62 | * https://www.facebook.com/permalink.php?story_fbid={post-id} |
| 63 | */ |
| 64 | '~facebook\.com/(?:photo|permalink)\.php\?(?:(story_)?fbid)=(?:[^ ]+)~i', |
| 65 | |
| 66 | /** |
| 67 | * https://www.facebook.com/photos/{photo-id} |
| 68 | * https://www.facebook.com/questions/{question-id} |
| 69 | */ |
| 70 | '~facebook\.com/(?:photos|questions)/(?:[^/ ]+)/?~i', |
| 71 | |
| 72 | /** |
| 73 | * NOTE: This url scheme is stated to be supported, however |
| 74 | * I havent found any example that work. I'm leaving it |
| 75 | * but I suspect that its not valid anymore.. we know how |
| 76 | * facebook is with API's :/ |
| 77 | * |
| 78 | * However in order to be really complaint with the documentation |
| 79 | * I'm leaving the pattern. |
| 80 | * |
| 81 | * https://www.facebook.com/media/set?set={set-id} |
| 82 | */ |
| 83 | '~facebook\.com/media/set/?\?set=(?:[^/ ]+)~i', |
| 84 | '~fb\.watch\/~i', |
| 85 | ]; |
| 86 | |
| 87 | /** Patterns that match video urls */ |
| 88 | protected $videoPatterns = [ |
| 89 | /** |
| 90 | * https://www.facebook.com/{page-name}/videos/{video-id}/ |
| 91 | * https://www.facebook.com/{username}/videos/{video-id}/ |
| 92 | */ |
| 93 | '~facebook\.com/(?:[^/]+)/videos/(?:[^/]+)/?~i', |
| 94 | |
| 95 | /** |
| 96 | * https://www.facebook.com/video.php?id={video-id} |
| 97 | * https://www.facebook.com/video.php?v={video-id} |
| 98 | */ |
| 99 | '~facebook\.com/video\.php\?(?:id|v)=(?:[^ ]+)~i', |
| 100 | |
| 101 | '~fb\.watch\/~i', |
| 102 | ]; |
| 103 | |
| 104 | /** Patterns that match page urls */ |
| 105 | protected $pagePatterns = array( |
| 106 | '~facebook\.com\/\S+[\/]?$~' |
| 107 | ); |
| 108 | |
| 109 | /** |
| 110 | * Checks if $url matches the given list of patterns |
| 111 | * |
| 112 | * @param string $url |
| 113 | * @param array $patternList |
| 114 | * @return bool |
| 115 | */ |
| 116 | protected function urlMatchesPattern($url, array $patternList) |
| 117 | { |
| 118 | foreach ($patternList as $p) { |
| 119 | if (preg_match($p, (string) $url)) { |
| 120 | return true; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | /** inline {@inheritdoc} */ |
| 128 | public function validateUrl(Url $url) |
| 129 | { |
| 130 | return $this->urlMatchesPattern($url, array_merge($this->postPatterns, $this->videoPatterns, $this->pagePatterns)); |
| 131 | } |
| 132 | |
| 133 | /** inline {@inheritdoc} */ |
| 134 | public function getEndpoint() |
| 135 | { |
| 136 | if ($this->urlMatchesPattern($this->url, $this->videoPatterns)) { |
| 137 | $type = 'video'; |
| 138 | } elseif ($this->urlMatchesPattern($this->url, $this->postPatterns)) { |
| 139 | $type = 'post'; |
| 140 | } else { |
| 141 | $type = 'page'; |
| 142 | } |
| 143 | |
| 144 | return str_replace('{type}', $type, $this->endpoint); |
| 145 | } |
| 146 | |
| 147 | /** inline {@inheritdoc} */ |
| 148 | public function normalizeUrl(Url $url) |
| 149 | { |
| 150 | $url->convertToHttps(); |
| 151 | return $url; |
| 152 | } |
| 153 | |
| 154 | /** inline {@inheritdoc} */ |
| 155 | public function getStaticResponse() { |
| 156 | |
| 157 | $response = []; |
| 158 | $params =$this->getParams(); |
| 159 | $regx = "/fb\.watch\/|facebook\.com\/[0-9]+\/videos\/|facebook\.com\/watch\//"; |
| 160 | $is_video = preg_match($regx, $this->url); |
| 161 | $embedUrl = 'https://www.facebook.com/plugins/post.php?href={url}&width={width}&height={height}&show_text=true'; |
| 162 | |
| 163 | $height= 680; |
| 164 | $width = 500; |
| 165 | $attr = []; |
| 166 | $class = 'embedpress-facebook--iframe'; |
| 167 | if ( $is_video ) { |
| 168 | $embedUrl = 'https://www.facebook.com/plugins/video.php?height={url_height}&href={url}&show_text=true&width={width}&t=0'; |
| 169 | $class = 'embedpress-facebook-vid-iframe'; |
| 170 | } |
| 171 | $attr[] = 'class="embera-facebook-iframe-{md5} '.$class.'"'; |
| 172 | $attr[] = 'src="' . $embedUrl . '"'; |
| 173 | $attr[] = 'width="{width}"'; |
| 174 | $attr[] = 'height="{height}"'; |
| 175 | $attr[] = 'style="border:none;overflow:hidden"'; |
| 176 | $attr[] = 'scrolling="no"'; |
| 177 | $attr[] = 'frameborder="0"'; |
| 178 | |
| 179 | if ( $is_video ) { |
| 180 | $attr[] = 'allow="autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share"'; |
| 181 | } |
| 182 | $attr[] = 'allowTransparency="true"'; |
| 183 | $attr[] = 'allowFullScreen="true"'; |
| 184 | $iframe = '<iframe ' . implode(' ', $attr) . '></iframe>'; |
| 185 | if (!empty($params['maxheight'])) { |
| 186 | $height = $params['maxheight']; |
| 187 | } else { |
| 188 | if (!empty($params['maxwidth'])){ |
| 189 | if ( $is_video ) { |
| 190 | $height = min(571, (int) ($params['maxwidth'] + 100)); |
| 191 | }else{ |
| 192 | $height = min(680, (int) ($params['maxwidth'] + 100)); |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | if (!empty($params['maxwidth'])) { |
| 198 | $width = $params['maxwidth']; |
| 199 | } else { |
| 200 | if (!empty($params['maxheight'])){ |
| 201 | if ( $is_video ) { |
| 202 | $width = min(476, (int) ($params['maxheight'] - 100)); |
| 203 | }else{ |
| 204 | $width = min(500, (int) ($params['maxheight'] - 100)); |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | $url_height = $height-100; |
| 209 | |
| 210 | $table = array( |
| 211 | '{url}' => rawurlencode( rtrim( $this->url, '/')), |
| 212 | '{md5}' => substr(md5($this->url), 0, 5), |
| 213 | '{width}' => $width, |
| 214 | '{height}' => $height, |
| 215 | '{url_height}' => $url_height, |
| 216 | ); |
| 217 | |
| 218 | // Replace the html response |
| 219 | $response['html'] = str_replace(array_keys($table), array_values($table), $iframe); |
| 220 | return $response; |
| 221 | } |
| 222 | |
| 223 | } |
| 224 |