X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FContent%2FOEmbed.php;h=b09fd2249535a2914548bf3ef99020b279335aa8;hb=0a13ab6b9f81fe46698386a197e280859cb10f67;hp=3ab5b4fea863a1a01a293ed16164ab0760b78d5f;hpb=c0eecfc55fd84d7ef4ec51704fe47f6d0b470ef5;p=friendica.git diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index 3ab5b4fea8..b09fd22495 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -3,18 +3,22 @@ /** * @file src/Content/OEmbed.php */ - namespace Friendica\Content; +use Friendica\Core\Addon; use Friendica\Core\Cache; -use Friendica\Core\System; use Friendica\Core\Config; +use Friendica\Core\L10n; +use Friendica\Core\System; use Friendica\Database\DBM; +use Friendica\Util\DateTimeFormat; +use Friendica\Util\Network; use Friendica\Util\ParseUrl; use dba; use DOMDocument; -use DOMXPath; use DOMNode; +use DOMText; +use DOMXPath; use Exception; require_once 'include/dba.php'; @@ -67,7 +71,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 = array("mp3", "mp4", "ogg", "ogv", "oga", "ogm", "webm"); + $noexts = ["mp3", "mp4", "ogg", "ogv", "oga", "ogm", "webm"]; $ext = pathinfo(strtolower($embedurl), PATHINFO_EXTENSION); @@ -77,7 +81,7 @@ class OEmbed if (!in_array($ext, $noexts)) { // try oembed autodiscovery $redirects = 0; - $html_text = fetch_url($embedurl, false, $redirects, 15, "text/*"); + $html_text = Network::fetchUrl($embedurl, false, $redirects, 15, "text/*"); if ($html_text) { $dom = @DOMDocument::loadHTML($html_text); if ($dom) { @@ -85,13 +89,13 @@ class OEmbed $entries = $xpath->query("//link[@type='application/json+oembed']"); foreach ($entries as $e) { $href = $e->getAttributeNode("href")->nodeValue; - $txt = fetch_url($href . '&maxwidth=' . $a->videowidth); + $txt = Network::fetchUrl($href . '&maxwidth=' . $a->videowidth); break; } $entries = $xpath->query("//link[@type='text/json+oembed']"); foreach ($entries as $e) { $href = $e->getAttributeNode("href")->nodeValue; - $txt = fetch_url($href . '&maxwidth=' . $a->videowidth); + $txt = Network::fetchUrl($href . '&maxwidth=' . $a->videowidth); break; } } @@ -109,7 +113,7 @@ class OEmbed 'url' => normalise_link($embedurl), 'maxwidth' => $a->videowidth, 'content' => $txt, - 'created' => datetime_convert() + 'created' => DateTimeFormat::utcNow() ], true); } @@ -125,20 +129,18 @@ class OEmbed // Always embed the SSL version if (isset($j->html)) { - $j->html = str_replace(array("http://www.youtube.com/", "http://player.vimeo.com/"), array("https://www.youtube.com/", "https://player.vimeo.com/"), $j->html); + $j->html = str_replace(["http://www.youtube.com/", "http://player.vimeo.com/"], ["https://www.youtube.com/", "https://player.vimeo.com/"], $j->html); } $j->embedurl = $embedurl; // If fetching information doesn't work, then improve via internal functions - if (($j->type == "error") || ($no_rich_type && ($j->type == "rich"))) { + if ($no_rich_type && ($j->type == "rich")) { $data = ParseUrl::getSiteinfoCached($embedurl, true, false); $j->type = $data["type"]; if ($j->type == "photo") { $j->url = $data["url"]; - //$j->width = $data["images"][0]["width"]; - //$j->height = $data["images"][0]["height"]; } if (isset($data["title"])) { @@ -156,7 +158,7 @@ class OEmbed } } - call_hooks('oembed_fetch_url', $embedurl, $j); + Addon::callHooks('oembed_fetch_url', $embedurl, $j); return $j; } @@ -177,14 +179,14 @@ class OEmbed $th = 120; $tw = $th * $tr; $tpl = get_markup_template('oembed_video.tpl'); - $ret .= replace_macros($tpl, array( + $ret .= replace_macros($tpl, [ '$baseurl' => System::baseUrl(), '$embedurl' => $embedurl, '$escapedhtml' => base64_encode($jhtml), '$tw' => $tw, '$th' => $th, '$turl' => $j->thumbnail_url, - )); + ]); } else { $ret = $jhtml; } @@ -202,23 +204,22 @@ class OEmbed // add link to source if not present in "rich" type if ($j->type != 'rich' || !strpos($j->html, $embedurl)) { $ret .= '

'; - if (isset($j->title)) { - if (isset($j->provider_name)) { + if (!empty($j->title)) { + if (!empty($j->provider_name)) { $ret .= $j->provider_name . ": "; } - $embedlink = (isset($j->title)) ? $j->title : $embedurl; - $ret .= '' . $embedlink . ''; - if (isset($j->author_name)) { + $ret .= '' . $j->title . ''; + if (!empty($j->author_name)) { $ret .= ' (' . $j->author_name . ')'; } - } elseif (isset($j->provider_name) || isset($j->author_name)) { + } elseif (!empty($j->provider_name) || !empty($j->author_name)) { $embedlink = ""; - if (isset($j->provider_name)) { + if (!empty($j->provider_name)) { $embedlink .= $j->provider_name; } - if (isset($j->author_name)) { + if (!empty($j->author_name)) { if ($embedlink != "") { $embedlink .= ": "; } @@ -230,6 +231,8 @@ class OEmbed } $ret .= '' . $embedlink . ''; + } else { + $ret .= '' . $embedurl . ''; } $ret .= "

"; } elseif (!strpos($j->html, $embedurl)) { @@ -247,7 +250,7 @@ class OEmbed { $stopoembed = Config::get("system", "no_oembed"); if ($stopoembed == true) { - return preg_replace("/\[embed\](.+?)\[\/embed\]/is", "" . t('Embedding disabled') . " : $1", $text); + return preg_replace("/\[embed\](.+?)\[\/embed\]/is", "" . L10n::t('Embedding disabled') . " : $1", $text); } return preg_replace_callback("/\[embed\](.+?)\[\/embed\]/is", ['self', 'replaceCallback'], $text); } @@ -312,14 +315,14 @@ class OEmbed $allowed = explode(',', $str_allowed); - return allowed_domain($domain, $allowed); + return Network::isDomainAllowed($domain, $allowed); } public static function getHTML($url, $title = null) { // Always embed the SSL version - $url = str_replace(array("http://www.youtube.com/", "http://player.vimeo.com/"), - array("https://www.youtube.com/", "https://player.vimeo.com/"), $url); + $url = str_replace(["http://www.youtube.com/", "http://player.vimeo.com/"], + ["https://www.youtube.com/", "https://player.vimeo.com/"], $url); $o = self::fetchURL($url, !self::isAllowedURL($url)); @@ -367,7 +370,7 @@ class OEmbed $width = '100%'; $src = System::baseUrl() . '/oembed/' . base64url_encode($src); - return ''; + return ''; } /**