Adding media attachments to Diaspora posts if they are only attached and not embedded in the body
This commit is contained in:
parent
ef43aa1a4d
commit
9afa3610cf
|
@ -45,6 +45,7 @@ use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Conversation;
|
use Friendica\Model\Conversation;
|
||||||
use Friendica\Model\FileTag;
|
use Friendica\Model\FileTag;
|
||||||
use Friendica\Model\Item;
|
use Friendica\Model\Item;
|
||||||
|
use Friendica\Model\ItemURI;
|
||||||
use Friendica\Model\Notification;
|
use Friendica\Model\Notification;
|
||||||
use Friendica\Model\Photo;
|
use Friendica\Model\Photo;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
|
@ -613,6 +614,8 @@ function item_post(App $a) {
|
||||||
$datarray['origin'] = $origin;
|
$datarray['origin'] = $origin;
|
||||||
$datarray['object'] = $object;
|
$datarray['object'] = $object;
|
||||||
|
|
||||||
|
$datarray["uri-id"] = ItemURI::getIdByURI($datarray["uri"]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These fields are for the convenience of addons...
|
* These fields are for the convenience of addons...
|
||||||
* 'self' if true indicates the owner is posting on their own wall
|
* 'self' if true indicates the owner is posting on their own wall
|
||||||
|
|
|
@ -2485,7 +2485,6 @@ class Diaspora
|
||||||
|
|
||||||
Tag::storeFromBody($datarray['uri-id'], $datarray["body"]);
|
Tag::storeFromBody($datarray['uri-id'], $datarray["body"]);
|
||||||
|
|
||||||
//Post\Media::copy($original_item['uri-id'], $datarray['uri-id']);
|
|
||||||
$datarray["app"] = $original_item["app"];
|
$datarray["app"] = $original_item["app"];
|
||||||
|
|
||||||
$datarray["plink"] = self::plink($author, $guid);
|
$datarray["plink"] = self::plink($author, $guid);
|
||||||
|
@ -3369,6 +3368,36 @@ class Diaspora
|
||||||
return $eventdata;
|
return $eventdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add media attachments to the body
|
||||||
|
*
|
||||||
|
* @param array $item
|
||||||
|
* @return string body
|
||||||
|
*/
|
||||||
|
private static function addAttachments(array $item)
|
||||||
|
{
|
||||||
|
$body = $item['body'];
|
||||||
|
|
||||||
|
foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::IMAGE, Post\Media::AUDIO, Post\Media::VIDEO]) as $media) {
|
||||||
|
if (Item::containsLink($item['body'], $media['url'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($media['type'] == Post\Media::IMAGE) {
|
||||||
|
if (!empty($media['description'])) {
|
||||||
|
$body .= "\n[img=" . $media['url'] . ']' . $media['description'] .'[/img]';
|
||||||
|
} else {
|
||||||
|
$body .= "\n[img]" . $media['url'] .'[/img]';
|
||||||
|
}
|
||||||
|
} elseif ($media['type'] == Post\Media::AUDIO) {
|
||||||
|
$body .= "\n[audio]" . $media['url'] . "[/audio]\n";
|
||||||
|
} elseif ($media['type'] == Post\Media::VIDEO) {
|
||||||
|
$body .= "\n[video]" . $media['url'] . "[/video]\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a post (status message or reshare)
|
* Create a post (status message or reshare)
|
||||||
*
|
*
|
||||||
|
@ -3409,7 +3438,7 @@ class Diaspora
|
||||||
$type = "reshare";
|
$type = "reshare";
|
||||||
} else {
|
} else {
|
||||||
$title = $item["title"];
|
$title = $item["title"];
|
||||||
$body = $item["body"];
|
$body = self::addAttachments($item);
|
||||||
|
|
||||||
// Fetch the title from an attached link - if there is one
|
// Fetch the title from an attached link - if there is one
|
||||||
if (empty($item["title"]) && DI::pConfig()->get($owner['uid'], 'system', 'attach_link_title')) {
|
if (empty($item["title"]) && DI::pConfig()->get($owner['uid'], 'system', 'attach_link_title')) {
|
||||||
|
@ -3623,7 +3652,7 @@ class Diaspora
|
||||||
$thread_parent_item = Post::selectFirst(['guid', 'author-id', 'author-link', 'gravity'], ['uri' => $item['thr-parent'], 'uid' => $item['uid']]);
|
$thread_parent_item = Post::selectFirst(['guid', 'author-id', 'author-link', 'gravity'], ['uri' => $item['thr-parent'], 'uid' => $item['uid']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$body = $item["body"];
|
$body = self::addAttachments($item);
|
||||||
|
|
||||||
// The replied to autor mention is prepended for clarity if:
|
// The replied to autor mention is prepended for clarity if:
|
||||||
// - Item replied isn't yours
|
// - Item replied isn't yours
|
||||||
|
|
Loading…
Reference in New Issue
Block a user