pref-feeds: add action to rescore feeds

master
Andrew Dolgov 17 years ago
parent 32d59314bc
commit fee840fbe3

@ -5519,4 +5519,35 @@
$text = preg_replace("/\]\]\>/", "", $text);
return $text;
}
function load_filters($link, $feed, $owner_uid, $action_id = false) {
$filters = array();
if ($action_id) $ftype_query_part = "action_id = '$action_id' AND";
$result = db_query($link, "SELECT reg_exp,
ttrss_filter_types.name AS name,
ttrss_filter_actions.name AS action,
inverse,
action_param
FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE
enabled = true AND
$ftype_query_part
owner_uid = $owner_uid AND
ttrss_filter_types.id = filter_type AND
ttrss_filter_actions.id = action_id AND
(feed_id IS NULL OR feed_id = '$feed') ORDER BY reg_exp");
while ($line = db_fetch_assoc($result)) {
if (!$filters[$line["name"]]) $filters[$line["name"]] = array();
$filter["reg_exp"] = $line["reg_exp"];
$filter["action"] = $line["action"];
$filter["action_param"] = $line["action_param"];
$filter["inverse"] = sql_bool_to_bool($line["inverse"]);
array_push($filters[$line["name"]], $filter);
}
return $filters;
}
?>

@ -473,6 +473,49 @@
clear_feed_articles($link, $id);
}
if ($subop == "rescore") {
$ids = split(",", db_escape_string($_GET["ids"]));
foreach ($ids as $id) {
$filters = load_filters($link, $id, $_SESSION["uid"], 6);
$result = db_query($link, "SELECT title, content, link, ref_id FROM
ttrss_user_entries, ttrss_entries
WHERE ref_id = id AND feed_id = '$id' AND
owner_uid = " .$_SESSION['uid']."
ORDER BY updated DESC LIMIT 100");
$scores = array();
while ($line = db_fetch_assoc($result)) {
$article_filters = get_article_filters($filters, $line['title'],
$line['content'], $line['link']);
$new_score = calculate_article_score($article_filters);
if (!$scores[$new_score]) $scores[$new_score] = array();
array_push($scores[$new_score], $line['ref_id']);
}
foreach (array_keys($scores) as $s) {
if ($s > 1000) {
db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
marked = true WHERE
ref_id IN (" . join(',', $scores[$s]) . ")");
} else {
db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
ref_id IN (" . join(',', $scores[$s]) . ")");
}
}
}
print __("All done.");
}
if ($subop == "add") {
if (!WEB_DEMO_MODE) {
@ -1020,6 +1063,7 @@
<option value=\"facEdit\">&nbsp;&nbsp;".__('Edit')."</option>
<option value=\"facPurge\">&nbsp;&nbsp;".__('Manual purge')."</option>
<option value=\"facClear\">&nbsp;&nbsp;".__('Clear feed data')."</option>
<option value=\"facRescore\">&nbsp;&nbsp;".__('Rescore articles')."</option>
<option value=\"facUnsubscribe\">&nbsp;&nbsp;".__('Unsubscribe')."</option>";
if (get_pref($link, 'ENABLE_FEED_CATS')) {

@ -1888,6 +1888,10 @@ function feedActionGo(op) {
editFeedCats();
}
if (op == "facRescore") {
rescoreSelectedFeeds();
}
if (op == "facUnsubscribe") {
removeSelectedFeeds();
}
@ -1912,4 +1916,31 @@ function clearFeedArticles(feed_id) {
return false;
}
function rescoreSelectedFeeds() {
if (!xmlhttp_ready(xmlhttp)) {
printLockingError();
return
}
var sel_rows = getSelectedFeeds();
if (sel_rows.length > 0) {
var ok = confirm(__("Rescore last 100 articles in selected feeds?"));
if (ok) {
notify_progress("Rescoring selected labels...");
xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=rescore&quiet=1&ids="+
param_escape(sel_rows.toString()), true);
xmlhttp.onreadystatechange=notify_callback;
xmlhttp.send(null);
}
} else {
alert(__("No feeds are selected."));
}
return false;
}

Loading…
Cancel
Save