diff --git a/Code/Lib/Activity.php b/Code/Lib/Activity.php index 4ff51b14b..5e6291cbb 100644 --- a/Code/Lib/Activity.php +++ b/Code/Lib/Activity.php @@ -592,11 +592,14 @@ class Activity $atts = ((is_array($item['attach'])) ? $item['attach'] : json_decode($item['attach'], true)); if ($atts) { foreach ($atts as $att) { + $name = ''; if (isset($att['type']) && str_contains($att['type'], 'image')) { if (!empty($att['href'])) { - $name = ($att['title']) ?? ''; + if ($att['name']) { + $name = $att['name']; + } if (! $name) { - $name = ($att['name']) ?? ''; + $name = $att['title']; } $ret[] = [ 'type' => 'Image', @@ -939,11 +942,15 @@ class Activity $activity['tag'] = $t; } - $a = self::encode_attachment($item); - if ($a) { - $activity['attachment'] = $a; + if ($obj && $obj['attachment']) { + $activity['attachment'] = $obj['attachment']; + } + else { + $a = self::encode_attachment($item); + if ($a) { + $activity['attachment'] = $a; + } } - // addressing madness diff --git a/Code/Module/Item.php b/Code/Module/Item.php index 8f2e956a8..223bbff00 100644 --- a/Code/Module/Item.php +++ b/Code/Module/Item.php @@ -44,6 +44,7 @@ use App; use URLify; require_once('include/attach.php'); +require_once('include/photos.php'); require_once('include/bbcode.php'); require_once('include/security.php'); @@ -1143,8 +1144,15 @@ class Item extends Controller else { $r = attach_by_hash_nodata($hash, $observer['xchan_hash'], $rev); if ($r['success']) { + $href = z_root() . '/attach/' . $r['data']['hash']; + if ($r['data']['is_photo']) { + $href = z_root() . '/photo/' . $r['data']['hash'] . '-1.' . photoExtensionFromType($r['data']['filetype']); + if ($token) { + $href .= '?token=' . $token; + } + } $attachments[] = [ - 'href' => z_root() . '/attach/' . $r['data']['hash'], + 'href' => $href, 'length' => $r['data']['filesize'], 'type' => $r['data']['filetype'], 'title' => urlencode($r['data']['filename']), diff --git a/include/photos.php b/include/photos.php index 28ce9a084..6e06fa25d 100644 --- a/include/photos.php +++ b/include/photos.php @@ -575,6 +575,7 @@ function photo_upload($channel, $observer, $args) $ret['success'] = true; $ret['item'] = $arr; $ret['body'] = $obj_body; + $ret['filename'] = $url[1]['href']; $ret['resource_id'] = $photo_hash; $ret['photoitem_id'] = $item_id; @@ -1049,6 +1050,21 @@ function profile_photo_set_profile_perms($uid, $profileid = 0) } } +function photoExtensionFromType($type) +{ + + $t = [ + 'image/jpeg' => 'jpg', + 'image/png' => 'png', + 'image/gif' => 'gif', + 'image/webp' => 'webp', + ]; + + return ($t[$type]) ?? ''; + +} + + function fetch_image_from_url($url, &$mimetype) { $x = Url::get($url, [ 'novalidate' => true ]);