From 5593784a2c64a910425d2064575ee575721dad53 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 18 Apr 2011 00:01:24 +0400 Subject: [PATCH] implement test button in filter dialogs --- functions.js | 18 +++++ modules/popup-dialog.php | 3 + modules/pref-filters.php | 151 ++++++++++++++++++++++++++++++++++++--- prefs.js | 17 +++++ 4 files changed, 179 insertions(+), 10 deletions(-) diff --git a/functions.js b/functions.js index 3b18b007..ee92674e 100644 --- a/functions.js +++ b/functions.js @@ -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()) { diff --git a/modules/popup-dialog.php b/modules/popup-dialog.php index dbbd1fb3..78962dc6 100644 --- a/modules/popup-dialog.php +++ b/modules/popup-dialog.php @@ -526,6 +526,9 @@ print "
"; + print " "; + print " "; diff --git a/modules/pref-filters.php b/modules/pref-filters.php index dc9015f3..a270ba8e 100644 --- a/modules/pref-filters.php +++ b/modules/pref-filters.php @@ -1,4 +1,98 @@ $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 "
"; + print ""; + + foreach ($articles as $article) { + print ""; + + print ""; + print ""; + } + print "
"; + + print $article["title"]; + print " ("; + print "" . $article["feed"] . ""; + print "): "; + print "" . $article["content"] . ""; + + print "
"; + print "
"; + } + } + function module_pref_filters($link) { $subop = $_REQUEST["subop"]; $quiet = $_REQUEST["quiet"]; @@ -249,6 +343,9 @@ __('Remove').""; print "
"; + print " "; + print " "; @@ -267,6 +364,7 @@ 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"]); @@ -297,7 +395,8 @@ $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', @@ -307,6 +406,21 @@ 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 "
"; + print ""; + print "
"; + + } + + return; } if ($subop == "remove") { @@ -325,6 +439,7 @@ 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"]); @@ -355,15 +470,31 @@ $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 %s", 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 %s", htmlspecialchars($regexp)); + } + + } else { + + filter_test($link, $filter_type, $regexp, + $action_id, $action_param, $filter_param, sql_bool_to_bool($inverse), + $feed_id); + + print "
"; + print ""; + print "
"; + } return; diff --git a/prefs.js b/prefs.js index 05052093..2a054df5 100644 --- 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()) { -- 2.39.5