]> git.wh0rd.org Git - tt-rss.git/commitdiff
add support for inverse filters
authorAndrew Dolgov <fox@bah.spb.su>
Tue, 30 Jan 2007 16:38:36 +0000 (17:38 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Tue, 30 Jan 2007 16:38:36 +0000 (17:38 +0100)
functions.php

index 897444031174fae45f08ed7abe3dcf5ab65dddd3..7d16c2586902c6a0acd9ae82f15cf72a014eac8b 100644 (file)
                        $result = db_query($link, "SELECT reg_exp,
                                ttrss_filter_types.name AS name,
                                ttrss_filter_actions.name AS action,
+                               inverse,
                                action_param
                                FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE                                        
                                        enabled = true AND
                                $filter["reg_exp"] = $line["reg_exp"];
                                $filter["action"] = $line["action"];
                                $filter["action_param"] = $line["action_param"];
+                               $filter["inverse"] = sql_bool_to_bool($line["inverse"]);
                        
                                array_push($filters[$line["name"]], $filter);
                        }
 
        function get_article_filters($filters, $title, $content, $link) {
                $matches = array();
-               
+
                if ($filters["title"]) {
                        foreach ($filters["title"] as $filter) {
-                               $reg_exp = $filter["reg_exp"];                  
-                               if (preg_match("/$reg_exp/i", $title)) {
+                               $reg_exp = $filter["reg_exp"];          
+                               $inverse = $filter["inverse"];  
+                               if ((!$inverse && preg_match("/$reg_exp/i", $title)) || 
+                                               ($inverse && !preg_match("/$reg_exp/i", $title))) {
+
                                        array_push($matches, array($filter["action"], $filter["action_param"]));
                                }
                        }
 
                if ($filters["content"]) {
                        foreach ($filters["content"] as $filter) {
-                               $reg_exp = $filter["reg_exp"];                  
-                               if (preg_match("/$reg_exp/i", $content)) {
+                               $reg_exp = $filter["reg_exp"];
+                               $inverse = $filter["inverse"];
+
+                               if ((!$inverse && preg_match("/$reg_exp/i", $content)) || 
+                                               ($inverse && !preg_match("/$reg_exp/i", $content))) {
+
                                        array_push($matches, array($filter["action"], $filter["action_param"]));
                                }               
                        }
                if ($filters["both"]) {
                        foreach ($filters["both"] as $filter) {                 
                                $reg_exp = $filter["reg_exp"];          
-                               if (preg_match("/$reg_exp/i", $title) || preg_match("/$reg_exp/i", $content)) {
-                                       array_push($matches, array($filter["action"], $filter["action_param"]));
+                               $inverse = $filter["inverse"];
+
+                               if ($inverse) {
+                                       if (!preg_match("/$reg_exp/i", $title) || !preg_match("/$reg_exp/i", $content)) {
+                                               array_push($matches, array($filter["action"], $filter["action_param"]));
+                                       }
+                               } else {
+                                       if (preg_match("/$reg_exp/i", $title) || preg_match("/$reg_exp/i", $content)) {
+                                               array_push($matches, array($filter["action"], $filter["action_param"]));
+                                       }
                                }
                        }
                }
                        $reg_exp = $filter["reg_exp"];
                        foreach ($filters["link"] as $filter) {
                                $reg_exp = $filter["reg_exp"];
-                               if (preg_match("/$reg_exp/i", $link)) {
+                               $inverse = $filter["inverse"];
+
+                               if ((!$inverse && preg_match("/$reg_exp/i", $link)) || 
+                                               ($inverse && !preg_match("/$reg_exp/i", $link))) {
+                                               
                                        array_push($matches, array($filter["action"], $filter["action_param"]));
                                }
                        }