aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorredmatrix <redmatrix@redmatrix.me>2015-06-28 21:16:56 -0700
committerredmatrix <redmatrix@redmatrix.me>2015-06-28 21:16:56 -0700
commitde13497333c9b68e3fa2d73c9a0284da7797f405 (patch)
tree8fd039284fb96bcdb74efad09c69dc34348364f4 /include
parent1ee1b6a33435a0d05031312f988066d99ea06d5c (diff)
downloadvolse-hubzilla-de13497333c9b68e3fa2d73c9a0284da7797f405.tar.gz
volse-hubzilla-de13497333c9b68e3fa2d73c9a0284da7797f405.tar.bz2
volse-hubzilla-de13497333c9b68e3fa2d73c9a0284da7797f405.zip
no this isn't it. well ok, it's part of it, but not the important part. it's still pretty cool.
Diffstat (limited to 'include')
-rwxr-xr-xinclude/items.php65
-rw-r--r--include/zot.php45
2 files changed, 93 insertions, 17 deletions
diff --git a/include/items.php b/include/items.php
index 229512ead..cef303d2e 100755
--- a/include/items.php
+++ b/include/items.php
@@ -3284,8 +3284,7 @@ function check_item_source($uid, $item) {
$text = prepare_text($item['body'],$item['mimetype']);
$text = html2plain($text);
- /** @BUG $items is undefined, should this be $item? */
- $tags = ((count($items['term'])) ? $items['term'] : false);
+ $tags = ((count($item['term'])) ? $item['term'] : false);
$words = explode("\n",$r[0]['src_patt']);
if($words) {
@@ -3295,11 +3294,71 @@ function check_item_source($uid, $item) {
if(($t['type'] == TERM_HASHTAG) && ((substr($t,1) === substr($word,1)) || (substr($word,1) === '*')))
return true;
}
- if(stristr($text,$word) !== false)
+ elseif((strpos($word,'/') === 0) && preg_match($word,$body))
return true;
+ elseif(stristr($text,$word) !== false)
+ return true;
+ }
+ }
+
+ return false;
+}
+
+function post_is_importable($item,$abook) {
+
+ if(! $abook)
+ return true;
+ if(! $item)
+ return false;
+
+ if((! $abook['abook_incl']) && (! $abook['abook_excl']))
+ return true;
+
+ require_once('include/html2plain.php');
+ $text = prepare_text($item['body'],$item['mimetype']);
+ $text = html2plain($text);
+
+ $tags = ((count($item['term'])) ? $item['term'] : false);
+
+ // exclude always has priority
+
+ $exclude = (($abook['abook_excl']) ? explode("\n",$abook['abook_excl']) : null);
+
+ if($exclude) {
+ foreach($exclude as $word) {
+ $word = trim($word);
+ if(substr($word,0,1) === '#' && $tags) {
+ foreach($tags as $t)
+ if(($t['type'] == TERM_HASHTAG) && ((substr($t,1) === substr($word,1)) || (substr($word,1) === '*')))
+ return false;
+ }
+ elseif((strpos($word,'/') === 0) && preg_match($word,$body))
+ return false;
+ elseif(stristr($text,$word) !== false)
+ return false;
}
}
+ $include = (($abook['abook_incl']) ? explode("\n",$abook['abook_incl']) : null);
+
+ if($include) {
+ foreach($include as $word) {
+ $word = trim($word);
+ if(substr($word,0,1) === '#' && $tags) {
+ foreach($tags as $t)
+ if(($t['type'] == TERM_HASHTAG) && ((substr($t,1) === substr($word,1)) || (substr($word,1) === '*')))
+ return true;
+ }
+ elseif((strpos($word,'/') === 0) && preg_match($word,$body))
+ return true;
+ elseif(stristr($text,$word) !== false)
+ return true;
+ }
+ }
+ else {
+ return true;
+ }
+
return false;
}
diff --git a/include/zot.php b/include/zot.php
index 02ac1301b..66156b4e0 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -1654,6 +1654,12 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $
}
}
+ $ab = q("select abook.* from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and (abook_flags & %d) = 0",
+ intval($channel['channel_id']),
+ intval(ABOOK_FLAG_SELF)
+ );
+ $abook = (($ab) ? $ab[0] : null);
+
if($arr['item_restrict'] & ITEM_DELETED) {
// remove_community_tag is a no-op if this isn't a community tag activity
@@ -1693,10 +1699,15 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $
elseif($arr['edited'] > $r[0]['edited']) {
$arr['id'] = $r[0]['id'];
$arr['uid'] = $channel['channel_id'];
- update_imported_item($sender,$arr,$channel['channel_id']);
- $result[] = array($d['hash'],'updated',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']);
- if(! $relay)
- add_source_route($item_id,$sender['hash']);
+ if(($arr['mid'] == $arr['parent_mid']) && (! post_is_importable($arr,$abook))) {
+ $result[] = array($d['hash'],'update ignored',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']);
+ }
+ else {
+ update_imported_item($sender,$arr,$channel['channel_id']);
+ $result[] = array($d['hash'],'updated',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']);
+ if(! $relay)
+ add_source_route($item_id,$sender['hash']);
+ }
}
else {
$result[] = array($d['hash'],'update ignored',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']);
@@ -1715,18 +1726,24 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $
if(check_item_source($arr['uid'], $arr))
call_hooks('post_local', $arr);
-
- $item_result = item_store($arr);
+
$item_id = 0;
- if($item_result['success']) {
- $item_id = $item_result['item_id'];
- $parr = array('item_id' => $item_id,'item' => $arr,'sender' => $sender,'channel' => $channel);
- call_hooks('activity_received',$parr);
- // don't add a source route if it's a relay or later recipients will get a route mismatch
- if(! $relay)
- add_source_route($item_id,$sender['hash']);
+
+ if(($arr['mid'] == $arr['parent_mid']) && (! post_is_importable($arr,$abook))) {
+ $result[] = array($d['hash'],'post ignored',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']);
+ }
+ else {
+ $item_result = item_store($arr);
+ if($item_result['success']) {
+ $item_id = $item_result['item_id'];
+ $parr = array('item_id' => $item_id,'item' => $arr,'sender' => $sender,'channel' => $channel);
+ call_hooks('activity_received',$parr);
+ // don't add a source route if it's a relay or later recipients will get a route mismatch
+ if(! $relay)
+ add_source_route($item_id,$sender['hash']);
+ }
+ $result[] = array($d['hash'],(($item_id) ? 'posted' : 'storage failed:' . $item_result['message']),$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']);
}
- $result[] = array($d['hash'],(($item_id) ? 'posted' : 'storage failed:' . $item_result['message']),$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']);
}
if($relay && $item_id) {