diff options
author | Mario Vavti <mario@mariovavti.com> | 2024-11-03 11:45:08 +0100 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2024-11-03 11:45:08 +0100 |
commit | d25314c75b0941b91f73eb39cba489ec6b48c301 (patch) | |
tree | 7cdb40cf9e1d17c22a363f8baaaf03a099281c58 /Zotlabs/Lib/Activity.php | |
parent | 005d4ad35143e417b7c1dbfbf38417dee03e9608 (diff) | |
parent | e20327d26760adbea6554268119bc671e0199afb (diff) | |
download | volse-hubzilla-d25314c75b0941b91f73eb39cba489ec6b48c301.tar.gz volse-hubzilla-d25314c75b0941b91f73eb39cba489ec6b48c301.tar.bz2 volse-hubzilla-d25314c75b0941b91f73eb39cba489ec6b48c301.zip |
Merge branch 'dev' into containers
Diffstat (limited to 'Zotlabs/Lib/Activity.php')
-rw-r--r-- | Zotlabs/Lib/Activity.php | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index c95552562..b7f40f632 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -504,15 +504,21 @@ class Activity { $ret['diaspora:guid'] = $i['uuid']; $images = []; + $audios = []; + $videos = []; + $has_images = preg_match_all('/\[[zi]mg(.*?)](.*?)\[/ism', $i['body'], $images, PREG_SET_ORDER); + $has_audios = preg_match_all('/\[zaudio](.*?)\[/ism', $i['body'], $audios, PREG_SET_ORDER); + $has_videos = preg_match_all('/\[zvideo](.*?)\[/ism', $i['body'], $videos, PREG_SET_ORDER); // provide ocap access token for private media. // set this for descendants even if the current item is not private // because it may have been relayed from a private item. $token = IConfig::Get($i, 'ocap', 'relay'); + $matches_processed = []; + if ($token && $has_images) { - $matches_processed = []; for ($n = 0; $n < count($images); $n++) { $match = $images[$n]; if (str_starts_with($match[1], '=http') && str_contains($match[1], z_root() . '/photo/') && !in_array($match[1], $matches_processed)) { @@ -527,6 +533,28 @@ class Activity { } } + if ($token && $has_audios) { + for ($n = 0; $n < count($audios); $n++) { + $match = $audios[$n]; + if (str_contains($match[1], z_root() . '/attach/') && !in_array($match[1], $matches_processed)) { + $i['body'] = str_replace($match[1], $match[1] . '?token=' . $token, $i['body']); + $audios[$n][1] = $match[1] . '?token=' . $token; + $matches_processed[] = $match[1]; + } + } + } + + if ($token && $has_videos) { + for ($n = 0; $n < count($videos); $n++) { + $match = $videos[$n]; + if (str_contains($match[1], z_root() . '/attach/') && !in_array($match[1], $matches_processed)) { + $i['body'] = str_replace($match[1], $match[1] . '?token=' . $token, $i['body']); + $videos[$n][1] = $match[1] . '?token=' . $token; + $matches_processed[] = $match[1]; + } + } + } + if ($i['title']) $ret['name'] = unescape_tags($i['title']); @@ -733,6 +761,8 @@ class Activity { $ret = []; + $token = IConfig::Get($item, 'ocap', 'relay'); + if (!$iconfig && array_key_exists('attach', $item)) { $atts = ((is_array($item['attach'])) ? $item['attach'] : json_decode($item['attach'], true)); if ($atts) { @@ -741,11 +771,17 @@ class Activity { continue; } - if (isset($att['type']) && strpos($att['type'], 'image')) { - $ret[] = ['type' => 'Image', 'mediaType' => $att['type'], 'name' => $att['title'], 'url' => $att['href']]; + if (str_starts_with($att['type'], 'image')) { + $ret[] = ['type' => 'Image', 'mediaType' => $att['type'], 'name' => $att['title'], 'url' => $att['href'] . (($token) ? '?token=' . $token : '')]; + } + elseif (str_starts_with($att['type'], 'audio')) { + $ret[] = ['type' => 'Audio', 'mediaType' => $att['type'], 'name' => $att['title'], 'url' => $att['href'] . (($token) ? '?token=' . $token : '')]; + } + elseif (str_starts_with($att['type'], 'video')) { + $ret[] = ['type' => 'Video', 'mediaType' => $att['type'], 'name' => $att['title'], 'url' => $att['href'] . (($token) ? '?token=' . $token : '')]; } else { - $ret[] = ['type' => 'Link', 'mediaType' => $att['type'], 'name' => $att['title'], 'href' => $att['href']]; + $ret[] = ['type' => 'Link', 'mediaType' => $att['type'], 'name' => $att['title'], 'href' => $att['href'] . (($token) ? '?token=' . $token : '')]; } } } |