Merge pull request #4191 from MrPetovan/bug/4173-fix-oembed-iframe-url

Fix oembed iframe url for Facebook attachments
This commit is contained in:
Michael Vogel 2018-01-11 08:11:01 +01:00 committed by GitHub
commit 465e1d6a5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 40 deletions

View file

@ -43,7 +43,7 @@ define('FRIENDICA_PLATFORM', 'Friendica');
define('FRIENDICA_CODENAME', 'Asparagus'); define('FRIENDICA_CODENAME', 'Asparagus');
define('FRIENDICA_VERSION', '3.6-dev'); define('FRIENDICA_VERSION', '3.6-dev');
define('DFRN_PROTOCOL_VERSION', '2.23'); define('DFRN_PROTOCOL_VERSION', '2.23');
define('DB_UPDATE_VERSION', 1239); define('DB_UPDATE_VERSION', 1240);
define('NEW_UPDATE_ROUTINE_VERSION', 1170); define('NEW_UPDATE_ROUTINE_VERSION', 1170);
/** /**

View file

@ -4,6 +4,7 @@ Table oembed
| Field | Description | Type | Null | Key | Default | Extra | | Field | Description | Type | Null | Key | Default | Extra |
| ------------ | ---------------------------------- | ------------ | ---- | --- | ------------------- | ----- | | ------------ | ---------------------------------- | ------------ | ---- | --- | ------------------- | ----- |
| url | page url | varchar(255) | NO | PRI | NULL | | | url | page url | varchar(255) | NO | PRI | NULL | |
| maxwidth | Maximum width passed to Oembed | int(11) | NO | PRI | 0 | |
| content | OEmbed data of the page | text | NO | | NULL | | | content | OEmbed data of the page | text | NO | | NULL | |
| created | datetime of creation | datetime | NO | MUL | 0001-01-01 00:00:00 | | | created | datetime of creation | datetime | NO | MUL | 0001-01-01 00:00:00 | |

View file

@ -46,16 +46,16 @@ function bb_map_location($match) {
* Note: Can produce a [bookmark] tag in the returned string * Note: Can produce a [bookmark] tag in the returned string
* *
* @brief Processes [attachment] tags * @brief Processes [attachment] tags
* @param string $Text * @param string $return
* @param bool|int $simplehtml * @param bool|int $simplehtml
* @param bool $tryoembed * @param bool $tryoembed
* @return string * @return string
*/ */
function bb_attachment($Text, $simplehtml = false, $tryoembed = true) function bb_attachment($return, $simplehtml = false, $tryoembed = true)
{ {
$data = get_attachment_data($Text); $data = get_attachment_data($return);
if (!$data) { if (!$data) {
return $Text; return $return;
} }
if (isset($data["title"])) { if (isset($data["title"])) {
@ -68,49 +68,46 @@ function bb_attachment($Text, $simplehtml = false, $tryoembed = true)
$data["image"] = ""; $data["image"] = "";
} }
$return = '';
if ($simplehtml == 7) { if ($simplehtml == 7) {
$text = style_url_for_mastodon($data["url"]); $return = style_url_for_mastodon($data["url"]);
} elseif (($simplehtml != 4) && ($simplehtml != 0)) { } elseif (($simplehtml != 4) && ($simplehtml != 0)) {
$text = sprintf('<a href="%s" target="_blank">%s</a><br>', $data["url"], $data["title"]); $return = sprintf('<a href="%s" target="_blank">%s</a><br>', $data["url"], $data["title"]);
} else { } else {
if ($simplehtml != 4) { try {
$text = sprintf('<span class="type-%s">', $data["type"]); if ($tryoembed) {
} $return = OEmbed::getHTML($data['url'], $data['title']);
} else {
$oembed = sprintf('[bookmark=%s]%s[/bookmark]', $data['url'], $data['title']); throw new Exception('OEmbed is disabled for this attachment.');
if ($tryoembed) { }
try { } catch (Exception $e) {
$oembed = OEmbed::getHTML($data['url'], $data['title']); if ($simplehtml != 4) {
} catch (Exception $e) { $return = sprintf('<span class="type-%s">', $data["type"]);
// $oembed isn't modified
} }
}
if (stripos($oembed, "<iframe ") !== false) { if ($data["image"] != "") {
$text = $oembed; $return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a><br />', $data["url"], proxy_url($data["image"]), $data["title"]);
} else { } elseif ($data["preview"] != "") {
if (($data["image"] != "") && !strstr(strtolower($oembed), "<img ")) { $return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-preview" /></a><br />', $data["url"], proxy_url($data["preview"]), $data["title"]);
$text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a><br />', $data["url"], proxy_url($data["image"]), $data["title"]);
} elseif (($data["preview"] != "") && !strstr(strtolower($oembed), "<img ")) {
$text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-preview" /></a><br />', $data["url"], proxy_url($data["preview"]), $data["title"]);
} }
if (($data["type"] == "photo") && ($data["url"] != "") && ($data["image"] != "")) { if (($data["type"] == "photo") && ($data["url"] != "") && ($data["image"] != "")) {
$text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a>', $data["url"], proxy_url($data["image"]), $data["title"]); $return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a>', $data["url"], proxy_url($data["image"]), $data["title"]);
} else { } else {
$text .= $oembed; $return .= sprintf('[bookmark=%s]%s[/bookmark]', $data['url'], $data['title']);
} }
if (trim($data["description"]) != "") { if (trim($data["description"]) != "") {
$text .= sprintf('<blockquote>%s</blockquote>', trim(bbcode($data["description"]))); $return .= sprintf('<blockquote>%s</blockquote>', trim(bbcode($data["description"])));
}
if ($simplehtml != 4) {
$return .= '</span>';
} }
} }
if ($simplehtml != 4) {
$text .= '</span>';
}
} }
return trim($data["text"] . ' ' . $text . ' ' . $data["after"]);
return trim($data["text"] . ' ' . $return . ' ' . $data["after"]);
} }
function bb_remove_share_information($Text, $plaintext = false, $nolink = false) { function bb_remove_share_information($Text, $plaintext = false, $nolink = false) {

View file

@ -47,8 +47,8 @@ class OEmbed
* @param string $embedurl The URL from which the data should be fetched. * @param string $embedurl The URL from which the data should be fetched.
* @param bool $no_rich_type If set to true rich type content won't be fetched. * @param bool $no_rich_type If set to true rich type content won't be fetched.
* *
* @return bool|object Returns object with embed content or false if no embedable * @return bool|object Returns object with embed content or false if no embeddable
* content exists * content exists
*/ */
public static function fetchURL($embedurl, $no_rich_type = false) public static function fetchURL($embedurl, $no_rich_type = false)
{ {
@ -57,7 +57,7 @@ class OEmbed
$a = get_app(); $a = get_app();
$condition = ['url' => normalise_link($embedurl)]; $condition = ['url' => normalise_link($embedurl), 'maxwidth' => $a->videowidth];
$r = dba::selectFirst('oembed', ['content'], $condition); $r = dba::selectFirst('oembed', ['content'], $condition);
if (DBM::is_result($r)) { if (DBM::is_result($r)) {
$txt = $r["content"]; $txt = $r["content"];
@ -105,8 +105,12 @@ class OEmbed
} else { //save in cache } else { //save in cache
$j = json_decode($txt); $j = json_decode($txt);
if ($j->type != "error") { if ($j->type != "error") {
dba::insert('oembed', array('url' => normalise_link($embedurl), dba::insert('oembed', [
'content' => $txt, 'created' => datetime_convert()), true); 'url' => normalise_link($embedurl),
'maxwidth' => $a->videowidth,
'content' => $txt,
'created' => datetime_convert()
], true);
} }
Cache::set($a->videowidth . $embedurl, $txt, CACHE_DAY); Cache::set($a->videowidth . $embedurl, $txt, CACHE_DAY);
@ -306,7 +310,7 @@ class OEmbed
if (!x($str_allowed)) { if (!x($str_allowed)) {
return false; return false;
} }
$allowed = explode(',', $str_allowed); $allowed = explode(',', $str_allowed);
return allowed_domain($domain, $allowed); return allowed_domain($domain, $allowed);

View file

@ -1277,11 +1277,12 @@ class DBStructure {
$database["oembed"] = array( $database["oembed"] = array(
"fields" => array( "fields" => array(
"url" => array("type" => "varbinary(255)", "not null" => "1", "primary" => "1"), "url" => array("type" => "varbinary(255)", "not null" => "1", "primary" => "1"),
"maxwidth" => array("type" => "int(11)", "not null" => "1", "primary" => "1"),
"content" => array("type" => "mediumtext"), "content" => array("type" => "mediumtext"),
"created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
), ),
"indexes" => array( "indexes" => array(
"PRIMARY" => array("url"), "PRIMARY" => array("url", "maxwidth"),
"created" => array("created"), "created" => array("created"),
) )
); );

View file

@ -23,6 +23,7 @@ function frio_init(App $a)
{ {
// disable the events module link in the profile tab // disable the events module link in the profile tab
$a->theme_events_in_profile = false; $a->theme_events_in_profile = false;
$a->videowidth = 622;
$a->set_template_engine('smarty3'); $a->set_template_engine('smarty3');