From a01c33d65409d8313221b981152ec627b8f8f3f1 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 6 Dec 2018 19:15:00 +0300 Subject: add HOOK_FILTER_TRIGGERED (for filter debugging) --- classes/pluginhost.php | 1 + classes/rssutils.php | 19 ++++++++++++++++--- include/functions.php | 3 ++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/classes/pluginhost.php b/classes/pluginhost.php index 7e3fb08ab..1ea6d8a5b 100755 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -57,6 +57,7 @@ class PluginHost { const HOOK_SEND_LOCAL_FILE = 37; const HOOK_UNSUBSCRIBE_FEED = 38; const HOOK_SEND_MAIL = 39; + const HOOK_FILTER_TRIGGERED = 40; const KIND_ALL = 1; const KIND_SYSTEM = 2; diff --git a/classes/rssutils.php b/classes/rssutils.php index 56108bd1e..923e98c82 100755 --- a/classes/rssutils.php +++ b/classes/rssutils.php @@ -769,13 +769,25 @@ class RSSUtils { /* Collect article tags here so we could filter by them: */ - $matched_rules = array(); + $matched_rules = []; + $matched_filters = []; $article_filters = RSSUtils::get_article_filters($filters, $article["title"], $article["content"], $article["link"], $article["author"], - $article["tags"], $matched_rules); + $article["tags"], $matched_rules, $matched_filters); + + // $article_filters should be renamed to something like $filter_actions; actual filter objects are in $matched_filters + foreach ($pluginhost->get_hooks(PluginHost::HOOK_FILTER_TRIGGERED) as $plugin) { + $plugin->hook_filter_triggered($feed, $owner_uid, $article, $matched_filters, $matched_rules, $article_filters); + } if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) { + Debug::log("matched filters: ", Debug::$LOG_VERBOSE); + + if (count($matched_filters != 0)) { + print_r($matched_filters); + } + Debug::log("matched filter rules: ", Debug::$LOG_VERBOSE); if (count($matched_rules) != 0) { @@ -1342,7 +1354,7 @@ class RSSUtils { return $params; } - static function get_article_filters($filters, $title, $content, $link, $author, $tags, &$matched_rules = false) { + static function get_article_filters($filters, $title, $content, $link, $author, $tags, &$matched_rules = false, &$matched_filters = false) { $matches = array(); foreach ($filters as $filter) { @@ -1409,6 +1421,7 @@ class RSSUtils { if ($filter_match) { if (is_array($matched_rules)) array_push($matched_rules, $rule); + if (is_array($matched_filters)) array_push($matched_filters, $filter); foreach ($filter["actions"] AS $action) { array_push($matches, $action); diff --git a/include/functions.php b/include/functions.php index 5c1ad1c37..83cc72f80 100755 --- a/include/functions.php +++ b/include/functions.php @@ -1945,7 +1945,8 @@ } } - $filter = array(); + $filter = []; + $filter["id"] = $filter_id; $filter["match_any_rule"] = sql_bool_to_bool($line["match_any_rule"]); $filter["inverse"] = sql_bool_to_bool($line["inverse"]); $filter["rules"] = $rules; -- cgit v1.2.3