AmCharts.php
9 years ago
Animatron.php
9 years ago
Animoto.php
9 years ago
AolOn.php
9 years ago
AppNet.php
9 years ago
AudioSnaps.php
9 years ago
Bambuser.php
9 years ago
BlipTV.php
9 years ago
Cacoo.php
9 years ago
Chartblocks.php
9 years ago
Chirbit.php
9 years ago
CircuitLab.php
9 years ago
Clyp.php
9 years ago
Codepoints.php
9 years ago
CollegeHumor.php
9 years ago
Coub.php
9 years ago
CrowdRanking.php
9 years ago
DailyMile.php
9 years ago
DailyMotion.php
9 years ago
Deviantart.php
9 years ago
Dipity.php
9 years ago
DotSub.php
9 years ago
Edocr.php
9 years ago
EgliseInfo.php
9 years ago
Facebook.php
9 years ago
Flickr.php
9 years ago
FunnyOrDie.php
9 years ago
GeographCI.php
9 years ago
GeographDe.php
9 years ago
GeographUk.php
9 years ago
GettyImages.php
9 years ago
Gfycat.php
9 years ago
GithubGist.php
9 years ago
Gmep.php
9 years ago
Hq23.php
9 years ago
Huffduffer.php
9 years ago
Hulu.php
9 years ago
IFTTT.php
9 years ago
IFixIt.php
9 years ago
Infogram.php
9 years ago
Instagram.php
9 years ago
Issuu.php
9 years ago
Kickstarter.php
9 years ago
LearningApps.php
9 years ago
Meetup.php
9 years ago
MixCloud.php
9 years ago
MobyPicture.php
9 years ago
NFB.php
9 years ago
Officemix.php
9 years ago
OfficialFM.php
9 years ago
Oumy.php
9 years ago
Pastery.php
9 years ago
PollDaddy.php
9 years ago
PollEveryWhere.php
9 years ago
Portfolium.php
9 years ago
Rapidengage.php
9 years ago
Rdio.php
9 years ago
ReleaseWire.php
9 years ago
RepubHub.php
9 years ago
Reverbnation.php
9 years ago
Revision3.php
9 years ago
Roomshare.php
9 years ago
Rutube.php
9 years ago
Sapo.php
9 years ago
Screenr.php
9 years ago
Scribd.php
9 years ago
ShortNote.php
9 years ago
Shoudio.php
9 years ago
Showtheway.php
9 years ago
Silk.php
9 years ago
Sketchfab.php
9 years ago
SlideShare.php
9 years ago
SoundCloud.php
9 years ago
Speakerdeck.php
9 years ago
Spotify.php
9 years ago
Sway.php
9 years ago
Ted.php
9 years ago
TheySaidSo.php
9 years ago
Twitter.php
9 years ago
Ustream.php
9 years ago
Verse.php
9 years ago
Viddler.php
9 years ago
VideoFork.php
9 years ago
VideoJug.php
9 years ago
Vimeo.php
9 years ago
Vine.php
9 years ago
WordpressTV.php
9 years ago
YFrog.php
9 years ago
Yandex.php
9 years ago
Youtube.php
9 years ago
Facebook.php
142 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Facebook.php |
| 4 | * |
| 5 | * @package Providers |
| 6 | * @author Michael Pratt <pratt@hablarmierda.net> |
| 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\Providers; |
| 14 | |
| 15 | /** |
| 16 | * The Facebook Provider (Public posts and videos) |
| 17 | * @link https://www.facebook.com |
| 18 | * @link https://developers.facebook.com/docs/plugins/oembed-endpoints |
| 19 | */ |
| 20 | class Facebook extends \Embera\Adapters\Service |
| 21 | { |
| 22 | /** |
| 23 | * inline {@inheritdoc} |
| 24 | * This Provider is kind of special, because it uses different oembed endpoints |
| 25 | * based on the given url. The default value of the endpoint is null and is set |
| 26 | * during the process of getting the url information. |
| 27 | */ |
| 28 | protected $apiUrl = null; |
| 29 | |
| 30 | /** Patterns that match posts urls */ |
| 31 | protected $postPatterns = array( |
| 32 | /** |
| 33 | * https://www.facebook.com/{page-name}/posts/{post-id} |
| 34 | * https://www.facebook.com/{username}/posts/{post-id} |
| 35 | * https://www.facebook.com/{username}/activity/{activity-id} |
| 36 | * |
| 37 | * Undocumented: https://www.facebook.com/{username}/photos/{photo-id} |
| 38 | */ |
| 39 | '~facebook\.com/(?:[^/]+)/(?:posts|activity|photos)/(?:[^/]+)/?~i', |
| 40 | |
| 41 | /** |
| 42 | * https://www.facebook.com/notes/{username}/{note-url}/{note-id} |
| 43 | */ |
| 44 | '~facebook\.com/notes/(?:[^/]+)/(?:[^/]+)/(?:[^/]+)/?~i', |
| 45 | |
| 46 | /** |
| 47 | * https://www.facebook.com/photo.php?fbid={photo-id} |
| 48 | * https://www.facebook.com/permalink.php?story_fbid={post-id} |
| 49 | */ |
| 50 | '~facebook\.com/(?:photo|permalink)\.php\?(?:(story_)?fbid)=(?:[^ ]+)~i', |
| 51 | |
| 52 | /** |
| 53 | * https://www.facebook.com/photos/{photo-id} |
| 54 | * https://www.facebook.com/questions/{question-id} |
| 55 | */ |
| 56 | '~facebook\.com/(?:photos|questions)/(?:[^/ ]+)/?~i', |
| 57 | |
| 58 | /** |
| 59 | * NOTE: This url scheme is stated to be supported, however |
| 60 | * I havent found any example that work. I'm leaving it |
| 61 | * but I suspect that its not valid anymore.. we know how |
| 62 | * facebook is with API's :/ |
| 63 | * |
| 64 | * However in order to be really complaint with the documentation |
| 65 | * I'm leaving the pattern. |
| 66 | * |
| 67 | * https://www.facebook.com/media/set?set={set-id} |
| 68 | */ |
| 69 | '~facebook\.com/media/set/?\?set=(?:[^/ ]+)~i', |
| 70 | ); |
| 71 | |
| 72 | /** Patterns that match video urls */ |
| 73 | protected $videoPatterns = array( |
| 74 | /** |
| 75 | * https://www.facebook.com/{page-name}/videos/{video-id}/ |
| 76 | * https://www.facebook.com/{username}/videos/{video-id}/ |
| 77 | */ |
| 78 | '~facebook\.com/(?:[^/]+)/videos/(?:[^/]+)/?~i', |
| 79 | |
| 80 | /** |
| 81 | ` * https://www.facebook.com/video.php?id={video-id} |
| 82 | * https://www.facebook.com/video.php?v={video-id} |
| 83 | */ |
| 84 | '~facebook\.com/video\.php\?(?:id|v)=(?:[^ ]+)~i', |
| 85 | ); |
| 86 | |
| 87 | /** Patterns that match page urls */ |
| 88 | protected $pagePatterns = array( |
| 89 | '~facebook\.com\/(?:[^\/]+)[\/]?$~' |
| 90 | ); |
| 91 | |
| 92 | /** inline {@inheritdoc} */ |
| 93 | protected function validateUrl() |
| 94 | { |
| 95 | $this->url->convertToHttps(); |
| 96 | return ($this->urlMatchesPattern(array_merge($this->postPatterns, $this->videoPatterns, $this->pagePatterns))); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Checks if $this->url matches the given list of patterns |
| 101 | * |
| 102 | * @param array $patternList Array with regex |
| 103 | * @return bool |
| 104 | */ |
| 105 | protected function urlMatchesPattern(array $patternList) |
| 106 | { |
| 107 | foreach ($patternList as $p) { |
| 108 | if (preg_match($p, $this->url)) { |
| 109 | return true; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * inline {@inheritdoc} |
| 118 | * |
| 119 | * Im overriding this method because I need to set the |
| 120 | * endpoint based on the given url. By default we're always assuming |
| 121 | * it is a post url unless we have a specific video match. |
| 122 | * |
| 123 | * Why? Because we already did url validation and We dont want |
| 124 | * to loop over both sets of patterns all over again right? So |
| 125 | * we just need to loop over the smaller one ;) |
| 126 | */ |
| 127 | public function getInfo() |
| 128 | { |
| 129 | if ($this->urlMatchesPattern($this->videoPatterns)) { |
| 130 | $this->apiUrl = 'https://www.facebook.com/plugins/video/oembed.json/'; |
| 131 | } else if ($this->urlMatchesPattern($this->postPatterns)) { |
| 132 | $this->apiUrl = 'https://www.facebook.com/plugins/post/oembed.json/'; |
| 133 | } else { |
| 134 | $this->apiUrl = 'https://www.facebook.com/plugins/page/oembed.json/'; |
| 135 | } |
| 136 | |
| 137 | return parent::getInfo(); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | ?> |
| 142 |