PluginProbe
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 1.3.0
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v1.3.0
4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 All 189 releases
embedpress / library / ostraining / embera / Lib / Embera / Providers / Facebook.php
Facebook.php
135 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
73 /** Patterns that match video urls */
74 protected $videoPatterns = array(
75 /**
76 * https://www.facebook.com/{page-name}/videos/{video-id}/
77 * https://www.facebook.com/{username}/videos/{video-id}/
78 */
79 '~facebook\.com/(?:[^/]+)/videos/(?:[^/]+)/?~i',
80
81 /**
82 ` * https://www.facebook.com/video.php?id={video-id}
83 * https://www.facebook.com/video.php?v={video-id}
84 */
85 '~facebook\.com/video\.php\?(?:id|v)=(?:[^ ]+)~i',
86 );
87
88 /** inline {@inheritdoc} */
89 protected function validateUrl()
90 {
91 $this->url->convertToHttps();
92 return ($this->urlMatchesPattern(array_merge($this->postPatterns, $this->videoPatterns)));
93 }
94
95 /**
96 * Checks if $this->url matches the given list of patterns
97 *
98 * @param array $patternList Array with regex
99 * @return bool
100 */
101 protected function urlMatchesPattern(array $patternList)
102 {
103 foreach ($patternList as $p) {
104 if (preg_match($p, $this->url)) {
105 return true;
106 }
107 }
108
109 return false;
110 }
111
112 /**
113 * inline {@inheritdoc}
114 *
115 * Im overriding this method because I need to set the
116 * endpoint based on the given url. By default we're always assuming
117 * it is a post url unless we have a specific video match.
118 *
119 * Why? Because we already did url validation and We dont want
120 * to loop over both sets of patterns all over again right? So
121 * we just need to loop over the smaller one ;)
122 */
123 public function getInfo()
124 {
125 $this->apiUrl = 'https://www.facebook.com/plugins/post/oembed.json/';
126 if ($this->urlMatchesPattern($this->videoPatterns)) {
127 $this->apiUrl = 'https://www.facebook.com/plugins/video/oembed.json/';
128 }
129
130 return parent::getInfo();
131 }
132 }
133
134 ?>
135