Attachments do work now

This commit is contained in:
Michael 2018-10-03 17:36:55 +00:00
parent 78a7e130ae
commit a9a1ac808b
2 changed files with 72 additions and 2 deletions

View file

@ -43,6 +43,7 @@ use Friendica\Core\Config;
*
* To-do:
* - Polling the outboxes for missing content?
* - "about" needs HTML2BBCode parser
*/
class ActivityPub
{

View file

@ -21,6 +21,8 @@ use Friendica\Util\JsonLD;
use Friendica\Util\LDSignature;
use Friendica\Protocol\ActivityPub;
use Friendica\Model\Profile;
use Friendica\Core\Config;
use Friendica\Object\Image;
/**
* @brief ActivityPub Transmitter Protocol class
@ -33,7 +35,6 @@ use Friendica\Model\Profile;
* - Undo Announce
*
* General:
* - Attachments
* - nsfw (sensitive)
* - Queueing unsucessful deliveries
*/
@ -595,6 +596,74 @@ class Transmitter
return $tags;
}
/**
* @brief Adds attachment data to the JSON document
*
* @param array $item Data of the item that is to be posted
* @return attachment array
*/
private static function createAttachmentList($item)
{
$attachments = [];
$siteinfo = BBCode::getAttachedData($item['body']);
switch ($siteinfo['type']) {
case 'photo':
if (!empty($siteinfo['image'])) {
$imgdata = Image::getInfoFromURL($siteinfo['image']);
if ($imgdata) {
$attachments[] = ['type' => 'Document',
'mediaType' => $imgdata['mime'],
'url' => $siteinfo['image'],
'name' => null];
}
}
break;
case 'video':
$attachments[] = ['type' => 'Document',
'mediaType' => 'text/html; charset=UTF-8',
'url' => $siteinfo['url'],
'name' => defaults($siteinfo, 'title', $siteinfo['url'])];
break;
default:
break;
}
if (!Config::get('system', 'ostatus_not_attach_preview') && ($siteinfo['type'] != 'photo') && isset($siteinfo['image'])) {
$imgdata = Image::getInfoFromURL($siteinfo['image']);
if ($imgdata) {
$attachments[] = ['type' => 'Document',
'mediaType' => $imgdata['mime'],
'url' => $siteinfo['image'],
'name' => null];
}
}
$arr = explode('[/attach],', $item['attach']);
if (count($arr)) {
foreach ($arr as $r) {
$matches = false;
$cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|', $r, $matches);
if ($cnt) {
$attributes = ['type' => 'Document',
'mediaType' => $matches[3],
'url' => $matches[1],
'name' => null];
if (trim($matches[4]) != '') {
$attributes['name'] = trim($matches[4]);
}
$attachments[] = $attributes;
}
}
}
return $attachments;
}
/**
* @brief Fetches the "context" value for a givem item array from the "conversation" table
*
@ -674,7 +743,7 @@ class Transmitter
$data['diaspora:comment'] = $item['signed_text'];
}
$data['attachment'] = []; // @ToDo
$data['attachment'] = self::createAttachmentList($item);
$data['tag'] = self::createTagList($item);
$data = array_merge($data, self::createPermissionBlockForItem($item));