]> git.wh0rd.org Git - tt-rss.git/commitdiff
new filter action: tag article
authorAndrew Dolgov <fox@madoka.spb.ru>
Fri, 8 Dec 2006 07:21:44 +0000 (08:21 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Fri, 8 Dec 2006 07:21:44 +0000 (08:21 +0100)
functions.php
modules/popup-dialog.php
modules/pref-filters.php
prefs.js

index 5fe75c2883f9e9fd602edbf1d2352c87ef9790c8..c0326421366ad58c310143312a43fca9b12c92fb 100644 (file)
 
                        $result = db_query($link, "SELECT reg_exp,
                                ttrss_filter_types.name AS name,
-                               ttrss_filter_actions.name AS action
+                               ttrss_filter_actions.name AS action,
+                               action_param
                                FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE                                        
                                        enabled = true AND
                                        owner_uid = $owner_uid AND
 
                                $filter["reg_exp"] = $line["reg_exp"];
                                $filter["action"] = $line["action"];
-                               
+                               $filter["action_param"] = $line["action_param"];
+                       
                                array_push($filters[$line["name"]], $filter);
                        }
 
 
 //                                     error_reporting(0);
 
-                                       $filter_name = get_filter_name($entry_title, $entry_content, 
+                                       $tuple = get_filter_name($entry_title, $entry_content, 
                                                $entry_link, $filters);
 
+                                       $filter_name = $tuple[0];
+                                       $filter_param = $tuple[1];
+
                                        if ($filter_name == "filter") {
                                                continue;
                                        }
 
                                $entry_tags = $entry_tags[1];
 
+                               # check for manual tags
+
+                               if ($filter_name == "tag") {
+
+                                       $manual_tags = trim_array(split(",", $filter_param));
+
+                                       foreach ($manual_tags as $tag) {
+                                               if (!preg_match("/^[0-9]*$/", $tag)) {
+                                                       array_push($entry_tags, $tag);
+                                               }
+                                       }
+                               }
+
                                if (count($entry_tags) > 0) {
                                
                                        db_query($link, "BEGIN");
                        foreach ($filters["title"] as $filter) {
                                $reg_exp = $filter["reg_exp"];                  
                                if (preg_match("/$reg_exp/i", $title)) {
-                                       return $filter["action"];
+                                       return array($filter["action"], $filter["action_param"]);
                                }
                        }
                }
                        foreach ($filters["content"] as $filter) {
                                $reg_exp = $filter["reg_exp"];                  
                                if (preg_match("/$reg_exp/i", $content)) {
-                                       return $filter["action"];
+                                       return array($filter["action"], $filter["action_param"]);
                                }               
                        }
                }
                                $reg_exp = $filter["reg_exp"];          
                                if (preg_match("/$reg_exp/i", $title) || 
                                        preg_match("/$reg_exp/i", $content)) {
-                                       return $filter["action"];
+                                               return array($filter["action"], $filter["action_param"]);
                                }
                        }
                }
                        foreach ($filters["link"] as $filter) {
                                $reg_exp = $filter["reg_exp"];
                                if (preg_match("/$reg_exp/i", $link)) {
-                                       return $filter["action"];
+                                       return array($filter["action"], $filter["action_param"]);
                                }
                        }
                }
index 459b3b3e95df8f8bf2e8cd41a8454c43cdb891a7..5549a2d79991f821ace9848ff68fa274c28a99d0 100644 (file)
        
                        print "<tr><td>Action:</td>";
        
-                       print "<td colspan='2'><select name=\"action_id\">";
+                       print "<td colspan='2'><select name=\"action_id\" 
+                               onchange=\"filterDlgCheckAction(this)\">";
        
                        $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions 
                                ORDER BY name");
        
                        print "</select>";
 
-                       print "</td></tr></table>";
+                       print "</td></tr>";
+
+                       print "<tr><td>Params:</td>";
+
+                       print "<td><input disabled class='iedit' name='action_param'></td></tr>";
+
+                       print "</table>";
 
                        print "</form>";
 
index 0570b7ac502beadae3958af9e128f256a895858f..610e3dcd0df1b692269bcb27779cbc84578f716f 100644 (file)
@@ -14,6 +14,7 @@
                        $filter_type = db_fetch_result($result, 0, "filter_type");
                        $feed_id = db_fetch_result($result, 0, "feed_id");
                        $action_id = db_fetch_result($result, 0, "action_id");
+                       $action_param = db_fetch_result($result, 0, "action_param");
 
                        $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
 
@@ -58,7 +59,8 @@
        
                        print "<tr><td>Action:</td>";
        
-                       print "<td colspan='2'><select name=\"action_id\">";
+                       print "<td colspan='2'><select name=\"action_id\"
+                               onchange=\"filterDlgCheckAction(this)\">";
        
                        $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions 
                                ORDER BY name");
 
                        print "</td></tr>";
 
+                       print "<tr><td>Params:</td>";
+
+                       $param_disabled = ($action_id == 4) ? "" : "disabled";
+
+                       print "<td><input $param_disabled class='iedit' 
+                               name=\"action_param\" value=\"$action_param\"></td></tr>";
+
                        if ($enabled) {
                                $checked = "checked";
                        } else {
                        $filter_id = db_escape_string($_GET["id"]);
                        $feed_id = db_escape_string($_GET["feed_id"]);
                        $action_id = db_escape_string($_GET["action_id"]); 
+                       $action_param = db_escape_string($_GET["action_param"]); 
                        $enabled = checkbox_to_sql_bool(db_escape_string($_GET["enabled"]));
 
                        if (!$feed_id) {
                                        feed_id = $feed_id,
                                        action_id = '$action_id',
                                        filter_type = '$filter_type',
-                                       enabled = $enabled
+                                       enabled = $enabled,
+                                       action_param = '$action_param'
                                WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
                }
 
                                $filter_type = db_escape_string(trim($_GET["filter_type"]));
                                $feed_id = db_escape_string($_GET["feed_id"]);
                                $action_id = db_escape_string($_GET["action_id"]); 
+                               $action_param = db_escape_string($_GET["action_param"]); 
 
                                if (!$regexp) return;
 
 
                                $result = db_query($link,
                                        "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
-                                               action_id) 
+                                               action_id, action_param
                                        VALUES 
                                                ('$regexp', '$filter_type','".$_SESSION["uid"]."', 
-                                                       $feed_id, '$action_id')");
+                                                       $feed_id, '$action_id', '$action_param')");
                        } 
                }
 
index 6b772b1cddd7b0a035c95ee5a99d2dff536c4568..37b738358910182b9d82e4dd85f5b38221a68204 100644 (file)
--- a/prefs.js
+++ b/prefs.js
@@ -1548,3 +1548,40 @@ function editFeedCats() {
 function showFeedsWithErrors() {
        displayDlg('feedUpdateErrors');
 }
+
+function filterDlgCheckAction(sender) {
+
+       try {
+
+               var action = sender[sender.selectedIndex].value;
+
+               var form = document.forms["filter_add_form"];
+       
+               if (!form) {
+                       form = document.forms["filter_edit_form"];
+               }
+
+               if (!form) {
+                       debug("filterDlgCheckAction: can't find form!");
+                       return;
+               }
+
+               var action_param = form.action_param;
+
+               if (!action_param) {
+                       debug("filterDlgCheckAction: can't find action param!");
+                       return;
+               }
+
+               // if selected action supports parameters, enable params field
+               if (action == 4) {
+                       action_param.disabled = false;
+               } else {
+                       action_param.disabled = true;
+               }
+
+       } catch (e) {
+               exception_error(e, "filterDlgCheckAction");
+       }
+
+}