From db1998e0c8f3050c4d93c26a5af69773a55c17d2 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 28 Jan 2015 14:22:52 -0800 Subject: limit the number of forums that can be tagged in a single post - default is 2. The reason is simple - count how many posts would be in transit simultaneously if this was unlimited and somebody tagged 40-50 forums. In practice when used legitimately - we've rarely seen more than two, in fact I don't recall seeing more than two ever. Typically it is one and occasionally two. Changing the default is tricky - a client system cannot do it, but the site hosting a forum can choose to. Since not all sites that host forums will choose to do so, the ordering of the mentions would then be important. --- include/items.php | 54 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 8 deletions(-) (limited to 'include/items.php') diff --git a/include/items.php b/include/items.php index 70802404a..756625d85 100755 --- a/include/items.php +++ b/include/items.php @@ -2852,12 +2852,27 @@ function tag_deliver($uid,$item_id) { if(preg_match($pattern,$body,$matches)) $tagged = true; - $pattern = '/@\!?\[zrl\=' . preg_quote($term['url'],'/') . '\]' . preg_quote($term['term'] . '+','/') . '\[\/zrl\]/'; - if(preg_match($pattern,$body,$matches)) - $plustagged = true; + $pattern = '/@\!?\[zrl\=(.*?)\](.*?)\+\[\/zrl\]/'; + + if(preg_match_all($pattern,$body,$matches,PREG_SET_ORDER)) { + $max_forums = get_config('system','max_tagged_forums'); + if(! $max_forums) + $max_forums = 2; + $matched_forums = 0; + foreach($matches as $match) { + $matched_forums ++; + if($term['url'] === $match[1] && $term['term'] === $match[2]) { + if($matched_forums <= $max_forums) { + $plustagged = true; + break; + } + logger('forum ' . $term['term'] . ' exceeded max_tagged_forums - ignoring'); + } + } + } if(! ($tagged || $plustagged)) { - logger('tag_deliver: mention was in a reshare - ignoring'); + logger('tag_deliver: mention was in a reshare or exceeded max_tagged_forums - ignoring'); return; } @@ -2974,6 +2989,7 @@ function tgroup_check($uid,$item) { } } + if($mention) { logger('tgroup_check: mention found for ' . $u[0]['channel_name']); } @@ -2982,6 +2998,7 @@ function tgroup_check($uid,$item) { // At this point we've determined that the person receiving this post was mentioned in it. // Now let's check if this mention was inside a reshare so we don't spam a forum + // note: $term has been set to the matching term $body = $item['body']; @@ -2993,14 +3010,35 @@ function tgroup_check($uid,$item) { $body = preg_replace('/\[share(.*?)\[\/share\]/','',$body); - $pattern = '/@\!?\[zrl\=' . preg_quote($term['url'],'/') . '\]' . preg_quote($term['term'] . '+','/') . '\[\/zrl\]/'; + +// $pattern = '/@\!?\[zrl\=' . preg_quote($term['url'],'/') . '\]' . preg_quote($term['term'] . '+','/') . '\[\/zrl\]/'; + + $pattern = '/@\!?\[zrl\=(.*?)\](.*?)\+\[\/zrl\]/'; + + $found = false; + + if(preg_match_all($pattern,$body,$matches,PREG_SET_ORDER)) { + $max_forums = get_config('system','max_tagged_forums'); + if(! $max_forums) + $max_forums = 2; + $matched_forums = 0; + foreach($matches as $match) { + $matched_forums ++; + if($term['url'] === $match[1] && $term['term'] === $match[2]) { + if($matched_forums <= $max_forums) { + $found = true; + break; + } + logger('forum ' . $term['term'] . ' exceeded max_tagged_forums - ignoring'); + } + } + } - if(! preg_match($pattern,$body,$matches)) { - logger('tgroup_check: mention was in a reshare - ignoring'); + if(! $found) { + logger('tgroup_check: mention was in a reshare or exceeded max_tagged_forums - ignoring'); return false; } - return true; } -- cgit v1.2.3 From a4960360669daa0a0c842427185ce1ada3b4ab97 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 28 Jan 2015 20:56:04 -0800 Subject: local_user => local_channel --- include/items.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'include/items.php') diff --git a/include/items.php b/include/items.php index 756625d85..a5a42d23b 100755 --- a/include/items.php +++ b/include/items.php @@ -1967,7 +1967,7 @@ function item_store($arr,$allow_exec = false) { $arr['body'] = z_input_filter($arr['uid'],$arr['body'],$arr['mimetype']); - if(local_user() && (! $arr['sig'])) { + if(local_channel() && (! $arr['sig'])) { $channel = get_app()->get_channel(); if($channel['channel_hash'] === $arr['author_xchan']) { $arr['sig'] = base64url_encode(rsa_sign($arr['body'],$channel['channel_prvkey'])); @@ -2355,7 +2355,7 @@ function item_store_update($arr,$allow_exec = false) { // apply the input filter here - if it is obscured it has been filtered already $arr['body'] = z_input_filter($arr['uid'],$arr['body'],$arr['mimetype']); - if(local_user() && (! $arr['sig'])) { + if(local_channel() && (! $arr['sig'])) { $channel = get_app()->get_channel(); if($channel['channel_hash'] === $arr['author_xchan']) { $arr['sig'] = base64url_encode(rsa_sign($arr['body'],$channel['channel_prvkey'])); @@ -3949,7 +3949,7 @@ function retain_item($id) { function drop_items($items) { $uid = 0; - if(! local_user() && ! remote_user()) + if(! local_channel() && ! remote_user()) return; if(count($items)) { @@ -4005,7 +4005,7 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL,$force = fal $ok_to_delete = true; // owner deletion - if(local_user() && local_user() == $item['uid']) + if(local_channel() && local_channel() == $item['uid']) $ok_to_delete = true; // author deletion @@ -4472,7 +4472,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C $r = q("SELECT abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d and abook_channel = %d and not ( abook_flags & " . intval(ABOOK_FLAG_BLOCKED) . ")>0 limit 1", intval($arr['cid']), - intval(local_user()) + intval(local_channel()) ); if($r) { $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND uid = " . intval($arr['uid']) . " AND ( author_xchan = '" . dbesc($r[0]['abook_xchan']) . "' or owner_xchan = '" . dbesc($r[0]['abook_xchan']) . "' ) and item_restrict = 0 ) "; -- cgit v1.2.3 From e157371c39121db472cbc45b59ac89d847788648 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 28 Jan 2015 20:58:59 -0800 Subject: remote_user => remote_channel --- include/items.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/items.php') diff --git a/include/items.php b/include/items.php index a5a42d23b..c34e694ac 100755 --- a/include/items.php +++ b/include/items.php @@ -3949,7 +3949,7 @@ function retain_item($id) { function drop_items($items) { $uid = 0; - if(! local_channel() && ! remote_user()) + if(! local_channel() && ! remote_channel()) return; if(count($items)) { -- cgit v1.2.3