-
Notifications
You must be signed in to change notification settings - Fork 7
/
Embed.php
46 lines (38 loc) · 2.16 KB
/
Embed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Ayesh\OembedPlus;
class Embed {
private static $providerPatterns = [
'#https?://www\.facebook\.com/.*/posts/.*#i' => ['https://graph.facebook.com/v8.0/oembed_post', true],
'#https?://www\.facebook\.com/.*/activity/.*#i' => ['https://graph.facebook.com/v8.0/oembed_post', true],
'#https?://www\.facebook\.com/.*/photos/.*#i' => ['https://graph.facebook.com/v8.0/oembed_post', true],
'#https?://www\.facebook\.com/photo(s/|\.php).*#i' => ['https://graph.facebook.com/v8.0/oembed_post', true],
'#https?://www\.facebook\.com/permalink\.php.*#i' => ['https://graph.facebook.com/v8.0/oembed_post', true],
'#https?://www\.facebook\.com/media/.*#i' => ['https://graph.facebook.com/v8.0/oembed_post', true],
'#https?://www\.facebook\.com/questions/.*#i' => ['https://graph.facebook.com/v8.0/oembed_post', true],
'#https?://www\.facebook\.com/notes/.*#i' => ['https://graph.facebook.com/v8.0/oembed_post', true],
'#https?://www\.facebook\.com/.*/videos/.*#i' => ['https://graph.facebook.com/v8.0/oembed_video', true],
'#https?://www\.facebook\.com/video\.php.*#i' => ['https://graph.facebook.com/v8.0/oembed_video', true],
'#https?://www\.facebook\.com/watch/?\?v=\d+#i' => ['https://graph.facebook.com/v8.0/oembed_video', true],
'#https?://(www\.)?instagr(\.am|am\.com)/(p|tv)/.*#i' => ['https://graph.facebook.com/v8.0/instagram_oembed', true],
'#https?://(www\.)?instagr(\.am|am\.com)/p/.*#i' => ['https://graph.facebook.com/v8.0/instagram_oembed', true],
];
private $app_id;
private $app_secret;
private $valid_credentials = false;
public function __construct(?string $app_id = null, ?string $app_secret = null) {
$this->app_id = $app_id;
$this->app_secret = $app_secret;
if (!empty($app_id) && !empty($app_secret)) {
$this->valid_credentials = true;
}
}
public static function registerProviders(array $existing_providers = []): array {
return array_merge($existing_providers, static::$providerPatterns);
}
public function processProviderUrls(string $provider_url): string {
if (!$this->valid_credentials) {
return $provider_url;
}
return $provider_url . '&access_token=' . urlencode($this->app_id . '|' . $this->app_secret);
}
}