implement test button in filter dialogs

master
Andrew Dolgov 14 years ago
parent 50aa64b3c4
commit 5593784a2c

@ -969,6 +969,24 @@ function quickAddFilter() {
id: "filterEditDlg", id: "filterEditDlg",
title: __("Create Filter"), title: __("Create Filter"),
style: "width: 600px", 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() { execute: function() {
if (this.validate()) { if (this.validate()) {

@ -526,6 +526,9 @@
print "<div class=\"dlgButtons\">"; 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()\">". print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
__('Create')."</button> "; __('Create')."</button> ";

@ -1,4 +1,98 @@
<?php <?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) { function module_pref_filters($link) {
$subop = $_REQUEST["subop"]; $subop = $_REQUEST["subop"];
$quiet = $_REQUEST["quiet"]; $quiet = $_REQUEST["quiet"];
@ -249,6 +343,9 @@
__('Remove')."</button>"; __('Remove')."</button>";
print "</div>"; 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()\">". print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
__('Save')."</button> "; __('Save')."</button> ";
@ -267,6 +364,7 @@
if ($memcache) $memcache->flush(); if ($memcache) $memcache->flush();
$savemode = db_escape_string($_REQUEST["savemode"]);
$reg_exp = db_escape_string(trim($_REQUEST["reg_exp"])); $reg_exp = db_escape_string(trim($_REQUEST["reg_exp"]));
$filter_type = db_escape_string(trim($_REQUEST["filter_type"])); $filter_type = db_escape_string(trim($_REQUEST["filter_type"]));
$filter_id = db_escape_string($_REQUEST["id"]); $filter_id = db_escape_string($_REQUEST["id"]);
@ -297,7 +395,8 @@
$action_param = (int) str_replace("+", "", $action_param); $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', reg_exp = '$reg_exp',
feed_id = $feed_id, feed_id = $feed_id,
action_id = '$action_id', action_id = '$action_id',
@ -307,6 +406,21 @@
action_param = '$action_param', action_param = '$action_param',
filter_param = '$filter_param' filter_param = '$filter_param'
WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]); 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 ($subop == "remove") {
@ -325,6 +439,7 @@
if ($memcache) $memcache->flush(); if ($memcache) $memcache->flush();
$savemode = db_escape_string($_REQUEST["savemode"]);
$regexp = db_escape_string(trim($_REQUEST["reg_exp"])); $regexp = db_escape_string(trim($_REQUEST["reg_exp"]));
$filter_type = db_escape_string(trim($_REQUEST["filter_type"])); $filter_type = db_escape_string(trim($_REQUEST["filter_type"]));
$feed_id = db_escape_string($_REQUEST["feed_id"]); $feed_id = db_escape_string($_REQUEST["feed_id"]);
@ -355,15 +470,31 @@
$action_param = (int) str_replace("+", "", $action_param); $action_param = (int) str_replace("+", "", $action_param);
} }
$result = db_query($link, if ($savemode != "test") {
"INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id, $result = db_query($link,
action_id, action_param, inverse, filter_param) "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
VALUES action_id, action_param, inverse, filter_param)
('$regexp', '$filter_type','".$_SESSION["uid"]."', VALUES
$feed_id, '$action_id', '$action_param', $inverse, '$filter_param')"); ('$regexp', '$filter_type','".$_SESSION["uid"]."',
$feed_id, '$action_id', '$action_param', $inverse,
if (db_affected_rows($link, $result) != 0) { '$filter_param')");
print T_sprintf("Created filter <b>%s</b>", htmlspecialchars($regexp));
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; return;

@ -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() { execute: function() {
if (this.validate()) { if (this.validate()) {

Loading…
Cancel
Save