From a869bd2fe56d1795ab1d8744796a6e908e5adc29 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 7 Feb 2012 02:16:28 -0800 Subject: [PATCH] don't link tags enclosed inside Diaspora links --- include/diaspora.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/diaspora.php b/include/diaspora.php index cded389c38..2a4c8b9da4 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -673,6 +673,14 @@ function diaspora_post($importer,$xml) { if(strpos($tag,'#') === 0) { if(strpos($tag,'[url=')) continue; + + // don't link tags that are already embedded in links + + if(preg_match('/\[(.*?)' . preg_quote($tag) . '(.*?)\]/',$body)) + continue; + if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag) . '(.*?)\)/',$body)) + continue; + $basetag = str_replace('_',' ',substr($tag,1)); $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body); if(strlen($str_tags)) @@ -830,6 +838,15 @@ function diaspora_reshare($importer,$xml) { if(strpos($tag,'#') === 0) { if(strpos($tag,'[url=')) continue; + + // don't link tags that are already embedded in links + + if(preg_match('/\[(.*?)' . preg_quote($tag) . '(.*?)\]/',$body)) + continue; + if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag) . '(.*?)\)/',$body)) + continue; + + $basetag = str_replace('_',' ',substr($tag,1)); $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body); if(strlen($str_tags)) @@ -1062,6 +1079,15 @@ function diaspora_comment($importer,$xml,$msg) { if(strpos($tag,'#') === 0) { if(strpos($tag,'[url=')) continue; + + // don't link tags that are already embedded in links + + if(preg_match('/\[(.*?)' . preg_quote($tag) . '(.*?)\]/',$body)) + continue; + if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag) . '(.*?)\)/',$body)) + continue; + + $basetag = str_replace('_',' ',substr($tag,1)); $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body); if(strlen($str_tags)) -- 2.39.5