]> git.wh0rd.org - tt-rss.git/commitdiff
add multiple-match to filters
authorAndrew Dolgov <fox@bah.spb.su>
Tue, 30 Jan 2007 16:00:42 +0000 (17:00 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Tue, 30 Jan 2007 16:00:42 +0000 (17:00 +0100)
functions.php
modules/pref-filters.php

index 3a0ab933eb770adf0822be4df2b7a33373744353..897444031174fae45f08ed7abe3dcf5ab65dddd3 100644 (file)
                                        owner_uid = $owner_uid AND
                                        ttrss_filter_types.id = filter_type AND
                                        ttrss_filter_actions.id = action_id AND
-                               (feed_id IS NULL OR feed_id = '$feed')");
+                               (feed_id IS NULL OR feed_id = '$feed') ORDER BY reg_exp");
 
                        while ($line = db_fetch_assoc($result)) {
                                if (!$filters[$line["name"]]) $filters[$line["name"]] = array();
 
 //                                     error_reporting(0);
 
-                                       $tuple = get_filter_name($entry_title, $entry_content
-                                               $entry_link, $filters);
+                                       $article_filters = get_article_filters($filters, $entry_title
+                                                       $entry_content, $entry_link);
 
-                                       $filter_name = $tuple[0];
-                                       $filter_param = $tuple[1];
-
-                                       if ($filter_name == "filter") {
+                                       if (find_article_filter($article_filters, "filter")) {
                                                continue;
                                        }
 
                                        // okay it doesn't exist - create user entry
                                        if (db_num_rows($result) == 0) {
 
-                                               if ($filter_name != 'catchup') {
+                                               if (!find_article_filter($article_filters, 'catchup')) {
                                                        $unread = 'true';
                                                        $last_read_qpart = 'NULL';
                                                } else {
                                                        $last_read_qpart = 'NOW()';
                                                }                                               
 
-                                               if ($filter_name == 'mark') {
+                                               if (find_article_filter($article_filters, 'mark')) {
                                                        $marked = 'true';
                                                } else {
                                                        $marked = 'false';
 
                                # check for manual tags
 
-                               if ($filter_name == "tag") {
+                               $tag_filter = find_article_filter($article_filters, "tag"); 
+
+                               if ($tag_filter) {
 
-                                       $manual_tags = trim_array(split(",", $filter_param));
+                                       $manual_tags = trim_array(split(",", $tag_filter[1]));
 
-                                       foreach ($manual_tags as $tag) {                                        
+                                       foreach ($manual_tags as $tag) {
                                                if (tag_is_valid($tag)) {
                                                        array_push($entry_tags, $tag);
                                                }
                print "</select>";
        }
 
-       function get_filter_name($title, $content, $link, $filters) {
-
-               if ($filters["title"]) {
-                       foreach ($filters["title"] as $filter) {
-                               $reg_exp = $filter["reg_exp"];                  
-                               if (preg_match("/$reg_exp/i", $title)) {
-                                       return 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)) {
-                                       return 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)) {
-                                               return array($filter["action"], $filter["action_param"]);
-                               }
-                       }
-               }
-
-               if ($filters["link"]) {
-                       $reg_exp = $filter["reg_exp"];
-                       foreach ($filters["link"] as $filter) {
-                               $reg_exp = $filter["reg_exp"];
-                               if (preg_match("/$reg_exp/i", $link)) {
-                                       return array($filter["action"], $filter["action_param"]);
-                               }
-                       }
-               }
-
-               return false;
-       }
-
-       function get_filter_matches($title, $content, $link, $filters) {
-
+       function get_article_filters($filters, $title, $content, $link) {
                $matches = array();
-
+               
                if ($filters["title"]) {
                        foreach ($filters["title"] as $filter) {
                                $reg_exp = $filter["reg_exp"];                  
                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"]));
+                               if (preg_match("/$reg_exp/i", $title) || preg_match("/$reg_exp/i", $content)) {
+                                       array_push($matches, array($filter["action"], $filter["action_param"]));
                                }
                        }
                }
                return $matches;
        }
 
+       function find_article_filter($filters, $filter_name) {
+               foreach ($filters as $f) {
+                       if ($f[0] == $filter_name) {
+                               return $f;
+                       };
+               }
+               return false;
+       }
+
        function printFeedEntry($feed_id, $class, $feed_title, $unread, $icon_file, $link,
                $rtl_content = false, $last_updated = false, $last_error = false) {
 
index 6fa99eb470bb91eeefaa9ae3fef33bd6c7d9bdfe..73366380872636c47a95343facbc51b3fcd22bd9 100644 (file)
 
                        print "</p>";
 
-                       print "<div class=\"insensitive\" style=\"float : right\">
+/*                     print "<div class=\"insensitive\" style=\"float : right\">
                                First matching filter is used, filtering is performed
-                               when importing articles from the feed.</div>";
-
+                               when importing articles from the feed.</div>"; */
 
                } else {