aboutsummaryrefslogtreecommitdiffstats
path: root/include/items.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2015-01-28 14:22:52 -0800
committerfriendica <info@friendica.com>2015-01-28 14:22:52 -0800
commitdb1998e0c8f3050c4d93c26a5af69773a55c17d2 (patch)
tree0a1375ec236da4d561a6334dbf17b70cc7c7beda /include/items.php
parent4de6aec6574e956b45aedfb4e72af53f0f5ae418 (diff)
downloadvolse-hubzilla-db1998e0c8f3050c4d93c26a5af69773a55c17d2.tar.gz
volse-hubzilla-db1998e0c8f3050c4d93c26a5af69773a55c17d2.tar.bz2
volse-hubzilla-db1998e0c8f3050c4d93c26a5af69773a55c17d2.zip
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.
Diffstat (limited to 'include/items.php')
-rwxr-xr-xinclude/items.php54
1 files changed, 46 insertions, 8 deletions
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;
}