New upstream version 3.3.7
Dominik George
5 years ago
12 | 12 | { |
13 | 13 | private static $contentTypes = [ |
14 | 14 | 'video/ogg' => ['video', 'videoHtml'], |
15 | 'video/quicktime' => ['video', 'videoHtml'], | |
15 | 16 | 'application/ogg' => ['video', 'videoHtml'], |
16 | 17 | 'video/ogv' => ['video', 'videoHtml'], |
17 | 18 | 'video/webm' => ['video', 'videoHtml'], |
80 | 81 | |
81 | 82 | case 'google': |
82 | 83 | return Utils::google($this->url); |
84 | ||
85 | case 'imageHtml': | |
86 | return Utils::imageHtml($this->url, 'Remote file', $this->imageWidth, $this->imageHeight); | |
83 | 87 | } |
84 | 88 | } |
85 | 89 |
27 | 27 | $this->width = null; |
28 | 28 | $this->height = null; |
29 | 29 | |
30 | $dom = $this->getResponse()->getHtmlContent(); | |
30 | if (!($dom = $this->getResponse()->getHtmlContent())) { | |
31 | return; | |
32 | } | |
33 | ||
31 | 34 | // #embedModal textarea |
32 | 35 | $textarea = Utils::xpathQuery($dom, "descendant-or-self::*[@id = 'embedModal']/descendant-or-self::*/textarea"); |
33 | 36 |
29 | 29 | $id = $this->getResponse()->getUrl()->getDirectoryPosition(1); |
30 | 30 | |
31 | 31 | return <<<CODE |
32 | <div id="snipplr_embed_{$id}" class="snipplr_embed"><a target_"blank" href="http://snipplr.com/view/{$id}">View this snippet</a> on Snipplr</div><script type="text/javascript" src="http://snipplr.com/js/embed.js"></script><script type="text/javascript" src="http://snipplr.com/json/{$id}"></script> | |
32 | <div id="snipplr_embed_{$id}" class="snipplr_embed"><a target_"blank" href="https://snipplr.com/view/{$id}">View this snippet</a> on Snipplr</div><script type="text/javascript" src="https://snipplr.com/js/embed.js"></script><script type="text/javascript" src="https://snipplr.com/json/{$id}"></script> | |
33 | 33 | CODE; |
34 | 34 | } |
35 | 35 | } |
11 | 11 | class CurlDispatcher implements DispatcherInterface |
12 | 12 | { |
13 | 13 | private $responses = []; |
14 | private static $acceptHeaders = [ | |
15 | 'jpg' => 'image/jpeg', | |
16 | 'jpeg' => 'image/jpeg', | |
17 | 'gif' => 'image/gif', | |
18 | 'png' => 'image/png', | |
19 | 'mp3' => 'audio/mpeg', | |
20 | 'mp4' => 'video/mp4', | |
21 | 'ogg' => 'audio/ogg', | |
22 | 'ogv' => 'video/ogg', | |
23 | 'webm' => 'video/webm', | |
24 | ]; | |
14 | 25 | |
15 | 26 | private $config = [ |
16 | 27 | CURLOPT_MAXREDIRS => 10, |
78 | 89 | public function dispatch(Url $url) |
79 | 90 | { |
80 | 91 | $options = $this->config; |
81 | $options[CURLOPT_HTTPHEADER] = ['Accept: text/html']; | |
92 | ||
93 | $extension = $url->getExtension(); | |
94 | ||
95 | if (!empty($extension) && isset(self::$acceptHeaders[$extension])) { | |
96 | $options[CURLOPT_HTTPHEADER] = ['Accept: '.self::$acceptHeaders[$extension]]; | |
97 | } else { | |
98 | $options[CURLOPT_HTTPHEADER] = ['Accept: */*']; | |
99 | } | |
82 | 100 | |
83 | 101 | $response = $this->exec($url, $options); |
84 | 102 | |
175 | 193 | |
176 | 194 | $connection = curl_init((string) $url); |
177 | 195 | |
178 | curl_setopt_array($connection, $this->config); | |
196 | $options = $this->config; | |
197 | $options[CURLOPT_HTTPHEADER] = ['Accept: image/*']; | |
198 | ||
199 | curl_setopt_array($connection, $options); | |
179 | 200 | curl_multi_add_handle($curl_multi, $connection); |
180 | 201 | |
181 | 202 | $curl = new CurlResult($connection); |
23 | 23 | return false; |
24 | 24 | } |
25 | 25 | |
26 | if (($info = getimagesizefromstring(base64_decode(substr($pieces[1], 7)))) !== false) { | |
26 | if (($info = @getimagesizefromstring(base64_decode(substr($pieces[1], 7)))) !== false) { | |
27 | 27 | return new self( |
28 | 28 | $url, |
29 | 29 | $url, |
11 | 11 | 'googleTranslator' => 'translate.google.com/translate', |
12 | 12 | 'hashBang' => '*#!*', |
13 | 13 | 'spotify' => 'play.spotify.com/*', |
14 | 'tumblr' => 't.umblr.com/redirect', | |
14 | 15 | ]; |
15 | 16 | |
16 | 17 | /** |
90 | 91 | { |
91 | 92 | return $url->withHost('open.spotify.com'); |
92 | 93 | } |
94 | ||
95 | /** | |
96 | * Redirect the tumblr url | |
97 | * | |
98 | * @param Url $url | |
99 | * | |
100 | * @return Url | |
101 | */ | |
102 | public static function tumblr(Url $url) | |
103 | { | |
104 | if (($value = $url->getQueryParameter('z'))) { | |
105 | return Url::create($value); | |
106 | } | |
107 | ||
108 | return $url; | |
109 | } | |
93 | 110 | } |
61 | 61 | |
62 | 62 | $this->htmlContent = new DOMDocument(); |
63 | 63 | |
64 | if (mb_detect_encoding($content) === 'UTF-8') { | |
64 | if (mb_detect_encoding($content, 'UTF-8', true) === 'UTF-8') { | |
65 | 65 | $content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'); |
66 | $content = preg_replace( | |
67 | '/<head[^>]*>/', | |
68 | '<head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">', | |
69 | $content | |
70 | ); | |
71 | } elseif (mb_detect_encoding($content, 'SJIS', true) === 'SJIS') { | |
72 | $content = mb_convert_encoding($content, 'HTML-ENTITIES', 'SJIS'); | |
73 | $content = preg_replace('/<head[^>]*>/', '<head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=shift_jis">', $content); | |
74 | } elseif (mb_detect_encoding($content, 'ISO-8859-1', true) === 'ISO-8859-1') { | |
75 | $content = mb_convert_encoding($content, 'HTML-ENTITIES', 'ISO-8859-1'); | |
66 | 76 | $content = preg_replace('/<head[^>]*>/', '<head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">', $content); |
67 | 77 | } |
68 | 78 | |
142 | 152 | list($mime, $charset) = array_map('trim', explode(';', $this->contentType)); |
143 | 153 | |
144 | 154 | $this->contentType = $mime; |
145 | $this->content = Utils::toUtf8($content, substr(strstr($charset, '='), 1)); | |
155 | $charset = str_replace(['"', "'"], '', substr(strstr($charset, '='), 1)); | |
156 | $this->content = Utils::toUtf8($content, trim($charset)); | |
146 | 157 | } |
147 | 158 | } |
148 | 159 | } |
558 | 558 | return ''; |
559 | 559 | } |
560 | 560 | |
561 | if (strpos($url, 'data:') === 0) { | |
561 | if (preg_match('|^\w+:[^/]|', $url)) { | |
562 | 562 | return $url; |
563 | 563 | } |
564 | 564 |
31 | 31 | * |
32 | 32 | * @param Response $response |
33 | 33 | */ |
34 | public function __construct(Response $response) | |
34 | protected function __construct(Response $response) | |
35 | 35 | { |
36 | 36 | $this->response = $response; |
37 | 37 | } |
28 | 28 | * @param Response $response |
29 | 29 | * @param string $key |
30 | 30 | */ |
31 | private function __construct(Response $response, $key) | |
31 | protected function __construct(Response $response, $key) | |
32 | 32 | { |
33 | 33 | $this->response = $response; |
34 | 34 | $this->key = $key; |
31 | 31 | * |
32 | 32 | * @param Response $response |
33 | 33 | */ |
34 | private function __construct(Response $response) | |
34 | protected function __construct(Response $response) | |
35 | 35 | { |
36 | 36 | $this->response = $response; |
37 | 37 | } |
28 | 28 | * @param Response $response |
29 | 29 | * @param string $key |
30 | 30 | */ |
31 | private function __construct(Response $response, $key) | |
31 | protected function __construct(Response $response, $key) | |
32 | 32 | { |
33 | 33 | $this->response = $response; |
34 | 34 | $this->key = $key; |
11 | 11 | ]; |
12 | 12 | protected static $endPoint = 'https://infogr.am/oembed'; |
13 | 13 | |
14 | /** | |
14 | /** | |
15 | 15 | * {@inheritdoc} |
16 | 16 | */ |
17 | 17 | public function getEndPoint() |
0 | <?php | |
1 | ||
2 | namespace Embed\Providers\OEmbed; | |
3 | ||
4 | use Embed\Adapters\Adapter; | |
5 | use Embed\Http\Response; | |
6 | use Embed\Http\Url; | |
7 | ||
8 | class Tumblr extends EndPoint implements EndPointInterface | |
9 | { | |
10 | protected static $pattern = [ | |
11 | '*.tumblr.com/post/*' | |
12 | ]; | |
13 | ||
14 | protected static $endPoint = 'https://www.tumblr.com/oembed/1.0'; | |
15 | ||
16 | /** | |
17 | * {@inheritdoc} | |
18 | */ | |
19 | public static function create(Adapter $adapter) | |
20 | { | |
21 | $response = $adapter->getResponse(); | |
22 | ||
23 | if ($response->getStartingUrl()->match(static::$pattern)) { | |
24 | return new static($response); | |
25 | } | |
26 | } | |
27 | ||
28 | /** | |
29 | * {@inheritdoc} | |
30 | */ | |
31 | public function getEndPoint() | |
32 | { | |
33 | return Url::create(static::$endPoint) | |
34 | ->withQueryParameters([ | |
35 | 'url' => (string) $this->response->getStartingUrl() | |
36 | ]); | |
37 | } | |
38 | } |
0 | <?php | |
1 | ||
2 | namespace Embed\Providers\OEmbed; | |
3 | ||
4 | class Twitter extends EndPoint implements EndPointInterface | |
5 | { | |
6 | protected static $pattern = ['*.twitter.com/*', 'twitter.com/*']; | |
7 | protected static $endPoint = 'https://publish.twitter.com/oembed'; | |
8 | } |
22 | 22 | |
23 | 23 | foreach ($html->getElementsByTagName('meta') as $meta) { |
24 | 24 | $name = trim(strtolower($meta->getAttribute('name'))); |
25 | $value = $meta->getAttribute('content'); | |
25 | $value = $meta->getAttribute('content') ?: $meta->getAttribute('value'); | |
26 | 26 | |
27 | 27 | if (empty($name) || empty($value)) { |
28 | 28 | continue; |
68 | 68 | } |
69 | 69 | |
70 | 70 | switch ($type) { |
71 | case 'video': | |
72 | case 'photo': | |
73 | case 'link': | |
74 | case 'rich': | |
75 | return $type; | |
76 | ||
71 | case 'summary': | |
72 | case 'summary_large_image': | |
73 | case 'app': | |
74 | return 'rich'; | |
77 | 75 | case 'player': |
78 | 76 | return 'video'; |
79 | 77 | } |
113 | 111 | public function getAuthorUrl() |
114 | 112 | { |
115 | 113 | $author = $this->getAuthorName(); |
116 | ||
114 | ||
117 | 115 | if (!empty($author)) { |
118 | 116 | return 'https://twitter.com/'.ltrim($author, '@'); |
119 | 117 | } |