Merge branch 'nomadic' of codeberg.org:streams/streams into nomadic

This commit is contained in:
Mike Macgirvin 2024-04-06 19:53:24 +11:00
commit af8f6e7461
2 changed files with 21 additions and 18 deletions

View file

@ -9,6 +9,7 @@ use Code\Lib\Apps;
use Code\Lib\Activity;
use Code\Access\AccessControl;
use Code\Access\PermissionLimits;
use Code\Lib\Channel;
use Code\Lib\Time;
use Code\Web\HTTPHeaders;
use Code\Daemon\Run;
@ -266,7 +267,7 @@ function photo_upload($channel, $observer, $args)
'rel' => 'alternate',
'mediaType' => $type,
'summary' => $alt_desc,
'href' => z_root() . '/photo/' . $photo_hash . '-0.' . $ph->getExt(),
'href' => Channel::getDidResolver($channel) . '/photo/' . $photo_hash . '-0.' . $ph->getExt(),
'width' => $width,
'height' => $height
];
@ -290,7 +291,7 @@ function photo_upload($channel, $observer, $args)
'rel' => 'alternate',
'mediaType' => $type,
'summary' => $alt_desc,
'href' => z_root() . '/photo/' . $photo_hash . '-1.' . $ph->getExt(),
'href' => Channel::getDidResolver($channel) . '/photo/' . $photo_hash . '-1.' . $ph->getExt(),
'width' => $ph->getWidth(),
'height' => $ph->getHeight()
];
@ -309,7 +310,7 @@ function photo_upload($channel, $observer, $args)
'rel' => 'alternate',
'mediaType' => $type,
'summary' => $alt_desc,
'href' => z_root() . '/photo/' . $photo_hash . '-2.' . $ph->getExt(),
'href' => Channel::getDidResolver($channel) . '/photo/' . $photo_hash . '-2.' . $ph->getExt(),
'width' => $ph->getWidth(),
'height' => $ph->getHeight()
];
@ -328,7 +329,7 @@ function photo_upload($channel, $observer, $args)
'rel' => 'alternate',
'mediaType' => $type,
'summary' => $alt_desc,
'href' => z_root() . '/photo/' . $photo_hash . '-3.' . $ph->getExt(),
'href' => Channel::getDidResolver($channel) . '/photo/' . $photo_hash . '-3.' . $ph->getExt(),
'width' => $ph->getWidth(),
'height' => $ph->getHeight()
];
@ -356,7 +357,7 @@ function photo_upload($channel, $observer, $args)
'type' => 'Link',
'rel' => 'about',
'mediaType' => 'text/html',
'href' => z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash
'href' => Channel::getDidResolver($channel) . '/photos/image/' . $photo_hash
];
$item_hidden = (($visible) ? 0 : 1 );
@ -389,12 +390,12 @@ function photo_upload($channel, $observer, $args)
$height = $url[1]['height'];
$tag = (($r1) ? '[zmg width="' . $width . '" height="' . $height . '"' . $alt . ']' : '[zmg' . $alt . ']');
$author_link = '[zrl=' . z_root() . '/channel/' . $channel['channel_address'] . ']' . $channel['channel_name'] . '[/zrl]';
$author_link = '[zrl=' . Channel::getDidResolver($channel) . ']' . $channel['channel_name'] . '[/zrl]';
$photo_link = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' . t('a new photo') . '[/zrl]';
$photo_link = '[zrl=' . Channel::getDidResolver($channel) . '/photos/image/' . $photo_hash . ']' . t('a new photo') . '[/zrl]';
if (array_path_exists('/directory/hash',$args)) {
$album_link = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/album/' . $args['directory']['hash'] . ']' . ((strlen($album)) ? $album : '/') . '[/zrl]';
$album_link = '[zrl=' . Channel::getDidResolver($channel) . '/photos/album/' . $args['directory']['hash'] . ']' . ((strlen($album)) ? $album : '/') . '[/zrl]';
$activity_format = sprintf(t('%1$s posted %2$s to %3$s', 'photo_upload'), $author_link, $photo_link, $album_link);
}
else {
@ -405,8 +406,8 @@ function photo_upload($channel, $observer, $args)
// If uploaded into a post, this is the text that is returned to the webapp for inclusion in the post.
$obj_body = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']'
. $tag . z_root() . "/photo/{$photo_hash}-{$scale}." . $ph->getExt() . '[/zmg]'
$obj_body = '[zrl=' . Channel::getDidResolver($channel) . '/photos/image/' . $photo_hash . ']'
. $tag . Channel::getDidResolver($channel) . "/photo/{$photo_hash}-{$scale}." . $ph->getExt() . '[/zmg]'
. '[/zrl]';
$attribution = (Activity::actorEncode(($visitor) ?: $channel, false));
@ -430,7 +431,7 @@ function photo_upload($channel, $observer, $args)
if ($public) {
$object['to'] = [ ACTIVITY_PUBLIC_INBOX ];
$object['cc'] = [ z_root() . '/followers/' . $channel['channel_address'] ];
$object['cc'] = [ Channel::getDidResolver($channel) . '/followers' ];
} else {
$object['to'] = Activity::map_acl(array_merge($ac, ['item_private' => 1]));
}
@ -438,8 +439,8 @@ function photo_upload($channel, $observer, $args)
$target = [
'type' => 'orderedCollection',
'name' => ((strlen($album)) ? $album : '/'),
'id' => z_root() . '/album/' . $channel['channel_address'] . ((isset($args['folder'])) ? '/' . $args['folder'] : EMPTY_STR),
'attributedTo' => z_root() . '/channel/' . $channel['channel_address'],
'id' => Channel::getDidResolver($channel) . '/album/' . ((isset($args['folder'])) ? '/' . $args['folder'] : EMPTY_STR),
'attributedTo' => Channel::getDidResolver($channel),
];
$post_tags = [];
@ -515,7 +516,7 @@ function photo_upload($channel, $observer, $args)
}
} else {
$uuid = new_uuid();
$mid = z_root() . '/item/' . $uuid;
$mid = Channel::getDidResolver($channel) . '/item/' . $uuid;
$object['id'] = $mid;
@ -559,7 +560,7 @@ function photo_upload($channel, $observer, $args)
$arr['term'] = $post_tags;
}
$arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . urlencode($arr['mid']);
$arr['plink'] = $arr['mid'];
if ($lat || $lon) {
$arr['lat'] = floatval($lat);
@ -721,7 +722,7 @@ function photos_albums_list($channel, $observer, $sort_key = 'display_path', $di
'shorttext' => (($album['album']) ? ellipsify($album['album'], 28) : '/'),
'jstext' => (($album['album']) ? addslashes($album['album']) : '/'),
'total' => $album['total'],
'url' => z_root() . '/photos/' . $channel['channel_address'] . '/album/' . $album['folder'],
'url' => Channel::getDidResolver($channel) . '/photos/album/' . $album['folder'],
'urlencode' => urlencode($album['album']),
'bin2hex' => $album['folder']
];
@ -795,7 +796,7 @@ function photos_list_photos($channel, $observer, $album = '')
if ($r) {
for ($x = 0; $x < count($r); $x++) {
$r[$x]['src'] = z_root() . '/photo/' . $r[$x]['resource_id'] . '-' . $r[$x]['imgscale'];
$r[$x]['src'] = Channel::getDidResolver($channel) . '/photo/' . $r[$x]['resource_id'] . '-' . $r[$x]['imgscale'];
}
$ret['success'] = true;
$ret['photos'] = $r;

View file

@ -78,6 +78,8 @@ class Apresolver extends Controller
$partialPaths = [
'/files/' => '/cloud/' . $channel['channel_address'],
'/photos/' => '/photos/' . $channel['channel_address'],
'/album/' => '/album/' . $channel['channel_address'],
];
foreach ($systemPaths as $index => $localPath) {
@ -89,7 +91,7 @@ class Apresolver extends Controller
foreach ($partialPaths as $index => $localPath) {
if (str_starts_with($path, $index)) {
$suffix = substr($path, strlen($index));
return $localPath . $suffix;
return $localPath . '/' . ltrim($suffix, '/');
}
}
return $path;