Replace hacky oembed local iframe with remote iframe html

- Remove call to OEmbed::iframe
- Replace oembed span by div
- Replace double quotes with single
This commit is contained in:
Hypolite Petovan 2018-01-06 00:35:43 -05:00
parent 6e7abb726c
commit 9593cac2d1

View file

@ -160,8 +160,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 = "<span class='oembed " . $j->type . "'>";
$jhtml = $j->html;
$ret = '<div class="oembed ' . $j->type . '">';
switch ($j->type) {
case "video":
if (isset($j->thumbnail_url)) {
@ -173,7 +173,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 +184,32 @@ class OEmbed
} else {
$ret = $jhtml;
}
//$ret.="<br>";
break;
case "photo":
$ret.= "<img width='" . $j->width . "' src='" . proxy_url($j->url) . "'>";
$ret .= '<img width="' . $j->width . '" src="' . proxy_url($j->url) . '">';
break;
case "link":
break;
case "rich":
// not so safe..
if (self::isAllowedURL($embedurl)) {
$ret .= proxy_parse_html($jhtml);
}
break;
}
$ret .= '</div>';
// add link to source if not present in "rich" type
if ($j->type != 'rich' || !strpos($j->html, $embedurl)) {
$ret .= "<h4>";
$ret .= '<h4>';
if (isset($j->title)) {
if (isset($j->provider_name)) {
$ret .= $j->provider_name . ": ";
}
$embedlink = (isset($j->title)) ? $j->title : $embedurl;
$ret .= "<a href='$embedurl' rel='oembed'>$embedlink</a>";
$ret .= '<a href="' . $embedurl . '" rel="oembed">' . $embedlink . '</a>';
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 +228,14 @@ class OEmbed
$embedlink = $embedurl;
}
$ret .= "<a href='$embedurl' rel='oembed'>$embedlink</a>";
$ret .= '<a href="' . $embedurl . '" rel="oembed">' . $embedlink . '</a>';
}
//if (isset($j->author_name)) $ret.=" by ".$j->author_name;
//if (isset($j->provider_name)) $ret.=" on ".$j->provider_name;
$ret .= "</h4>";
} else {
} elseif (!strpos($j->html, $embedurl)) {
// add <a> for html2bbcode conversion
$ret .= "<a href='$embedurl' rel='oembed'>$embedurl</a>";
$ret .= '<a href="' . $embedurl . '" rel="oembed">' . $j->title . '</a>';
}
$ret.="</span>";
$ret = str_replace("\n", "", $ret);
return mb_convert_encoding($ret, 'HTML-ENTITIES', mb_detect_encoding($ret));
}
@ -272,7 +269,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) {
@ -299,6 +296,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,10 +314,7 @@ 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);
}
$src = System::baseUrl() . '/oembed/' . base64url_encode($src);
return '<iframe onload="resizeIframe(this);" class="embed_rich" height="' . $height . '" width="' . $width . '" src="' . $src . '" allowfullscreen scrolling="no" frameborder="no">' . t('Embedded content') . '</iframe>';
}