From 6989a3eaadd676c5c1b5fd523c4196d289423471 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 12 Jun 2023 19:05:37 +0000 Subject: fix string replacement if a match is available more than once --- Zotlabs/Lib/Activity.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 8bb157347..dbf7f7b46 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -468,14 +468,17 @@ class Activity { $token = get_iconfig($i, 'ocap', 'relay'); 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/')) { + if (str_starts_with($match[1], '=http') && str_contains($match[1], z_root() . '/photo/') && !in_array($match[1], $matches_processed)) { $i['body'] = str_replace($match[1], $match[1] . '?token=' . $token, $i['body']); $images[$n][2] = substr($match[1], 1) . '?token=' . $token; - } elseif (str_contains($match[2], z_root() . '/photo/')) { + $matches_processed[] = $match[1]; + } elseif (str_contains($match[2], z_root() . '/photo/') && !in_array($match[2], $matches_processed)) { $i['body'] = str_replace($match[2], $match[2] . '?token=' . $token, $i['body']); $images[$n][2] = $match[2] . '?token=' . $token; + $matches_processed[] = $match[2]; } } } -- cgit v1.2.3