X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FContent%2FOEmbed.php;h=07c36685c3516f3afeb969e124d704bd8df37d02;hb=fd1515eff40341dab917f486bf15e392040cd48d;hp=51c987755e1b6f2211d06cfda02ba3be0356e878;hpb=066b776dcce54d39b56ad1075bef150d4125467b;p=friendica.git diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index 51c987755e..07c36685c3 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -15,6 +15,7 @@ use dba; use DOMDocument; use DOMXPath; use DOMNode; +use Exception; require_once 'include/dba.php'; require_once 'mod/proxy.php'; @@ -160,8 +161,8 @@ class OEmbed public static function formatObject($j) { $embedurl = $j->embedurl; - $jhtml = self::iframe($j->embedurl, (isset($j->width) ? $j->width : null), (isset($j->height) ? $j->height : null)); - $ret = ""; + $jhtml = $j->html; + $ret = '
'; switch ($j->type) { case "video": if (isset($j->thumbnail_url)) { @@ -173,7 +174,7 @@ class OEmbed $th = 120; $tw = $th * $tr; $tpl = get_markup_template('oembed_video.tpl'); - $ret.=replace_macros($tpl, array( + $ret .= replace_macros($tpl, array( '$baseurl' => System::baseUrl(), '$embedurl' => $embedurl, '$escapedhtml' => base64_encode($jhtml), @@ -184,33 +185,32 @@ class OEmbed } else { $ret = $jhtml; } - //$ret.="
"; break; case "photo": - $ret.= ""; + $ret .= ''; break; case "link": break; case "rich": - // not so safe.. if (self::isAllowedURL($embedurl)) { $ret .= proxy_parse_html($jhtml); } break; } + $ret .= '
'; // add link to source if not present in "rich" type if ($j->type != 'rich' || !strpos($j->html, $embedurl)) { - $ret .= "

"; + $ret .= '

'; if (isset($j->title)) { if (isset($j->provider_name)) { $ret .= $j->provider_name . ": "; } $embedlink = (isset($j->title)) ? $j->title : $embedurl; - $ret .= "$embedlink"; + $ret .= '' . $embedlink . ''; if (isset($j->author_name)) { - $ret.=" (" . $j->author_name . ")"; + $ret .= ' (' . $j->author_name . ')'; } } elseif (isset($j->provider_name) || isset($j->author_name)) { $embedlink = ""; @@ -229,16 +229,14 @@ class OEmbed $embedlink = $embedurl; } - $ret .= "$embedlink"; + $ret .= '' . $embedlink . ''; } - //if (isset($j->author_name)) $ret.=" by ".$j->author_name; - //if (isset($j->provider_name)) $ret.=" on ".$j->provider_name; $ret .= "

"; - } else { + } elseif (!strpos($j->html, $embedurl)) { // add for html2bbcode conversion - $ret .= "$embedurl"; + $ret .= '' . $j->title . ''; } - $ret.="
"; + $ret = str_replace("\n", "", $ret); return mb_convert_encoding($ret, 'HTML-ENTITIES', mb_detect_encoding($ret)); } @@ -272,7 +270,7 @@ class OEmbed $xpath = new DOMXPath($dom); $xattr = self::buildXPath("class", "oembed"); - $entries = $xpath->query("//span[$xattr]"); + $entries = $xpath->query("//div[$xattr]"); $xattr = "@rel='oembed'"; //oe_build_xpath("rel","oembed"); foreach ($entries as $e) { @@ -287,6 +285,55 @@ class OEmbed } } + /** + * Determines if rich content OEmbed is allowed for the provided URL + * + * @brief Determines if rich content OEmbed is allowed for the provided URL + * @param string $url + * @return boolean + */ + public static function isAllowedURL($url) + { + if (!Config::get('system', 'no_oembed_rich_content')) { + return true; + } + + $domain = parse_url($url, PHP_URL_HOST); + if (!x($domain)) { + return false; + } + + $str_allowed = Config::get('system', 'allowed_oembed', ''); + if (!x($str_allowed)) { + return false; + } + + $allowed = explode(',', $str_allowed); + + return allowed_domain($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); + + $o = OEmbed::fetchURL($url); + + if (!is_object($o) || $o->type == 'error') { + throw new Exception('OEmbed failed for URL: ' . $url); + } + + if (x($title)) { + $o->title = $title; + } + + $html = OEmbed::formatObject($o); + + return $html; + } + /** * @brief Generates the iframe HTML for an oembed attachment. * @@ -299,6 +346,8 @@ class OEmbed * Since the iframe is automatically resized on load, there are no need for ugly * and impractical scrollbars. * + * @todo This function is currently unused until someone™ adds support for a separate OEmbed domain + * * @param string $src Original remote URL to embed * @param string $width * @param string $height @@ -315,11 +364,8 @@ class OEmbed } $width = '100%'; - // Only proxy OEmbed URLs to avoid mixed-content errors - if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL && parse_url($src, PHP_URL_SCHEME) !== 'https') { - $src = System::baseUrl() . '/oembed/' . base64url_encode($src); - } - return ''; + $src = System::baseUrl() . '/oembed/' . base64url_encode($src); + return ''; } /** @@ -356,24 +402,4 @@ class OEmbed return $innerHTML; } - /** - * Determines if rich content OEmbed is allowed for the provided URL - * - * @brief Determines if rich content OEmbed is allowed for the provided URL - * @param string $url - * @return boolean - */ - private static function isAllowedURL($url) - { - if (!Config::get('system', 'no_oembed_rich_content')) { - return true; - } - - $domain = parse_url($url, PHP_URL_HOST); - - $str_allowed = Config::get('system', 'allowed_oembed', ''); - $allowed = explode(',', $str_allowed); - - return allowed_domain($domain, $allowed, true); - } }