From 4eb8921635add33215bffc4820f95c34b902f819 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 21 Sep 2021 11:07:23 +0200 Subject: improve item_url_replace() - fixes #1507 --- include/text.php | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index 2d863c5ae..7e1dd13c4 100644 --- a/include/text.php +++ b/include/text.php @@ -3216,38 +3216,46 @@ function item_url_replace($channel,&$item,$old,$new,$oldnick = '') { if($item['attach']) { json_url_replace($old,$new,$item['attach']); - if($oldnick) + if($oldnick && ($oldnick !== $channel['channel_address'])) json_url_replace('/' . $oldnick . '/' ,'/' . $channel['channel_address'] . '/' ,$item['attach']); } if($item['object']) { json_url_replace($old,$new,$item['object']); - if($oldnick) + if($oldnick && ($oldnick !== $channel['channel_address'])) json_url_replace('/' . $oldnick . '/' ,'/' . $channel['channel_address'] . '/' ,$item['object']); } if($item['target']) { json_url_replace($old,$new,$item['target']); - if($oldnick) + if($oldnick && ($oldnick !== $channel['channel_address'])) json_url_replace('/' . $oldnick . '/' ,'/' . $channel['channel_address'] . '/' ,$item['target']); } - $item['body'] = preg_replace("/(\[zrl=".preg_quote($old,'/')."\/(photo|photos|gallery)\/".$channel['channel_address'].".+\]\[zmg=\d+x\d+\])".preg_quote($old,'/')."\/(.+\[\/zmg\])/", '${1}'.$new.'/${3}', $item['body']); - $item['body'] = preg_replace("/".preg_quote($old,'/')."\/(search|\w+\/".$channel['channel_address'].")/", $new.'/${1}', $item['body']); + $root_replaced = null; + $nick_replaced = null; - $item['sig'] = base64url_encode(Crypto::sign($item['body'],$channel['channel_prvkey'])); - $item['item_verified'] = 1; + $item['body'] = str_replace($old, $new, $item['body'], $root_replaced); + + if($oldnick && ($oldnick !== $channel['channel_address'])) { + $item['body'] = str_replace('/' . $oldnick . '/', '/' . $channel['channel_address'] . '/', $item['body'], $nick_replaced); + } + + if ($root_replaced || $nick_replaced) { + $item['sig'] = Libzot::sign($item['body'], $channel['channel_prvkey']); + $item['item_verified'] = 1; + } $item['plink'] = str_replace($old,$new,$item['plink']); - if($oldnick) + if($oldnick && ($oldnick !== $channel['channel_address'])) $item['plink'] = str_replace('/' . $oldnick . '/' ,'/' . $channel['channel_address'] . '/' ,$item['plink']); $item['llink'] = str_replace($old,$new,$item['llink']); - if($oldnick) + if($oldnick && ($oldnick !== $channel['channel_address'])) $item['llink'] = str_replace('/' . $oldnick . '/' ,'/' . $channel['channel_address'] . '/' ,$item['llink']); if($item['term']) { for($x = 0; $x < count($item['term']); $x ++) { $item['term'][$x]['url'] = str_replace($old,$new,$item['term'][$x]['url']); - if ($oldnick) { + if ($oldnick && ($oldnick !== $channel['channel_address'])) { $item['term'][$x]['url'] = str_replace('/' . $oldnick . '/' ,'/' . $channel['channel_address'] . '/' ,$item['term'][$x]['url']); } } -- cgit v1.2.3