more photo album -> collection work

This commit is contained in:
Mike Macgirvin 2024-06-12 11:11:16 +10:00
parent 5cde03fa49
commit 1e46ff151a
2 changed files with 71 additions and 6 deletions

View file

@ -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
{

View file

@ -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));