Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

advancedcontentfilter: Add language values to filter fields #1097

Merged
merged 1 commit into from
Apr 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 22 additions & 8 deletions advancedcontentfilter/advancedcontentfilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
static $expressionLanguage;
Expand All @@ -102,10 +122,7 @@ function advancedcontentfilter_prepare_body_content_filter(App $a, &$hook_data)
return;
}

$vars = [];
foreach ($hook_data['item'] as $key => $value) {
$vars[str_replace('-', '_', $key)] = $value;
}
$vars = advancedcontentfilter_get_filter_fields($hook_data['item']);

$rules = DI::cache()->get('rules_' . local_user());
if (!isset($rules)) {
Expand Down Expand Up @@ -417,10 +434,7 @@ function advancedcontentfilter_get_variables_guid(ServerRequestInterface $reques
$item['hashtags'] = $tags['hashtags'];
$item['mentions'] = $tags['mentions'];

$return = [];
foreach ($item as $key => $value) {
$return[str_replace('-', '_', $key)] = $value;
}
$return = advancedcontentfilter_get_filter_fields($item);

return json_encode(['variables' => str_replace('\\\'', '\'', var_export($return, true))]);
}