Codebase list php-embed / aab7969
New upstream version 3.3.7 Dominik George 5 years ago
17 changed file(s) with 124 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
1212 {
1313 private static $contentTypes = [
1414 'video/ogg' => ['video', 'videoHtml'],
15 'video/quicktime' => ['video', 'videoHtml'],
1516 'application/ogg' => ['video', 'videoHtml'],
1617 'video/ogv' => ['video', 'videoHtml'],
1718 'video/webm' => ['video', 'videoHtml'],
8081
8182 case 'google':
8283 return Utils::google($this->url);
84
85 case 'imageHtml':
86 return Utils::imageHtml($this->url, 'Remote file', $this->imageWidth, $this->imageHeight);
8387 }
8488 }
8589
2727 $this->width = null;
2828 $this->height = null;
2929
30 $dom = $this->getResponse()->getHtmlContent();
30 if (!($dom = $this->getResponse()->getHtmlContent())) {
31 return;
32 }
33
3134 // #embedModal textarea
3235 $textarea = Utils::xpathQuery($dom, "descendant-or-self::*[@id = 'embedModal']/descendant-or-self::*/textarea");
3336
2929 $id = $this->getResponse()->getUrl()->getDirectoryPosition(1);
3030
3131 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>
3333 CODE;
3434 }
3535 }
1111 class CurlDispatcher implements DispatcherInterface
1212 {
1313 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 ];
1425
1526 private $config = [
1627 CURLOPT_MAXREDIRS => 10,
7889 public function dispatch(Url $url)
7990 {
8091 $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 }
82100
83101 $response = $this->exec($url, $options);
84102
175193
176194 $connection = curl_init((string) $url);
177195
178 curl_setopt_array($connection, $this->config);
196 $options = $this->config;
197 $options[CURLOPT_HTTPHEADER] = ['Accept: image/*'];
198
199 curl_setopt_array($connection, $options);
179200 curl_multi_add_handle($curl_multi, $connection);
180201
181202 $curl = new CurlResult($connection);
2323 return false;
2424 }
2525
26 if (($info = getimagesizefromstring(base64_decode(substr($pieces[1], 7)))) !== false) {
26 if (($info = @getimagesizefromstring(base64_decode(substr($pieces[1], 7)))) !== false) {
2727 return new self(
2828 $url,
2929 $url,
1111 'googleTranslator' => 'translate.google.com/translate',
1212 'hashBang' => '*#!*',
1313 'spotify' => 'play.spotify.com/*',
14 'tumblr' => 't.umblr.com/redirect',
1415 ];
1516
1617 /**
9091 {
9192 return $url->withHost('open.spotify.com');
9293 }
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 }
93110 }
6161
6262 $this->htmlContent = new DOMDocument();
6363
64 if (mb_detect_encoding($content) === 'UTF-8') {
64 if (mb_detect_encoding($content, 'UTF-8', true) === 'UTF-8') {
6565 $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');
6676 $content = preg_replace('/<head[^>]*>/', '<head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">', $content);
6777 }
6878
142152 list($mime, $charset) = array_map('trim', explode(';', $this->contentType));
143153
144154 $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));
146157 }
147158 }
148159 }
558558 return '';
559559 }
560560
561 if (strpos($url, 'data:') === 0) {
561 if (preg_match('|^\w+:[^/]|', $url)) {
562562 return $url;
563563 }
564564
3131 *
3232 * @param Response $response
3333 */
34 public function __construct(Response $response)
34 protected function __construct(Response $response)
3535 {
3636 $this->response = $response;
3737 }
2828 * @param Response $response
2929 * @param string $key
3030 */
31 private function __construct(Response $response, $key)
31 protected function __construct(Response $response, $key)
3232 {
3333 $this->response = $response;
3434 $this->key = $key;
3131 *
3232 * @param Response $response
3333 */
34 private function __construct(Response $response)
34 protected function __construct(Response $response)
3535 {
3636 $this->response = $response;
3737 }
2828 * @param Response $response
2929 * @param string $key
3030 */
31 private function __construct(Response $response, $key)
31 protected function __construct(Response $response, $key)
3232 {
3333 $this->response = $response;
3434 $this->key = $key;
1111 ];
1212 protected static $endPoint = 'https://infogr.am/oembed';
1313
14 /**
14 /**
1515 * {@inheritdoc}
1616 */
1717 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 }
2222
2323 foreach ($html->getElementsByTagName('meta') as $meta) {
2424 $name = trim(strtolower($meta->getAttribute('name')));
25 $value = $meta->getAttribute('content');
25 $value = $meta->getAttribute('content') ?: $meta->getAttribute('value');
2626
2727 if (empty($name) || empty($value)) {
2828 continue;
6868 }
6969
7070 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';
7775 case 'player':
7876 return 'video';
7977 }
113111 public function getAuthorUrl()
114112 {
115113 $author = $this->getAuthorName();
116
114
117115 if (!empty($author)) {
118116 return 'https://twitter.com/'.ltrim($author, '@');
119117 }
127127 */
128128 public static function google($src)
129129 {
130 return self::iframe('http://docs.google.com/viewer?'.http_build_query([
130 return self::iframe('https://docs.google.com/viewer?'.http_build_query([
131131 'url' => $src,
132132 'embedded' => 'true',
133133 ]), 600, 600);