mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 23:55:19 +00:00
duplicated images revisited
This commit is contained in:
parent
f4ae615bad
commit
9ee206267c
3 changed files with 38 additions and 7 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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']),
|
||||
|
|
|
@ -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 ]);
|
||||
|
|
Loading…
Reference in a new issue