]> git.wh0rd.org - tt-rss.git/commitdiff
implement test button in filter dialogs
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sun, 17 Apr 2011 20:01:24 +0000 (00:01 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sun, 17 Apr 2011 20:01:24 +0000 (00:01 +0400)
functions.js
modules/popup-dialog.php
modules/pref-filters.php
prefs.js

index 3b18b00725059f6037ce6ac6f9d05b864cd41f57..ee92674eb74d7dcc8bdfe0ea416e4eb79b2693b9 100644 (file)
@@ -969,6 +969,24 @@ function quickAddFilter() {
                        id: "filterEditDlg",
                        title: __("Create Filter"),
                        style: "width: 600px",
+                       test: function() {
+                               if (this.validate()) {
+
+                                       if (dijit.byId("filterTestDlg"))
+                                               dijit.byId("filterTestDlg").destroyRecursive();
+
+                                       tdialog = new dijit.Dialog({
+                                               id: "filterTestDlg",
+                                               title: __("Filter Test Results"),
+                                               style: "width: 600px",
+                                               href: "backend.php?savemode=test&" +
+                                                       dojo.objectToQuery(dialog.attr('value')),
+                                               });
+
+                                       tdialog.show();
+
+                               }
+                       },
                        execute: function() {
                                if (this.validate()) {
 
index dbbd1fb32c3e97704e96844603e5566f896a8cc6..78962dc6c42602c82308dee18ec777cc0975e716 100644 (file)
 
                        print "<div class=\"dlgButtons\">";
 
+                       print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
+                               __('Test')."</button> ";
+
                        print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
                                __('Create')."</button> ";
 
index dc9015f3a0296cc3773c9cf2547057e4dde923e4..a270ba8e60c36954ad007dd863aa6e19c3845808 100644 (file)
@@ -1,4 +1,98 @@
 <?php
+       function filter_test($link, $filter_type, $reg_exp,
+                       $action_id, $action_param, $filter_param, $inverse, $feed_id) {
+
+               $result = db_query($link, "SELECT name FROM ttrss_filter_types WHERE
+                       id = " . $filter_type);
+               $type_name = db_fetch_result($result, 0, "name");
+
+               $result = db_query($link, "SELECT name FROM ttrss_filter_actions WHERE
+                       id = " . $action_id);
+               $action_name = db_fetch_result($result, 0, "name");
+
+               $filter["reg_exp"] = $reg_exp;
+               $filter["action"] = $action_name;
+
+               $filter["action_param"] = $action_param;
+               $filter["filter_param"] = $filter_param;
+               $filter["inverse"] = sql_bool_to_bool($inverse);
+
+               $filters[$type_name] = array($filter);
+
+               if ($feed_id != "NULL")
+                       $feed = $feed_id;
+               else
+                       $feed = -4;
+
+               $feed_title = getFeedTitle($line, $feed);
+
+               $qfh_ret = queryFeedHeadlines($link, $feed,
+                       300, "", false, false, false,
+                       false, "updated DESC", 0, $_SESSION["uid"]);
+
+               $result = $qfh_ret[0];
+
+               $articles = array();
+               $found = 0;
+
+               while ($line = db_fetch_assoc($result)) {
+
+                       $entry_timestamp = strtotime($line["updated"]);
+                       $entry_tags = get_article_tags($link, $line["id"], $_SESSION["uid"]);
+
+                       $article_filters = get_article_filters($filters, $line["title"],
+                               $line["content_preview"], $line["link"],
+                               $entry_timestamp, $line["author"], $entry_tags);
+
+                       if (count($article_filters) != 0) {
+
+                               $content_preview = truncate_string(
+                                       strip_tags($line["content_preview"]), 100, '...');
+
+                               if ($line["feed_title"])
+                                       $feed_title = $line["feed_title"];
+
+                               array_push($articles, array("title" => $line["title"],
+                                       "content" => $content_preview, "feed" => $feed_title));
+
+                               $found++;
+                       }
+
+                       if ($found >= 30)
+                               break;
+               }
+
+               if ($found == 0) {
+                       print __("No recent articles matching this filter has been found.");
+               } else {
+
+                       print __("Recent articles matching this filter:");
+
+                       print "<div class=\"inactiveFeedHolder\">";
+                       print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
+
+                       foreach ($articles as $article) {
+                               print "<tr>";
+
+                               print "<td width='5%' align='center'><input
+                                       dojoType=\"dijit.form.CheckBox\" checked=\"1\"
+                                       disabled=\"1\"
+                                       type=\"checkbox\"></td>";
+                               print "<td>";
+
+                               print $article["title"];
+                               print "&nbsp;(";
+                               print "<b>" . $article["feed"] . "</b>";
+                               print "):&nbsp;";
+                               print "<span class=\"insensitive\">" . $article["content"] . "</span>";
+
+                               print "</td></tr>";
+                       }
+                       print "</table>";
+                       print "</div>";
+               }
+       }
+
        function module_pref_filters($link) {
                $subop = $_REQUEST["subop"];
                $quiet = $_REQUEST["quiet"];
                                __('Remove')."</button>";
                        print "</div>";
 
+                       print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
+                               __('Test')."</button> ";
+
                        print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
                                __('Save')."</button> ";
 
 
                        if ($memcache) $memcache->flush();
 
+                       $savemode = db_escape_string($_REQUEST["savemode"]);
                        $reg_exp = db_escape_string(trim($_REQUEST["reg_exp"]));
                        $filter_type = db_escape_string(trim($_REQUEST["filter_type"]));
                        $filter_id = db_escape_string($_REQUEST["id"]);
                                $action_param = (int) str_replace("+", "", $action_param);
                        }
 
-                       $result = db_query($link, "UPDATE ttrss_filters SET
+                       if ($savemode != "test") {
+                               $result = db_query($link, "UPDATE ttrss_filters SET
                                        reg_exp = '$reg_exp',
                                        feed_id = $feed_id,
                                        action_id = '$action_id',
                                        action_param = '$action_param',
                                        filter_param = '$filter_param'
                                        WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
+                       } else {
+
+                               filter_test($link, $filter_type, $reg_exp,
+                                       $action_id, $action_param, $filter_param, sql_bool_to_bool($inverse),
+                                       $feed_id);
+
+                               print "<div align='center'>";
+                               print "<button dojoType=\"dijit.form.Button\"
+                                       onclick=\"return dijit.byId('filterTestDlg').hide()\">".
+                                       __('Close this window')."</button>";
+                               print "</div>";
+
+                       }
+
+                       return;
                }
 
                if ($subop == "remove") {
 
                        if ($memcache) $memcache->flush();
 
+                       $savemode = db_escape_string($_REQUEST["savemode"]);
                        $regexp = db_escape_string(trim($_REQUEST["reg_exp"]));
                        $filter_type = db_escape_string(trim($_REQUEST["filter_type"]));
                        $feed_id = db_escape_string($_REQUEST["feed_id"]);
                                $action_param = (int) str_replace("+", "", $action_param);
                        }
 
-                       $result = db_query($link,
-                               "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
-                                       action_id, action_param, inverse, filter_param)
-                               VALUES
-                                       ('$regexp', '$filter_type','".$_SESSION["uid"]."',
-                                               $feed_id, '$action_id', '$action_param', $inverse, '$filter_param')");
-
-                       if (db_affected_rows($link, $result) != 0) {
-                               print T_sprintf("Created filter <b>%s</b>", htmlspecialchars($regexp));
+                       if ($savemode != "test") {
+                               $result = db_query($link,
+                                       "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
+                                               action_id, action_param, inverse, filter_param)
+                                       VALUES
+                                               ('$regexp', '$filter_type','".$_SESSION["uid"]."',
+                                               $feed_id, '$action_id', '$action_param', $inverse,
+                                               '$filter_param')");
+
+                               if (db_affected_rows($link, $result) != 0) {
+                                       print T_sprintf("Created filter <b>%s</b>", htmlspecialchars($regexp));
+                               }
+
+                       } else {
+
+                               filter_test($link, $filter_type, $regexp,
+                                       $action_id, $action_param, $filter_param, sql_bool_to_bool($inverse),
+                                       $feed_id);
+
+                               print "<div align='center'>";
+                               print "<button dojoType=\"dijit.form.Button\"
+                                       onclick=\"return dijit.byId('filterTestDlg').hide()\">".
+                                       __('Close this window')."</button>";
+                               print "</div>";
+
                        }
 
                        return;
index 05052093d5b7e06029dae8eef382be6a2c072f66..2a054df53f0110307ffc475868d7de6659075890 100644 (file)
--- a/prefs.js
+++ b/prefs.js
@@ -180,7 +180,24 @@ function editFilter(id) {
                                                } });
                                }
                        },
+                       test: function() {
+                               if (this.validate()) {
+
+                                       if (dijit.byId("filterTestDlg"))
+                                               dijit.byId("filterTestDlg").destroyRecursive();
+
+                                       tdialog = new dijit.Dialog({
+                                               id: "filterTestDlg",
+                                               title: __("Filter Test Results"),
+                                               style: "width: 600px",
+                                               href: "backend.php?savemode=test&" +
+                                                       dojo.objectToQuery(dialog.attr('value')),
+                                               });
 
+                                       tdialog.show();
+
+                               }
+                       },
                        execute: function() {
                                if (this.validate()) {