diff --git a/classes/pref/filters.php b/classes/pref/filters.php index a371fcff4..ec0c3862a 100644 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -43,8 +43,11 @@ class Pref_Filters extends Handler_Protected { return; } + function testFilterDo() { + require_once "include/rssfuncs.php"; + + $offset = (int) db_escape_string($_REQUEST["offset"]); - function testFilter() { $filter = array(); $filter["enabled"] = true; @@ -94,24 +97,14 @@ class Pref_Filters extends Handler_Protected { } } - $found = 0; - $offset = 0; - $limit = 30; - $started = time(); - - print __("Articles matching this filter:"); - - require_once "include/rssfuncs.php"; - - print "
"; - print ""; - $glue = $filter['match_any_rule'] ? " OR " : " AND "; $scope_qpart = join($glue, $scope_qparts); if (!$scope_qpart) $scope_qpart = "true"; - while ($found < $limit && $offset < $limit * 10 && time() - $started < ini_get("max_execution_time") * 0.7) { + $rv = array(); + + //while ($found < $limit && $offset < $limit * 1000 && time() - $started < ini_get("max_execution_time") * 0.7) { $result = db_query("SELECT ttrss_entries.id, ttrss_entries.title, @@ -130,7 +123,7 @@ class Pref_Filters extends Handler_Protected { ref_id = ttrss_entries.id AND ($scope_qpart) AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"] . " - ORDER BY date_entered DESC LIMIT $limit OFFSET $offset"); + ORDER BY date_entered DESC LIMIT 30 OFFSET $offset"); while ($line = db_fetch_assoc($result)) { @@ -149,14 +142,10 @@ class Pref_Filters extends Handler_Protected { if ($line["feed_title"]) $feed_title = "(" . $line["feed_title"] . ")"; - print ""; - - print ""; - print ""; + $line .= ""; - $found++; + array_push($rv, $line); } } - $offset += $limit; - } + //$offset += $limit; + //} - if ($found == 0) { + /*if ($found == 0) { print "
"; + $line = ""; /*foreach ($filter['rules'] as $rule) { - $reg_exp = $rule['reg_exp']; $reg_exp = str_replace('/', '\/', $rule["reg_exp"]); $line["title"] = preg_replace("/($reg_exp)/i", @@ -166,25 +155,38 @@ class Pref_Filters extends Handler_Protected { "$1", $content_preview); }*/ - print $line["title"]; - print "
" . $feed_title . "
"; - print "
" . $content_preview . "
"; - print " " . mb_substr($line["date_entered"], 0, 16); + $line .= $line["title"]; + $line .= "
" . $feed_title . "
"; + $line .= "
" . $content_preview . "
"; + $line .= " " . mb_substr($line["date_entered"], 0, 16); - print "
" . __("No recent articles matching this filter have been found."); - } + }*/ + + print json_encode($rv); + } + + function testFilter() { + + if (isset($_REQUEST["offset"])) return $this->testFilterDo(); + + //print __("Articles matching this filter:"); + + print "
 Looking for articles...
"; + print "
"; + print ""; print "
"; print "
"; diff --git a/js/prefs.js b/js/prefs.js index 66288764a..797e0e071 100644 --- a/js/prefs.js +++ b/js/prefs.js @@ -146,6 +146,7 @@ function editFilter(id) { id: "filterEditDlg", title: __("Edit Filter"), style: "width: 600px", + test: function() { var query = "backend.php?" + dojo.formToQuery("filter_edit_form") + "&savemode=test"; @@ -156,8 +157,61 @@ function editFilter(id) { id: "filterTestDlg", title: "Test Filter", style: "width: 600px", + results: 0, + max_offset: 10000, + getTestResults: function(query, offset) { + var updquery = query + "&offset=" + offset; + + console.log("getTestResults:" + offset); + //console.log(updquery); + + new Ajax.Request("backend.php", { + parameters: updquery, + onComplete: function (transport) { + + console.log(transport.responseText); + + var result = JSON.parse(transport.responseText); + + console.log("R:" + result); + + //console.log("<<< " + transport.responseText); + + if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) { + test_dlg.results += result.size(); + + $("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d)...".replace("%d", offset)); + + console.log(offset + " " + test_dlg.max_offset); + + for (var i = 0; i < result.size(); i++) { + $("prefFilterTestResultList").innerHTML += result[i]; + } + + if (test_dlg.results < 30 && offset < test_dlg.max_offset) { + window.setTimeout(function() { + //console.log("blaargh"); + + test_dlg.getTestResults(query, offset + 30); + }, 0); + } else { + + // all done + + } + + } else { + console.log("can't parse results object / dialog closed"); + } + + } }); + }, href: query}); + dojo.connect(test_dlg, "onShow", null, function(e) { + test_dlg.getTestResults(query, 0); + }); + test_dlg.show(); }, selectRules: function(select) {