diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index 217f42f0eb..9383363012 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -53,7 +53,7 @@ class OEmbed $cache_key = 'oembed:' . $appHelper->getThemeInfoValue('videowidth') . ':' . $embedurl; - $condition = ['url' => Strings::normaliseLink($embedurl), 'maxwidth' => $appHelper->getThemeInfoValue('videowidth')]; + $condition = ['url' => Strings::normaliseLink($embedurl), 'maxwidth' => $appHelper->getThemeInfoValue('videowidth')]; $oembed_record = DBA::selectFirst('oembed', ['content'], $condition); if (DBA::isResult($oembed_record)) { $json_string = $oembed_record['content']; @@ -64,7 +64,7 @@ class OEmbed // These media files should now be caught in bbcode.php // left here as a fallback in case this is called from another source $noexts = ['mp3', 'mp4', 'ogg', 'ogv', 'oga', 'ogm', 'webm']; - $ext = pathinfo(strtolower($embedurl), PATHINFO_EXTENSION); + $ext = pathinfo(strtolower($embedurl), PATHINFO_EXTENSION); $oembed = new \Friendica\Object\OEmbed($embedurl); @@ -81,15 +81,17 @@ class OEmbed if (@$dom->loadHTML($html_text)) { $xpath = new DOMXPath($dom); foreach ( - $xpath->query("//link[@type='application/json+oembed'] | //link[@type='text/json+oembed']") - as $link) - { + $xpath->query("//link[@type='application/json+oembed'] | //link[@type='text/json+oembed']") as $link + ) { /** @var DOMElement $link */ $href = $link->getAttributeNode('href')->nodeValue; // Both Youtube and Vimeo output OEmbed endpoint URL with HTTP // but their OEmbed endpoint is only accessible by HTTPS ¯\_(ツ)_/¯ - $href = str_replace(['http://www.youtube.com/', 'http://player.vimeo.com/'], - ['https://www.youtube.com/', 'https://player.vimeo.com/'], $href); + $href = str_replace( + ['http://www.youtube.com/', 'http://player.vimeo.com/'], + ['https://www.youtube.com/', 'https://player.vimeo.com/'], + $href + ); $result = DI::httpClient()->get($href . '&maxwidth=' . $appHelper->getThemeInfoValue('videowidth'), HttpClientAccept::DEFAULT, [HttpClientOptions::REQUEST => HttpClientRequest::SITEINFO]); if ($result->isSuccess()) { $json_string = $result->getBodyString(); @@ -110,10 +112,10 @@ class OEmbed if (!empty($oembed->type) && $oembed->type != 'error') { DBA::insert('oembed', [ - 'url' => Strings::normaliseLink($embedurl), + 'url' => Strings::normaliseLink($embedurl), 'maxwidth' => $appHelper->getThemeInfoValue('videowidth'), - 'content' => $json_string, - 'created' => DateTimeFormat::utcNow() + 'content' => $json_string, + 'created' => DateTimeFormat::utcNow() ], Database::INSERT_UPDATE); $cache_ttl = Duration::DAY; } else { @@ -141,8 +143,8 @@ class OEmbed if ($oembed->type == 'photo') { if (!empty($data['images'])) { - $oembed->url = $data['images'][0]['src']; - $oembed->width = $data['images'][0]['width']; + $oembed->url = $data['images'][0]['src']; + $oembed->width = $data['images'][0]['width']; $oembed->height = $data['images'][0]['height']; } else { $oembed->type = 'link'; @@ -175,8 +177,8 @@ class OEmbed } if (!empty($data['images']) && ($oembed->type != 'photo')) { - $oembed->thumbnail_url = $data['images'][0]['src']; - $oembed->thumbnail_width = $data['images'][0]['width']; + $oembed->thumbnail_url = $data['images'][0]['src']; + $oembed->thumbnail_width = $data['images'][0]['width']; $oembed->thumbnail_height = $data['images'][0]['height']; } @@ -210,15 +212,15 @@ class OEmbed // make sure we don't attempt divide by zero, fallback is a 1:1 ratio $tr = (($th) ? $tw / $th : 1); - $th = 120; - $tw = $th * $tr; + $th = 120; + $tw = $th * $tr; $tpl = Renderer::getMarkupTemplate('oembed_video.tpl'); $ret .= Renderer::replaceMacros($tpl, [ - '$embedurl' => $oembed->embed_url, + '$embedurl' => $oembed->embed_url, '$escapedhtml' => base64_encode($oembed->html), - '$tw' => $tw, - '$th' => $th, - '$turl' => BBCode::proxyUrl($oembed->thumbnail_url, BBCode::INTERNAL, $uriid, Proxy::SIZE_SMALL), + '$tw' => $tw, + '$th' => $th, + '$turl' => BBCode::proxyUrl($oembed->thumbnail_url, BBCode::INTERNAL, $uriid, Proxy::SIZE_SMALL), ]); } else { $ret .= Proxy::proxifyHtml($oembed->html, $uriid); @@ -285,7 +287,7 @@ class OEmbed } $ret .= '</div>'; -$test = Proxy::proxifyHtml($ret, $uriid); + $test = Proxy::proxifyHtml($ret, $uriid); return str_replace("\n", "", $ret); } diff --git a/tests/Unit/Core/Hooks/HookEventBridgeTest.php b/tests/Unit/Core/Hooks/HookEventBridgeTest.php index ea46230399..44b727cf71 100644 --- a/tests/Unit/Core/Hooks/HookEventBridgeTest.php +++ b/tests/Unit/Core/Hooks/HookEventBridgeTest.php @@ -164,7 +164,7 @@ class HookEventBridgeTest extends TestCase $reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook'); $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue(null, function (string $name, $data): string { + $reflectionProperty->setValue(null, function (string $name, string $data): string { $this->assertSame('oembed_fetch_url', $name); $this->assertSame('original_url', $data);