Merge pull request #1097 from annando/acvlang

advancedcontentfilter: Add language values to filter fields
This commit is contained in:
Hypolite Petovan 2021-04-11 06:56:28 -04:00 committed by GitHub
commit 2a3d43f1f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -90,6 +90,26 @@ function advancedcontentfilter_dbstructure_definition(App $a, &$database)
]; ];
} }
function advancedcontentfilter_get_filter_fields(array $item)
{
$vars = [];
// Convert the language JSON text into a filterable format
if (!empty($item['language']) && ($languages = json_decode($item['language'], true))) {
foreach ($languages as $key => $value) {
$vars['language_' . strtolower($key)] = $value;
}
}
foreach ($item as $key => $value) {
$vars[str_replace('-', '_', $key)] = $value;
}
ksort($vars);
return $vars;
}
function advancedcontentfilter_prepare_body_content_filter(App $a, &$hook_data) function advancedcontentfilter_prepare_body_content_filter(App $a, &$hook_data)
{ {
static $expressionLanguage; static $expressionLanguage;
@ -102,10 +122,7 @@ function advancedcontentfilter_prepare_body_content_filter(App $a, &$hook_data)
return; return;
} }
$vars = []; $vars = advancedcontentfilter_get_filter_fields($hook_data['item']);
foreach ($hook_data['item'] as $key => $value) {
$vars[str_replace('-', '_', $key)] = $value;
}
$rules = DI::cache()->get('rules_' . local_user()); $rules = DI::cache()->get('rules_' . local_user());
if (!isset($rules)) { if (!isset($rules)) {
@ -417,10 +434,7 @@ function advancedcontentfilter_get_variables_guid(ServerRequestInterface $reques
$item['hashtags'] = $tags['hashtags']; $item['hashtags'] = $tags['hashtags'];
$item['mentions'] = $tags['mentions']; $item['mentions'] = $tags['mentions'];
$return = []; $return = advancedcontentfilter_get_filter_fields($item);
foreach ($item as $key => $value) {
$return[str_replace('-', '_', $key)] = $value;
}
return json_encode(['variables' => str_replace('\\\'', '\'', var_export($return, true))]); return json_encode(['variables' => str_replace('\\\'', '\'', var_export($return, true))]);
} }