enhanced content filters

This commit is contained in:
Mario
2022-03-01 10:14:05 +00:00
parent 0cc6f66a26
commit 01b9f2dfcf
8 changed files with 291 additions and 96 deletions

View File

@@ -10,6 +10,7 @@ use Zotlabs\Lib\MarkdownSoap;
use Zotlabs\Lib\MessageFilter;
use Zotlabs\Lib\ThreadListener;
use Zotlabs\Lib\IConfig;
use Zotlabs\Lib\PConfig;
use Zotlabs\Lib\Activity;
use Zotlabs\Lib\Libsync;
use Zotlabs\Lib\Libzot;
@@ -2218,9 +2219,9 @@ function item_store_update($arr, $allow_exec = false, $deliver = true) {
$arr['deny_gid'] = ((array_key_exists('deny_gid',$arr)) ? trim($arr['deny_gid']) : $orig[0]['deny_gid']);
$arr['item_private'] = ((array_key_exists('item_private',$arr)) ? intval($arr['item_private']) : $orig[0]['item_private']);
$arr['title'] = ((array_key_exists('title',$arr) && strlen($arr['title'])) ? trim($arr['title']) : '');
$arr['body'] = ((array_key_exists('body',$arr) && strlen($arr['body'])) ? trim($arr['body']) : '');
$arr['html'] = ((array_key_exists('html',$arr) && strlen($arr['html'])) ? trim($arr['html']) : '');
$arr['title'] = ((array_key_exists('title',$arr) && $arr['title']) ? trim($arr['title']) : '');
$arr['body'] = ((array_key_exists('body',$arr) && $arr['body']) ? trim($arr['body']) : '');
$arr['html'] = ((array_key_exists('html',$arr) && $arr['html']) ? trim($arr['html']) : '');
$arr['attach'] = ((array_key_exists('attach',$arr)) ? notags(trim($arr['attach'])) : $orig[0]['attach']);
$arr['app'] = ((array_key_exists('app',$arr)) ? notags(trim($arr['app'])) : $orig[0]['app']);
@@ -3495,24 +3496,57 @@ function check_item_source($uid, $item) {
return false;
}
function post_is_importable($item,$abook) {
if(! $abook)
return true;
// Checks an incoming item against the per-channel and per-connection content filter.
// This implements the backend of the 'Content Filter' system app
if(($abook['abook_channel']) && (! feature_enabled($abook['abook_channel'],'connfilter')))
return true;
function post_is_importable($channel_id, $item, $abook) {
if(! $item)
if (! $item) {
return false;
}
if(! ($abook['abook_incl'] || $abook['abook_excl']))
$incl = PConfig::get($channel_id, 'system', 'message_filter_incl', EMPTY_STR);
$excl = PConfig::get($channel_id, 'system', 'message_filter_excl', EMPTY_STR);
if ($incl || $excl) {
$x = MessageFilter::evaluate($item, $incl, $excl);
if (! $x) {
logger('MessageFilter: channel blocked content', LOGGER_DEBUG, LOG_INFO);
return false;
}
}
if(!feature_enabled($channel_id, 'connfilter')) {
return true;
}
return MessageFilter::evaluate($item,$abook['abook_incl'],$abook['abook_excl']);
if (! $abook) {
return true;
}
foreach ($abook as $ab) {
// check eligibility
if (intval($ab['abook_self'])) {
continue;
}
if (! ($ab['abook_incl'] || $ab['abook_excl'])) {
continue;
}
$evaluator = MessageFilter::evaluate($item, $ab['abook_incl'], $ab['abook_excl']);
// A negative assessment for any individual connections
// is an instant fail
if (! $evaluator) {
logger('MessageFilter: connection blocked content', LOGGER_DEBUG, LOG_INFO);
return false;
}
}
return true;
}
function fix_private_photos($s, $uid, $item = null, $cid = 0) {
logger('fix_private_photos', LOGGER_DEBUG);