mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 23:55:19 +00:00
more photo album -> collection work
This commit is contained in:
parent
5cde03fa49
commit
1e46ff151a
2 changed files with 71 additions and 6 deletions
|
@ -394,6 +394,69 @@ class Activity
|
|||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
public static function encode_photo_collection($items, $id, $type, $activitypub = false, $attributedTo = '', $total = 0): array
|
||||
{
|
||||
|
||||
$ret = [
|
||||
'id' => z_root() . '/' . $id,
|
||||
'type' => $type,
|
||||
'totalItems' => $total,
|
||||
];
|
||||
if ($attributedTo) {
|
||||
$ret['attributedTo'] = $attributedTo;
|
||||
}
|
||||
|
||||
$content = '';
|
||||
|
||||
if ($items) {
|
||||
$x = [];
|
||||
foreach ($items as $i) {
|
||||
$m = ObjCache::Get($i['mid']);
|
||||
if ($m) {
|
||||
$t = json_decode($m, true);
|
||||
} else {
|
||||
$t = self::encode_activity($i, $activitypub);
|
||||
// These activities are unlikely to have a context or signature, which are
|
||||
// usually added during 'delivery'. Add them now.
|
||||
if (!$t['@context']) {
|
||||
$ldContext = ['@context' => Activity::ap_schema()];
|
||||
$t = array_merge($ldContext, $t);
|
||||
}
|
||||
if (!$t['proof']) {
|
||||
$channel = Channel::from_hash($i['author_xchan']);
|
||||
if ($channel) {
|
||||
$t['proof'] = (new JcsEddsa2022())->sign($t, $channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($t) {
|
||||
$x[] = $t;
|
||||
$image = $t['object']['url'][1];
|
||||
if ($image) {
|
||||
$alt = 'alt="' . $image['summary'] . '"' ;
|
||||
$width = $image['width'];
|
||||
$height = $image['height'];
|
||||
$tag = '[zmg width="' . $width . '" height="' . $height . '" ' . "\n\n" . $alt . "\n\n" . ']';
|
||||
$content .= '[zmg width="' . $width . '" height="' . $height . '" ' . "\n\n" . $alt . "\n\n" . ']'
|
||||
. $image['href'] . '[/zmg]';
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($type === 'OrderedCollection') {
|
||||
$ret['orderedItems'] = $x;
|
||||
} else {
|
||||
$ret['items'] = $x;
|
||||
}
|
||||
$ret['content'] = $content;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static function encode_follow_collection($items, $id, $type, $total = 0, $extra = null): array
|
||||
{
|
||||
|
||||
|
|
|
@ -80,7 +80,8 @@ class Album extends Controller
|
|||
intval($channel['channel_id'])
|
||||
);
|
||||
|
||||
$contents = [];
|
||||
$collection = [];
|
||||
$content = '';
|
||||
$item_normal_not_hidden = item_normal_not_hidden();
|
||||
if ($x) {
|
||||
foreach ($x as $xv) {
|
||||
|
@ -93,17 +94,18 @@ class Album extends Controller
|
|||
intval($channel['channel_id'])
|
||||
);
|
||||
if ($query) {
|
||||
$contents[] = array_shift($query);
|
||||
$collection[] = array_shift($query);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($contents) {
|
||||
xchan_query($contents);
|
||||
$contents = fetch_post_tags($contents);
|
||||
if ($collection) {
|
||||
xchan_query($collection);
|
||||
$collection = fetch_post_tags($collection);
|
||||
}
|
||||
|
||||
$obj = Activity::encode_item_collection($contents, App::$query_string, 'OrderedCollection', true, z_root() . '/channel/' . $channel['channel_hash'], count($contents));
|
||||
$obj = Activity::encode_photo_collection($collection, App::$query_string, 'Collection', true, z_root() . '/channel/' . $channel['channel_hash'], count($collection));
|
||||
$obj['content'] = bbcode($obj['content'], ['export' => true]);
|
||||
as_return_and_die($obj, $channel);
|
||||
}
|
||||
goaway(z_root() . '/photos/' . argv(1) . '/album/' . argv(2));
|
||||
|
|
Loading…
Reference in a new issue