mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2025-08-02 09:51:47 +00:00
Merge pull request 'Issue 15048: Support addon filters via API' (#1612) from heluecht/friendica-addons:issue-15048 into 2025.07-rc
Reviewed-on: https://git.friendi.ca/friendica/friendica-addons/pulls/1612
This commit is contained in:
commit
e76575eb52
3 changed files with 16 additions and 14 deletions
|
@ -120,21 +120,22 @@ function advancedcontentfilter_prepare_body_content_filter(&$hook_data)
|
|||
$expressionLanguage = new ExpressionLanguage\ExpressionLanguage();
|
||||
}
|
||||
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
$uid = $hook_data['uid'] ?: DI::userSession()->getLocalUserId();
|
||||
if (!$uid) {
|
||||
return;
|
||||
}
|
||||
|
||||
$vars = advancedcontentfilter_get_filter_fields($hook_data['item']);
|
||||
|
||||
$rules = DI::cache()->get('rules_' . DI::userSession()->getLocalUserId());
|
||||
$rules = DI::cache()->get('rules_' . $uid);
|
||||
if (!isset($rules)) {
|
||||
$rules = DBA::toArray(DBA::select(
|
||||
'advancedcontentfilter_rules',
|
||||
['name', 'expression', 'serialized'],
|
||||
['uid' => DI::userSession()->getLocalUserId(), 'active' => true]
|
||||
['uid' => $uid, 'active' => true]
|
||||
));
|
||||
|
||||
DI::cache()->set('rules_' . DI::userSession()->getLocalUserId(), $rules);
|
||||
DI::cache()->set('rules_' . $uid, $rules);
|
||||
}
|
||||
|
||||
if ($rules) {
|
||||
|
|
|
@ -99,8 +99,8 @@ function langfilter_addon_settings_post(array &$b)
|
|||
|
||||
function langfilter_prepare_body_content_filter(&$hook_data)
|
||||
{
|
||||
$logged_user = DI::userSession()->getLocalUserId();
|
||||
if (!$logged_user) {
|
||||
$uid = $hook_data['uid'] ?: DI::userSession()->getLocalUserId();
|
||||
if (!$uid) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -112,8 +112,8 @@ function langfilter_prepare_body_content_filter(&$hook_data)
|
|||
}
|
||||
|
||||
// Don't filter if language filter is disabled
|
||||
if (!DI::pConfig()->get($logged_user, 'langfilter', 'enable',
|
||||
!DI::pConfig()->get($logged_user, 'langfilter', 'disable'))
|
||||
if (!DI::pConfig()->get($uid, 'langfilter', 'enable',
|
||||
!DI::pConfig()->get($uid, 'langfilter', 'disable'))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ function langfilter_prepare_body_content_filter(&$hook_data)
|
|||
$naked_body = preg_replace('#\s+#', ' ', trim($naked_body));
|
||||
|
||||
// Don't filter if body lenght is below minimum
|
||||
$minlen = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'langfilter', 'minlength', 32);
|
||||
$minlen = DI::pConfig()->get($uid, 'langfilter', 'minlength', 32);
|
||||
if (!$minlen) {
|
||||
$minlen = 32;
|
||||
}
|
||||
|
@ -136,8 +136,8 @@ function langfilter_prepare_body_content_filter(&$hook_data)
|
|||
return;
|
||||
}
|
||||
|
||||
$read_languages_string = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'langfilter', 'languages');
|
||||
$minconfidence = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'langfilter', 'minconfidence');
|
||||
$read_languages_string = DI::pConfig()->get($uid, 'langfilter', 'languages');
|
||||
$minconfidence = DI::pConfig()->get($uid, 'langfilter', 'minconfidence');
|
||||
|
||||
// Don't filter if no spoken languages are configured
|
||||
if (!$read_languages_string) {
|
||||
|
|
|
@ -104,12 +104,13 @@ function nsfw_addon_settings_post(array &$b)
|
|||
function nsfw_prepare_body_content_filter(&$hook_data)
|
||||
{
|
||||
$words = null;
|
||||
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'nsfw', 'disable')) {
|
||||
$uid = $hook_data['uid'] ?: DI::userSession()->getLocalUserId();
|
||||
if (DI::pConfig()->get($uid, 'nsfw', 'disable')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (DI::userSession()->getLocalUserId()) {
|
||||
$words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'nsfw', 'words');
|
||||
if ($uid) {
|
||||
$words = DI::pConfig()->get($uid, 'nsfw', 'words');
|
||||
}
|
||||
|
||||
if ($words) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue