1
1
Fork 0

OStatus: Better attachment handling for pictures

This commit is contained in:
Michael 2017-09-07 15:34:50 +00:00
parent ce975ceba2
commit 6e670df80f
2 changed files with 27 additions and 29 deletions

View file

@ -351,17 +351,11 @@ class ostatus {
continue;
}
$item["body"] = add_page_info_to_body(html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue));
$item["body"] = html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue);
//$item["body"] = add_page_info_to_body(html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue));
$item["object-type"] = $xpath->query('activity:object-type/text()', $entry)->item(0)->nodeValue;
$item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue;
// Mastodon Content Warning
if (($item["verb"] == ACTIVITY_POST) && $xpath->evaluate('boolean(atom:summary)', $entry)) {
$clear_text = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue;
$item["body"] = html2bbcode($clear_text) . '[spoiler]' . $item["body"] . '[/spoiler]';
}
if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) || ($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
$item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue;
$item["body"] = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue;
@ -464,7 +458,6 @@ class ostatus {
}
$self = "";
$enclosure = "";
$links = $xpath->query('atom:link', $entry);
if ($links) {
@ -488,14 +481,18 @@ class ostatus {
}
break;
case "enclosure":
$enclosure = $attribute['href'];
if (strlen($item["attach"])) {
$item["attach"] .= ',';
$filetype = strtolower(substr($attribute['type'], 0, strpos($attribute['type'],'/')));
if ($filetype == 'image') {
$item['body'] .= "\n[img]".$attribute['href'].'[/img]';
} else {
if (strlen($item["attach"])) {
$item["attach"] .= ',';
}
if (!isset($attribute['length'])) {
$attribute['length'] = "0";
}
$item["attach"] .= '[attach]href="'.$attribute['href'].'" length="'.$attribute['length'].'" type="'.$attribute['type'].'" title="'.$attribute['title'].'"[/attach]';
}
if (!isset($attribute['length'])) {
$attribute['length'] = "0";
}
$item["attach"] .= '[attach]href="'.$attribute['href'].'" length="'.$attribute['length'].'" type="'.$attribute['type'].'" title="'.$attribute['title'].'"[/attach]';
break;
case "related":
if ($item["object-type"] != ACTIVITY_OBJ_BOOKMARK) {
@ -523,6 +520,18 @@ class ostatus {
}
}
// Only add additional data when there is no picture in the post
if (!strstr($item["body"],'[/img]')) {
$item["body"] = add_page_info_to_body($item["body"]);
}
// Mastodon Content Warning
if (($item["verb"] == ACTIVITY_POST) && $xpath->evaluate('boolean(atom:summary)', $entry)) {
$clear_text = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue;
$item["body"] = html2bbcode($clear_text) . '[spoiler]' . $item["body"] . '[/spoiler]';
}
$local_id = "";
$repeat_of = "";
@ -601,7 +610,6 @@ class ostatus {
foreach ($enclosures AS $link) {
$attribute = self::read_attributes($link);
if ($href != "") {
$enclosure = $attribute['href'];
if (strlen($item["attach"])) {
$item["attach"] .= ',';
}
@ -615,9 +623,6 @@ class ostatus {
}
}
//if ($enclosure != "")
// $item["body"] .= add_page_info($enclosure);
if (isset($item["parent-uri"])) {
$r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'",
intval($importer["uid"]), dbesc($item["parent-uri"]));

View file

@ -1424,15 +1424,8 @@ function prepare_body(&$item, $attach = false, $preview = false) {
$title = ((strlen(trim($mtch[4]))) ? escape_tags(trim($mtch[4])) : escape_tags($mtch[1]));
$title .= ' ' . $mtch[2] . ' ' . t('bytes');
if (($filetype == 'image') AND ($item['network'] == NETWORK_OSTATUS)) {
/// @todo Respect the spoiler for mastodon
$icon = '<img class="attached" src="'.$the_url.'" alt="" title="'.$title.'">';
$s .= '<br><a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attached" target="_blank" >' . $icon . '</a>';
} else {
$icon = '<div class="attachtype icon s22 type-' . $filetype . ' subtype-' . $filesubtype . '"></div>';
$as .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="_blank" >' . $icon . '</a>';
}
$icon = '<div class="attachtype icon s22 type-' . $filetype . ' subtype-' . $filesubtype . '"></div>';
$as .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="_blank" >' . $icon . '</a>';
}
}
}