From db038c56542f7fb9658c3b7a703e50efe7823014 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 18 Apr 2013 17:55:35 -0700 Subject: turn naked links in posts into zrl's if we've got a hubloc for the site --- include/bbcode.php | 1 - include/items.php | 25 +++++++++++++++++++++++++ mod/item.php | 7 +++++++ mod/post.php | 2 +- version.inc | 2 +- 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index 44bde9acb..7a1e3a5e8 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -268,7 +268,6 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/$urlchars+)/ism", '$1$2', $Text); -// $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/$urlchars+)\{zid\}($urlchars*)/ism", '$1$2$3', $Text); $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); diff --git a/include/items.php b/include/items.php index 954042b65..088aa11a1 100755 --- a/include/items.php +++ b/include/items.php @@ -53,6 +53,31 @@ function collect_recipients($item,&$private) { } +/** + * @function red_zrl_callback + * preg_match function when fixing 'naked' links in mod item.php + * Check if we've got a hubloc for the site and use a zrl if we do, a url if we don't. + * + */ + + +function red_zrl_callback($matches) { + $m = @parse_url($matches[2]); + $zrl = false; + if($m['host']) { + $r = q("select hubloc_url from hubloc where hubloc_host = '%s' limit 1", + dbesc($m['host']) + ); + if($r) + $zrl = true; + } + if($zrl) + return $matches[1] . '[zrl=' . $matches[2] . ']' . $matches[2] . '[/zrl]'; + return $matches[0]; +} + + + /** * @function post_activity_item($arr) * diff --git a/mod/item.php b/mod/item.php index a9b658441..814c2f0c6 100644 --- a/mod/item.php +++ b/mod/item.php @@ -320,6 +320,13 @@ function item_post(&$a) { } + /** + * fix naked links by passing through a callback to see if this is a red site + * (already known to us) which will get a zrl, otherwise link with url + */ + + $body = preg_replace_callback("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\+\,]+)/ism", 'red_zrl_callback', $body); + /** * * When a photo was uploaded into the message using the (profile wall) ajax diff --git a/mod/post.php b/mod/post.php index 5919ed2b4..5ec7eabca 100644 --- a/mod/post.php +++ b/mod/post.php @@ -1,4 +1,4 @@ -