use server-side localized formatting for matching rule to display as a tooltip (for now)

This commit is contained in:
Andrew Dolgov
2025-03-30 20:41:50 +03:00
parent b4962b670d
commit 2d041f7d28
2 changed files with 11 additions and 14 deletions

View File

@@ -95,7 +95,6 @@ class Pref_Filters extends Handler_Protected {
if (is_array($rule)) { if (is_array($rule)) {
$rule['type'] = $filter_types[$rule['filter_type']]; $rule['type'] = $filter_types[$rule['filter_type']];
unset($rule['filter_type']);
array_push($filter['rules'], $rule); array_push($filter['rules'], $rule);
$scope_inner_qparts = []; $scope_inner_qparts = [];
@@ -185,10 +184,7 @@ class Pref_Filters extends Handler_Protected {
$matches[] = $rule_regexp_match; $matches[] = $rule_regexp_match;
$rules[] = [ $rules[] = self::_get_rule_name($rule, '');
'reg_exp' => $rule['reg_exp'],
'type' => $rule['type']
];
if (in_array($rule['type'], ['content', 'both'])) { if (in_array($rule['type'], ['content', 'both'])) {
// also stripping [\r\n\t] to match what's done for content in RSSUtils#get_article_filters() // also stripping [\r\n\t] to match what's done for content in RSSUtils#get_article_filters()
@@ -452,7 +448,7 @@ class Pref_Filters extends Handler_Protected {
/** /**
* @param array<string, mixed>|null $rule * @param array<string, mixed>|null $rule
*/ */
private function _get_rule_name(?array $rule = null): string { private function _get_rule_name(?array $rule = null, string $format = 'html'): string {
if (!$rule) $rule = json_decode(clean($_REQUEST["rule"]), true); if (!$rule) $rule = json_decode(clean($_REQUEST["rule"]), true);
$feeds = $rule["feed_id"]; $feeds = $rule["feed_id"];
@@ -487,10 +483,14 @@ class Pref_Filters extends Handler_Protected {
$inverse = isset($rule["inverse"]) ? "inverse" : ""; $inverse = isset($rule["inverse"]) ? "inverse" : "";
return "<span class='filterRule $inverse'>" . if ($format === 'html')
T_sprintf("%s on %s in %s %s", htmlspecialchars($rule["reg_exp"]), return "<span class='filterRule $inverse'>" .
"<span class='field'>$filter_type</span>", "<span class='feed'>$feed</span>", isset($rule["inverse"]) ? __("(inverse)") : "") . "</span>"; T_sprintf("%s on %s in %s %s", htmlspecialchars($rule["reg_exp"]),
} "<span class='field'>$filter_type</span>", "<span class='feed'>$feed</span>", isset($rule["inverse"]) ? __("(inverse)") : "") . "</span>";
else
return T_sprintf("%s on %s in %s %s", $rule["reg_exp"],
$filter_type, $feed, isset($rule["inverse"]) ? __("(inverse)") : "");
}
function printRuleName(): void { function printRuleName(): void {
print $this->_get_rule_name(json_decode(clean($_REQUEST["rule"]), true)); print $this->_get_rule_name(json_decode(clean($_REQUEST["rule"]), true));

View File

@@ -19,9 +19,6 @@ const Filters = {
ACTION_REMOVE_TAG: 10, ACTION_REMOVE_TAG: 10,
PARAM_ACTIONS: [4, 6, 7, 9, 10], PARAM_ACTIONS: [4, 6, 7, 9, 10],
filter_info: {}, filter_info: {},
formatMatchedRules: function(rules) {
return rules.map((r) => r.reg_exp + ' (' + r.type + ')').join('\n');
},
test: function() { test: function() {
const test_dialog = new fox.SingleUseDialog({ const test_dialog = new fox.SingleUseDialog({
title: "Test Filter", title: "Test Filter",
@@ -46,7 +43,7 @@ const Filters = {
.replace("%f", test_dialog.results) .replace("%f", test_dialog.results)
.replace("%d", offset); .replace("%d", offset);
results_list.innerHTML += result.items.reduce((current, item) => current + `<li title="${App.escapeHtml(dialog.formatMatchedRules(item.rules))}"><span class='title'>${item.title}</span> results_list.innerHTML += result.items.reduce((current, item) => current + `<li title="${App.escapeHtml(item.rules.join('\n'))}"><span class='title'>${item.title}</span>
&mdash; <span class='feed'>${item.feed_title}</span>, <span class='date'>${item.date}</span> &mdash; <span class='feed'>${item.feed_title}</span>, <span class='date'>${item.date}</span>
<div class='preview text-muted'>${item.content_preview}</div></li>`, ''); <div class='preview text-muted'>${item.content_preview}</div></li>`, '');