From 439e62d1d487fd48e36775b0ae01939cb516e517 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Tue, 21 Feb 2012 18:39:55 +0100 Subject: [PATCH] SN addon: only shorteb links if neede --- statusnet/statusnet.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 2972f6622..382024831 100755 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -442,12 +442,14 @@ function statusnet_post_hook(&$a,&$b) { $tmp = preg_replace( '/\[bookmark\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\](\w+.*?)\[\/bookmark\]/i', '$2 $1', $tmp); // find all http or https links in the body of the entry and // apply the shortener if the link is longer then 20 characters - preg_match_all ( '/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/i', $tmp, $allurls ); - foreach ($allurls as $url) { - foreach ($url as $u) { - if (strlen($u)>20) { - $sl = short($u); - $tmp = str_replace( $u, $sl, $tmp ); + if (( strlen($tmp)>$max_char ) && ( $max_char > 0 )) { + preg_match_all ( '/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/i', $tmp, $allurls ); + foreach ($allurls as $url) { + foreach ($url as $u) { + if (strlen($u)>20) { + $sl = short($u); + $tmp = str_replace( $u, $sl, $tmp ); + } } } }