mirror of
https://github.com/friendica/friendica
synced 2024-11-18 14:23:41 +00:00
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:
parent
6e7abb726c
commit
9593cac2d1
1 changed files with 16 additions and 20 deletions
|
@ -160,8 +160,8 @@ class OEmbed
|
||||||
public static function formatObject($j)
|
public static function formatObject($j)
|
||||||
{
|
{
|
||||||
$embedurl = $j->embedurl;
|
$embedurl = $j->embedurl;
|
||||||
$jhtml = self::iframe($j->embedurl, (isset($j->width) ? $j->width : null), (isset($j->height) ? $j->height : null));
|
$jhtml = $j->html;
|
||||||
$ret = "<span class='oembed " . $j->type . "'>";
|
$ret = '<div class="oembed ' . $j->type . '">';
|
||||||
switch ($j->type) {
|
switch ($j->type) {
|
||||||
case "video":
|
case "video":
|
||||||
if (isset($j->thumbnail_url)) {
|
if (isset($j->thumbnail_url)) {
|
||||||
|
@ -173,7 +173,7 @@ class OEmbed
|
||||||
$th = 120;
|
$th = 120;
|
||||||
$tw = $th * $tr;
|
$tw = $th * $tr;
|
||||||
$tpl = get_markup_template('oembed_video.tpl');
|
$tpl = get_markup_template('oembed_video.tpl');
|
||||||
$ret.=replace_macros($tpl, array(
|
$ret .= replace_macros($tpl, array(
|
||||||
'$baseurl' => System::baseUrl(),
|
'$baseurl' => System::baseUrl(),
|
||||||
'$embedurl' => $embedurl,
|
'$embedurl' => $embedurl,
|
||||||
'$escapedhtml' => base64_encode($jhtml),
|
'$escapedhtml' => base64_encode($jhtml),
|
||||||
|
@ -184,33 +184,32 @@ class OEmbed
|
||||||
} else {
|
} else {
|
||||||
$ret = $jhtml;
|
$ret = $jhtml;
|
||||||
}
|
}
|
||||||
//$ret.="<br>";
|
|
||||||
break;
|
break;
|
||||||
case "photo":
|
case "photo":
|
||||||
$ret.= "<img width='" . $j->width . "' src='" . proxy_url($j->url) . "'>";
|
$ret .= '<img width="' . $j->width . '" src="' . proxy_url($j->url) . '">';
|
||||||
break;
|
break;
|
||||||
case "link":
|
case "link":
|
||||||
break;
|
break;
|
||||||
case "rich":
|
case "rich":
|
||||||
// not so safe..
|
|
||||||
if (self::isAllowedURL($embedurl)) {
|
if (self::isAllowedURL($embedurl)) {
|
||||||
$ret .= proxy_parse_html($jhtml);
|
$ret .= proxy_parse_html($jhtml);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$ret .= '</div>';
|
||||||
// add link to source if not present in "rich" type
|
// add link to source if not present in "rich" type
|
||||||
if ($j->type != 'rich' || !strpos($j->html, $embedurl)) {
|
if ($j->type != 'rich' || !strpos($j->html, $embedurl)) {
|
||||||
$ret .= "<h4>";
|
$ret .= '<h4>';
|
||||||
if (isset($j->title)) {
|
if (isset($j->title)) {
|
||||||
if (isset($j->provider_name)) {
|
if (isset($j->provider_name)) {
|
||||||
$ret .= $j->provider_name . ": ";
|
$ret .= $j->provider_name . ": ";
|
||||||
}
|
}
|
||||||
|
|
||||||
$embedlink = (isset($j->title)) ? $j->title : $embedurl;
|
$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)) {
|
if (isset($j->author_name)) {
|
||||||
$ret.=" (" . $j->author_name . ")";
|
$ret .= ' (' . $j->author_name . ')';
|
||||||
}
|
}
|
||||||
} elseif (isset($j->provider_name) || isset($j->author_name)) {
|
} elseif (isset($j->provider_name) || isset($j->author_name)) {
|
||||||
$embedlink = "";
|
$embedlink = "";
|
||||||
|
@ -229,16 +228,14 @@ class OEmbed
|
||||||
$embedlink = $embedurl;
|
$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>";
|
$ret .= "</h4>";
|
||||||
} else {
|
} elseif (!strpos($j->html, $embedurl)) {
|
||||||
// add <a> for html2bbcode conversion
|
// 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);
|
$ret = str_replace("\n", "", $ret);
|
||||||
return mb_convert_encoding($ret, 'HTML-ENTITIES', mb_detect_encoding($ret));
|
return mb_convert_encoding($ret, 'HTML-ENTITIES', mb_detect_encoding($ret));
|
||||||
}
|
}
|
||||||
|
@ -272,7 +269,7 @@ class OEmbed
|
||||||
$xpath = new DOMXPath($dom);
|
$xpath = new DOMXPath($dom);
|
||||||
|
|
||||||
$xattr = self::buildXPath("class", "oembed");
|
$xattr = self::buildXPath("class", "oembed");
|
||||||
$entries = $xpath->query("//span[$xattr]");
|
$entries = $xpath->query("//div[$xattr]");
|
||||||
|
|
||||||
$xattr = "@rel='oembed'"; //oe_build_xpath("rel","oembed");
|
$xattr = "@rel='oembed'"; //oe_build_xpath("rel","oembed");
|
||||||
foreach ($entries as $e) {
|
foreach ($entries as $e) {
|
||||||
|
@ -299,6 +296,8 @@ class OEmbed
|
||||||
* Since the iframe is automatically resized on load, there are no need for ugly
|
* Since the iframe is automatically resized on load, there are no need for ugly
|
||||||
* and impractical scrollbars.
|
* 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 $src Original remote URL to embed
|
||||||
* @param string $width
|
* @param string $width
|
||||||
* @param string $height
|
* @param string $height
|
||||||
|
@ -315,10 +314,7 @@ class OEmbed
|
||||||
}
|
}
|
||||||
$width = '100%';
|
$width = '100%';
|
||||||
|
|
||||||
// Only proxy OEmbed URLs to avoid mixed-content errors
|
$src = System::baseUrl() . '/oembed/' . base64url_encode($src);
|
||||||
if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL && parse_url($src, PHP_URL_SCHEME) !== 'https') {
|
|
||||||
$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>';
|
return '<iframe onload="resizeIframe(this);" class="embed_rich" height="' . $height . '" width="' . $width . '" src="' . $src . '" allowfullscreen scrolling="no" frameborder="no">' . t('Embedded content') . '</iframe>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue