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

This commit is contained in:
Mike Macgirvin 2024-09-01 10:56:16 +10:00
commit ca14a11d81
3 changed files with 25 additions and 16 deletions

View file

@ -4813,10 +4813,10 @@ class Activity
if (isset($a['image'])) {
if (self::media_not_in_body($a['image'], $item['body']) && self::media_not_in_body($a['href'], $item['body'])) {
if (isset($a['name']) && $a['name']) {
$alt = htmlspecialchars($a['name'], ENT_QUOTES, 'UTF-8', false);
// Escape brackets by converting to unicode full-width bracket since regular brackets will confuse multicode/bbcode parsing.
// The full width bracket isn't quite as alien looking as most other unicode bracket replacements.
$alt = str_replace(['[', ']', '"'], ['[', ']', '\"'], $alt);
// Do the same for double-quotes; which may present issues with the HTML purifier and when rendered as HTML attributes.
$alt = str_replace(['[', ']', '\\"', '\"', '"', '"'], ['[', ']', '"', '"', '"', '"'], $a['name']); $alt = htmlspecialchars($alt, ENT_QUOTES, 'UTF-8', false);
$item['body'] .= "\n\n" . '[img alt="' . $alt . '"]' . $a['href'] . '[/img]';
} else {
$item['body'] .= "\n\n" . '[img]' . $a['href'] . '[/img]';
@ -4826,10 +4826,10 @@ class Activity
}
elseif (self::media_not_in_body($a['href'], $item['body'])) {
if (isset($a['name']) && $a['name']) {
$alt = htmlspecialchars($a['name'], ENT_QUOTES, 'UTF-8', false);
// Escape brackets by converting to unicode full-width bracket since regular brackets will confuse multicode/bbcode parsing.
// The full width bracket isn't quite as alien looking as most other unicode bracket replacements.
$alt = str_replace(['[', ']', '"'], ['[', ']', '\"'], $alt);
// Do the same for double-quotes; which may present issues with the HTML purifier and when rendered as HTML attributes.
$alt = str_replace(['[', ']', '\\"', '\"', '"', '"'], ['[', ']', '"', '"', '"', '"'], $a['name']); $alt = htmlspecialchars($alt, ENT_QUOTES, 'UTF-8', false);
$item['body'] .= "\n\n" . '[img alt="' . $alt . '"]' . $a['href'] . '[/img]';
} else {
$item['body'] .= "\n\n" . '[img]' . $a['href'] . '[/img]';
@ -4839,8 +4839,7 @@ class Activity
if (array_key_exists('type', $a) && stripos($a['type'], 'video') !== false) {
if (self::media_not_in_body($a['href'], $item['body'])) {
if (isset($a['name']) && $a['name']) {
$alt = htmlspecialchars($a['name'], ENT_QUOTES, 'UTF-8', false);
$alt = str_replace(['[', ']'], ['[', ']'], $alt);
$alt = str_replace(['[', ']', '\\"', '\"', '"', '"'], ['[', ']', '"', '"', '"', '"'], $a['name']); $alt = htmlspecialchars($alt, ENT_QUOTES, 'UTF-8', false);
$item['body'] .= "\n\n" . '[video title="' . $alt . '"]' . $a['href'] . '[/video]';
} else {
$item['body'] .= "\n\n" . '[video]' . $a['href'] . '[/video]';
@ -4852,7 +4851,7 @@ class Activity
$item['body'] .= "\n\n" . '[audio]' . $a['href'] . '[/audio]';
}
}
if (!isset($a['type']) && ActivityStreams::is_url($a['href']) && !strpos($item['body'], $a['href'])) {
if ((!isset($a['type']) || $a['type'] === 'Link') && ActivityStreams::is_url($a['href']) && !strpos($item['body'], $a['href'])) {
$li = Url::get(z_root() . '/linkinfo?binurl=' . bin2hex($a['href']));
if ($li['success'] && $li['body']) {
$item['body'] .= "\n" . $li['body'];

View file

@ -2084,7 +2084,7 @@ class Channel
{
$pubkey = (new Multibase())->publicKey($channel['channel_epubkey']);
$nomadic = PConfig::Get($channel['channel_id'], 'system', 'nomadicAP');
if (!str_contains($id, '/.well-known/apgateway/')) {
if (!str_contains($id, '/.well-known/apgateway/') && !str_starts_with($id,'ap://')) {
$nomadic = false;
}
return (($nomadic) ? Channel::getDid($channel) : Channel::url($channel) . '#' . $pubkey);

View file

@ -6,6 +6,7 @@ namespace Code\Module;
use App;
use Code\Lib\ActorId;
use Code\Lib\Time;
use Code\Web\HTTPSig;
use Code\Lib\ActivityStreams;
@ -261,7 +262,7 @@ class Inbox extends Controller
$collections = Activity::get_actor_collections($observer_hash);
if (is_array($collections) && in_array($collections['followers'], $AS->recips)
if ((is_array($collections) && in_array($collections['followers'], $AS->recips))
|| in_array(ACTIVITY_PUBLIC_INBOX, $AS->recips)
|| in_array('Public', $AS->recips)
|| in_array('as:Public', $AS->recips)) {
@ -280,14 +281,23 @@ class Inbox extends Controller
// deliver to anybody at this site directly addressed
$channel_addr = '';
foreach($AS->recips as $recip) {
if (str_starts_with($recip, z_root())) {
$channel_addr .= '\'' . dbesc(basename($recip)) . '\',';
if (!str_starts_with($recip, z_root())) {
continue;
}
$actorId = new ActorId($recip);
if ($actorId->getType() === ActorId::ACTORID_TYPE_URL) {
$query = q("SELECT * from channel left join xchan on channel_hash = xchan_hash where xchan_url = '%s' and channel_removed = 0",
dbesc($recip)
);
}
else {
$query = q("select * from channel left join xchan on channel_hash = xchan_hash where xchan_epubkey = '%s' and channel_removed = 0",
dbesc(str_replace('did:key:', '', $actorId->getId()))
);
}
if ($query) {
$channels[] = array_shift($query);
}
}
if ($channel_addr) {
$channel_addr = rtrim($channel_addr, ',');
$channels = dbq("SELECT * FROM channel
WHERE channel_address IN ($channel_addr) AND channel_removed = 0");
}
}