From fee840fbe3c2ec42dd0174ca26060e140001154f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 30 Apr 2008 11:12:41 +0100 Subject: pref-feeds: add action to rescore feeds --- functions.php | 31 +++++++++++++++++++++++++++++++ modules/pref-feeds.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ prefs.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) diff --git a/functions.php b/functions.php index d42316886..cda69bb74 100644 --- a/functions.php +++ b/functions.php @@ -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; + } ?> diff --git a/modules/pref-feeds.php b/modules/pref-feeds.php index 6bd6b4aba..d54f2bdb9 100644 --- a/modules/pref-feeds.php +++ b/modules/pref-feeds.php @@ -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 @@ + "; if (get_pref($link, 'ENABLE_FEED_CATS')) { diff --git a/prefs.js b/prefs.js index 43a554cf2..5b5914ffc 100644 --- a/prefs.js +++ b/prefs.js @@ -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; +} -- cgit v1.2.3